Home | Previous Page | Next Page   Data Manipulation > Using Smart Large Objects > Creating a Smart Large Object >

Choosing Storage Characteristics

After initializing an LO-specification structure, you need to ensure that this structure contains the appropriate values for the storage characteristics you want the smart large object to have. Then you pass this LO-specification structure to one of the smart-large-object creation functions (Table 29) so that the smart-large-object optimizer can obtain the storage characteristics to use for the new smart large object.

To choose storage characteristics for a new smart large object
  1. Use the system-specified storage characteristics as a basis for obtaining the storage characteristics of a smart large object.

    The system-specified storage characteristics are the default storage characteristics for a smart large object.

  2. Customize the storage characteristics.

    You can override the system-specified storage characteristics with one of the following levels of the storage-characteristics hierarchy:

    • Storage characteristics defined for a particular CLOB or BLOB column in which you want to store the smart large object

      Storage characteristics that are unique to a particular CLOB or BLOB column are called column-level storage characteristics.

    • User-specified storage characteristics

      Special storage characteristics that you define for this smart large object only are called user-specified storage characteristics.

Important:
For most applications, use the system-specified values for the disk-storage information. Most DataBlade API modules need to ensure correct storage characteristics only for an sbspace name (the location of the smart large object) and for the smart-large-object attributes.

Obtaining Storage Characteristics

For most smart large objects, all you need to do is obtain the system-specified storage characteristics. When you obtain these storage characteristics for a smart large object, you can specify a location for it and override system-specified attributes.

To obtain system-specified storage characteristics
  1. Use the mi_lo_spec_init( ) function to allocate an LO-specification structure and to initialize this structure to the appropriate null values.

    When a storage characteristic in the LO-specification structure has the appropriate null value (zero or a NULL-valued pointer), the smart-large-object optimizer obtains the system-specified value for the storage characteristic. The smart-large-object optimizer calculates the system-specified values for disk-storage storage characteristics. Most applications can use these system-specified values. For more information, see Using System-Specified Storage Characteristics.

  2. Specify the location of the smart large object to override the default location. You can specify the location as one of the following:
    • The name of the sbspace associated with the CLOB or BLOB column in which you want to store the smart large object

      To store a new smart large object in a CLOB or BLOB column, use the mi_lo_colinfo_by_name( ) or mi_lo_colinfo_by_ids( ) function. These functions obtain the column-level storage characteristics for this column. One of the storage characteristics they obtain is the sbspace name for the column. For more information, see Obtaining Column-Level Storage Characteristics.

    • The name of some other sbspace

      You might want to specify an sbspace name for a new smart large object that is embedded in an opaque data type. The mi_lo_specset_sbspace( ) accessor function sets the name of the sbspace in the LO-specification structure. For more information, see Defining User-Specified Storage Characteristics.

  3. Optionally, override any attributes for the smart large object with the mi_lo_specset_flags( ) accessor function.

    The system-specified attributes have both logging and last-access time disabled. You might want to enable one or more attributes for the new smart large object. The mi_lo_specset_flags( ) function sets the attributes flag in the LO-specification structure. For more information, see Defining User-Specified Storage Characteristics.

  4. Pass this LO-specification structure to one of the smart-large-object creation functions (mi_lo_create( ), mi_lo_copy( ), mi_lo_expand( ), or mi_lo_from_file( )) to create the new smart large object.

    The smart-large-object creation function creates a new smart large object that has storage characteristics that the LO-specification structure indicates. For more information, see Initializing an LO-Specification Structure.

You would probably want to modify the storage characteristics of the new smart large object in the following cases:

Using the Storage-Characteristics Hierarchy

Dynamic Server uses the storage-characteristics hierarchy, which Figure 28 shows, to obtain the storage characteristics for a new smart large object.

Figure 28. Storage-Characteristics Hierarchy
begin figure description - This figure is described in the surrounding text. - end figure description

For a given storage characteristic, any value defined at the column level overrides the system-specified value, and any user-level value overrides the column-level value. Table 31 summarizes the ways to specify disk-storage information for a smart large object.

Table 31. Specifying Disk-Storage Information
Disk-Storage Information System-Specified Storage Characteristics Column-Level Storage Characteristics User-Specified Storage Characteristics
System Default Value Specified by onspaces Utility Specified by the PUT clause of CREATE TABLE Specified by a DataBlade API Function
Size of extent Calculated by smart-large-object optimizer EXTENT_SIZE EXTENT SIZE Yes
Size of next extent Calculated by smart-large-object optimizer NEXT_SIZE No No
Minimum extent size Four kilobytes MIN_EXT_SIZE No No
Size of smart large object Calculated by smart-large-object optimizer Average size of all smart large objects in sbspace:

AVG_LO_SIZE

No Estimated size of a particular smart large object

Maximum size of a particular smart large object

Maximum size of I/O block Calculated by smart-large-object optimizer MAX_IO_SIZE No No
Name of sbspace SBSPACENAME -S option Name of an existing sbspace that stores a smart large object:

IN clause

Yes

For most applications, use the values for the disk-storage information that the smart-large-object optimizer determines. If you know the size of the smart large object, it is recommended that you specify this size as a user-specified storage characteristic, instead of as a system-specified or column-level storage characteristic.

For more information on any of the disk-storage information in Table 31, see Disk-Storage Information.

Table 32 summarizes the ways to specify attribute information for a smart large object.

Table 32. Specifying Attribute Information
Attribute Information System-Specified Storage Characteristics Column-Level Storage Characteristics User-Specified Storage Characteristics
System Default Value Specified by the onspaces Utility Specified by the PUT clause of CREATE TABLE Specified by a DataBlade API Function
Logging OFF LOGGING LOG, NO LOG Yes
Last-access time OFF ACCESSTIME KEEP ACCESS TIME,

NO KEEP ACCESS TIME

Yes
Buffering mode OFF BUFFERING No Yes
Lock mode Lock entire smart large object LOCK_MODE No Yes
Data integrity High integrity No HIGH INTEG, MODERATE INTEG Yes

For more information on any of the attributes in Table 32, see Attribute Information.

Table 33 summarizes the ways to specify open-mode information for a smart large object.

Table 33. Specifying Open-Mode Information
Storage Characteristic System-Specified Storage Characteristics Column-Level Storage Characteristics User-Specified Storage Characteristics
System Default Value Specified by the onspaces Utility Specified by the PUT clause of CREATE TABLE Specified by a DataBlade API Function
Open-mode information Default open mode No No Yes

For more information on the open mode and the default open mode, see Attribute Information.

Using System-Specified Storage Characteristics

The Database Administrator (DBA) establishes system-specified storage characteristics when he or she initializes the database server and creates an sbspace with the onspaces utility, as follows:

The system-specified storage characteristics apply to all smart large objects that are stored in the sbspace, unless a smart large object specifically overrides them with column-level or user-specified storage characteristics.

The onspaces utility establishes storage characteristics for an sbspace. For the storage characteristics that onspaces can set as well as the system defaults, see Table 31 and Table 32. For example, the following call to the onspaces utility creates an sbspace named sb1 in the /dev/sbspace1 partition:

onspaces -c -S sb1 -p /dev/sbspace1 -o 500 -s 2000
   -Df "AVG_LO_SIZE=32"

Table 34 shows the system-specified storage characteristics for all smart large objects in the sb1 sbspace.

Table 34. System-Specified Storage Characteristics for the sb1 Sbspace
Storage Characteristic System-Specified Value Specified by the onspaces Utility
Disk-storage information:
Size of extent Calculated by smart-large-object optimizer system default
Size of next extent Calculated by smart-large-object optimizer system default
Minimum extent size Calculated by smart-large-object optimizer system default
Size of smart large object 32 kilobytes
(smart-large-object optimizer uses as size estimate)
AVG_LO_SIZE
Maximum size of I/O block Calculated by smart-large-object optimizer system default
Name of sbspace sb1 -S option
Attribute information:
Logging OFF system default
Last-access time OFF system default

For a smart large object that has system-specified storage characteristics, the smart-large-object optimizer calculates values for all disk-storage information except the sbspace name. The DBA can specify a default sbspace name with the SBSPACENAME configuration parameter in the ONCONFIG file. However, you must ensure that the location (the name of the sbspace) is correct for the smart large object that you create. If you do not specify an sbspace name for a new smart large object, the database server stores it in this default sbspace. This arrangement can quickly lead to space constraints.

Important:
For new smart large objects, use the system-specified values of all disk-storage information except the sbspace name. The smart-large-object optimizer can best determine most of the values of the storage characteristics. Most applications only need to specify an sbspace name for their disk-storage information.
Obtaining Column-Level Storage Characteristics

The DBA can establish column-level storage characteristics for a database table with the CREATE TABLE statement. If the table contains a CLOB or BLOB column, the PUT clause of CREATE TABLE can specify the storage characteristics that Table 31 and Table 32 show. This statement stores column-level storage characteristics in the syscolattribs system catalog table.

The column-level storage characteristics apply to all smart large objects whose LO handles are stored in the column, unless a smart large object specifically overrides them with user-specified storage characteristics. Column-level storage characteristics override any corresponding system-specified storage characteristics.

For example, if the sb1 sbspace was defined as Table 34 shows, the following CREATE TABLE statement specifies column-level storage characteristics of a location and last-access time for the cat_descr column:

CREATE TABLE catalog2
(
     catalog_num INTEGER,
     cat_descr CLOB
) PUT cat_descr IN (sb1) (KEEP ACCESS TIME);

Table 35 shows the storage characteristics for all smart large objects in the cat_descr column.

Table 35. Storage Characteristics for the cat_descr Column
Storage Characteristic Column-Level Value Specified by PUT Clause of CREATE TABLE
Disk-storage information:
Size of extent Calculated by smart-large-object optimizer system-specified
Size of next extent Calculated by smart-large-object optimizer system-specified
Minimum extent size Calculated by smart-large-object optimizer system-specified
Size of smart large object 32 kilobytes
(smart-large-object optimizer uses as size estimate)
system-specified
Maximum size of I/O block Calculated by smart-large-object optimizer system-specified
Name of sbspace sb1 IN (sb1)
Attribute information:
Logging OFF system-specified
Last-access time ON KEEP LAST ACCESS

For more information on the syntax of the CREATE TABLE statement, see its description in the IBM Informix: Guide to SQL Syntax.

The following DataBlade API functions obtain column-level storage characteristics for a specified CLOB or BLOB column:

Both these functions store the column-level storage characteristics for the specified column in an existing LO-specification structure. When a smart-large-object creation function receives this LO-specification structure, it creates a new smart-large-object instance that has these column-level storage characteristics.

Tip:
When you use the column-level storage characteristics, you do not usually need to override the name of the sbspace for the smart large object. The sbspace name is specified in the PUT clause of the CREATE TABLE statement.

For example, the following code fragment obtains the column-level storage characteristics for the emp_picture column of the employee table (Figure 26) and puts them in the LO-specification structure that LO_spec references:

MI_LO_SPEC *LO_spec = NULL;
MI_CONNECTION *conn;
...
mi_lo_spec_init(conn, &LO_spec);
mi_lo_colinfo_by_name(conn, "employee.emp_picture",
   LO_spec);

The call to mi_lo_colinfo_by_name( ) overwrites the system-specified storage characteristics that the call to mi_lo_spec_init( ) put in the LO-specification structure. The LO-specification structure that LO_spec references now contains the column-level storage characteristics for the emp_picture column.

Defining User-Specified Storage Characteristics

You can establish user-specified storage characteristics when you create a new smart large object. DataBlade API functions can specify the storage characteristics that Table 31 and Table 32 show. The user-specified storage characteristics apply only to the particular smart-large-object instance that is being created. They override any corresponding column-level or system-specified storage characteristics.

After you have an LO-specification structure allocated, you can use the appropriate LO-specification accessor functions to set fields of this structure. Accessor functions also exist to retrieve storage-characteristic values from the LO-specification structure. When a smart-large-object creation function receives the LO-specification structure, it creates a new smart-large-object instance that has these user-specified storage characteristics.

Important:
The LO-specification structure, MI_LO_SPEC, is an opaque structure to DataBlade API modules. Do not access its internal structure directly. The internal structure of MI_LO_SPEC may change in future releases. Therefore, to create portable code, always use the LO-specification accessor functions to obtain and store values from this structure.

The following sections describe how to access each group of storage characteristics in the LO-specification structure.

Accessing Disk-Storage Information

Table 36 shows the disk-storage information with the corresponding LO-specification accessor functions.

Table 36. Disk-Storage Information in the LO-Specification Structure
Disk-Storage Information Description LO-Specification
Accessor Function
Estimated number of bytes An estimate of the final size, in bytes, of the smart large object

The smart-large-object optimizer uses this value to determine the extents in which to store the smart large object. This value provides optimization information. If the value is grossly incorrect, it does not cause incorrect behavior. However, it does mean that the optimizer might not necessarily choose optimal extent sizes for the smart large object.

By default, this value is -1, which tells the smart-large-object optimizer to calculate the extent size from a set of heuristics.

mi_lo_specget_estbytes( )

mi_lo_specset_estbytes( )

Maximum number of bytes The maximum size, in bytes, for the smart large object

The smart-large-object optimizer does not allow the smart large object to grow beyond this size. By default, this value is -1, which tells the smart-large-object optimizer that there is no preset maximum size.

mi_lo_specget_maxbytes( )

mi_lo_specset_maxbytes( )

Allocation extent size The allocation extent size, in kilobytes

It is the size of the page extents for the smart large object. By default, this value is -1, which tells the smart-large-object optimizer to obtain the allocation extent size from the storage-characteristics hierarchy.

mi_lo_specget_extsz( )

mi_lo_specset_extsz( )

Name of the sbspace The name of the sbspace that contains the smart large object

The sbspace name can be at most 18 characters long and must be null terminated. By default, this value is null, which tells the smart-large-object optimizer to obtain the sbspace name from the storage-characteristics hierarchy.

mi_lo_specget_sbspace( )

mi_lo_specset_sbspace( )

For most applications, use the values for the disk-storage information that the smart-large-object optimizer determines. If you know the size of the smart large object, it is recommended that you specify this size in the mi_lo_specset_estbytes( ) function instead of in the onspaces utility or the CREATE TABLE or the ALTER TABLE statement. This mi_lo_specset_estbytes( ) function (and the corresponding ESQL/C ifx_lo_specset_estbytes( ) function) is the best way to set the extent size because the database server can allocate the entire smart large object as one extent. For more information, see Disk-Storage Information.

Accessing Attributes

The LO-specification structure uses a bitmask flag, called an attributes flag, to specify the attributes of a smart large object. Table 37 shows the attribute constants of an LO-specification structure.

Table 37. Attribute Constants in the LO-Specification Structure
Attribute Attribute Constant Description
Logging: MI_LO_ATTR_LOG Log changes to the smart large object in the system log file.
MI_LO_ATTR_NO_LOG Turn off logging for all operations that involve the associated smart large object.
Consider carefully whether to use the MI_LO_ATTR_LOG flag value. The database server incurs considerable overhead to log smart large objects. For more information, see Logging.
Last-access time: MI_LO_ATTR_KEEP_LASTACCESS_TIME Save the last-access time for the smart large object.
MI_LO_ATTR_NOKEEP_LASTACCESS_TIME Do not maintain the last-access time for the smart large object.
Consider carefully whether to use the MI_LO_ATTR_KEEP_LASTACCESS_TIME flag value. The database server incurs considerable overhead in logging and concurrency to maintain last-access times for smart large objects. For more information, see Last-Access Time.
Data integrity: MI_LO_ATTR_HIGH_INTEG Use both a page header and a page trailer for the pages of the sbspace.
MI_LO_ATTR_MODERATE_INTEG Use only a page header for the pages of the sbspace.
Consider carefully whether to use the MI_LO_ATTR_MODERATE_INTEG flag value. Although moderate integrity takes less disk space per page, it also reduces the ability of the database server to recover information should disk errors occur. For more information, see Data Integrity.

The milo.h header file defines the attribute constants: MI_LO_ATTR_LOG, MI_LO_ATTR_NO_LOG, MI_LO_ATTR_KEEP_LASTACCESS_TIME, and MI_LO_ATTR_NOKEEP_LASTACCESS_TIME, MI_LO_ATTR_HIGH_INTEG, and MI_LO_ATTR_MODERATE_INTEG.

Table 38 shows the LO-specification accessor functions for the attribute information.

Table 38. Accessor Functions for Attribute Information in the LO-Specification Structure
LO-Specification
Accessor Function
Description
mi_lo_specget_flags( ) Overrides system-specified or column-level attributes in the LO-specification structure with the attributes that the attributes flag specifies
mi_lo_specset_flags( ) Retrieves the attributes flag from the LO-specification structure
To set an attributes flag
  1. If you need to set more than one attribute, use the C-language bitwise OR operator (|) to mask attribute constants together.
  2. Use the mi_lo_specset_flags( ) accessor function to store the attributes flag in the LO-specification structure.

Masking mutually exclusive flags results in an error. If you do not specify a value for a particular attribute, the database server uses the storage-characteristics hierarchy to determine this information.

For example, the following code fragment specifies the constants to enable logging the last-access time for the attributes flag in the LO-specification structure that LO_spec identifies:

MI_CONNECTION *conn;
MI_LO_SPEC *LO_spec = NULL;
mi_integer create_flgs;
...

if ( mi_lo_spec_init(conn, &LO_spec) != MI_OK )
   /* handle error and exit */
create_flgs = 
   MI_LO_ATTR_LOG | MI_LO_ATTR_KEEP_LASTACCESS_TIME;
if ( mi_lo_specset_flags(LO_spec, create_flgs) != MI_OK )
   /* handle error and exit */

For more information on the attributes of a smart large object, see Attribute Information and the descriptions of the mi_lo_specset_flags( ) and mi_lo_specget_flags( ) functions in the IBM Informix: DataBlade API Function Reference.

Accessing the Default Open Flag

When you open a smart large object, you can specify the open mode for the data. The open mode describes the context in which the I/O operations on the smart large object are performed. The LO-specification structure uses a bitmask flag, called a default-open-mode flag, to specify the default open mode of a smart large object. Table 39 shows the open-mode constants of an LO-specification structure.

Table 39. Open-Mode Constants in the LO-Specification Structure
Open-Mode Information Open-Mode Constant Description
Access modes MI_LO_RDONLY Read-only mode
MI_LO_DIRTY_READ Dirty-read mode
MI_LO_WRONLY Write-only mode
MI_LO_APPEND Write/append mode
MI_LO_RDWR Read/write mode
MI_LO_TRUNC Truncate
These access-mode flags for a smart large object are patterned after the UNIX System V file-access modes. For more information, see Access Modes.
Access methods MI_LO_RANDOM Random access
MI_LO_SEQUENTIAL Sequential access
MI_LO_FORWARD Forward
MI_LO_REVERSE Reverse
For more information, see Access Methods.
Buffering modes MI_LO_BUFFER Buffered access (Buffered I/O)
MI_LO_NOBUFFER Unbuffered access (Lightweight I/O)
For more information, see Buffering Modes.
Locking modes MI_LO_LOCKALL Lock-all locks
MI_LO_LOCKRANGE Byte-range locks
For more information, see Locking Modes.

The milo.h header file defines the open-mode constants: MI_LO_RDONLY, MI_LO_DIRTY_READ, MI_LO_WRONLY, MI_LO_APPEND, MI_LO_RDWR, MI_LO_TRUNC, MI_LO_RANDOM, MI_LO_SEQUENTIAL, MI_LO_FORWARD, MI_LO_REVERSE, MI_LO_BUFFER, MI_LO_NOBUFFER, MI_LO_LOCKALL, and MI_LO_LOCKRANGE.

Table 40 shows the LO-specification accessor functions for the default-open-mode information.

Table 40. Accessor Functions for Attribute Information in the LO-Specification Structure
LO-Specification
Accessor Function
Description
mi_lo_specget_def_open_flags( ) Overrides the system default open mode with the open mode that the default-open-mode flag specifies
mi_lo_specset_def_open_flags( ) Retrieves the default-open-mode flag from the LO-specification structure
To set a default-open-mode flag
  1. Use the appropriate open-mode constants from the list in Table 39. If you need to set more than one default-open-mode value, use the C-language bitwise OR operator (|) to mask open-mode constants together.
  2. Use the mi_lo_specset_def_open_flags( ) accessor function to store the default-open-mode flag in the LO-specification structure.

Masking mutually exclusive flags results in an error. However, you can mask the MI_LO_APPEND constant with another access-mode constant. In any of these OR combinations, the seek operation remains unaffected. The following table shows the effect that each of the OR combinations has on the read and write operations.

OR Operation Read Operations Write Operations
MI_LO_RDONLY |
MI_LO_APPEND
Starts at the LO seek position and then moves the seek position to the end of the data that has been read Fails and does not move the LO seek position
MI_LO_WRONLY |
MI_LO_APPEND
Fails and does not move the LO seek position Moves the LO seek position to the end of the smart large object and then writes the data

The LO seek position is at the end of the data after the write operation.

MI_LO_RDWR |
MI_LO_APPEND
Starts at the LO seek position and then moves the seek position to the end of the data that has been read Moves the LO seek position to the end of the smart large object and then writes the data

The LO seek position is at the end of the data after the write operation.

For more information on access modes of a smart large object, see Access Modes.

If you do not specify a value for a particular part of the open mode, the database server assumes the following system default open mode when you open a smart large object.

Access Capability Default Open Mode Smart-Large-Object Constant
Access mode Read-only MI_LO_RDONLY
Access method Random MI_LO_RANDOM
Buffering Buffered access MI_LO_BUFFER
Locking Whole-object locks MI_LO_LOCKALL

You can specify a different open mode for a particular smart large object when you open a smart large object. For more information on how to open a smart large object, see Opening a Smart Large Object.

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]