Calculations to Determine Bind Array Size

本文详细讲解了如何计算SQL*Loader中bind数组的大小,特别关注VARCHAR、VARGRAPHIC等变长字段的最小最大长度设置,以减少内存消耗。通过实例演示了不同字符类型和长度指定方式对bind数组的影响,以及处理多INTO TABLE子句的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The bind array's size is equivalent to the number of rows it contains times the maximum length of each row. The maximum length of a row equals the sum of the maximum field lengths, plus overhead, as follows:

bind array size =

    (number of rows) * (  SUM(fixed field lengths)

                        + SUM(maximum varying field lengths)

                        + ( (number of varying length fields)

                             * (size of length indicator) )

                       )

  1. 固定长度字段长度见下面的data types(与oracle的数据类型不同), fixed field是没有overhead(开销)的
  2. 变长类型的会有额外的开销,以下类型为变长

The fields that can vary in size from row to row are:

CHAR, DATE, INTERVAL DAY TO SECOND, INTERVAL DAY TO YEAR,

LONG VARRAW, numeric EXTERNAL, TIME, TIMESTAMP, TIME WITH TIME ZONE,

TIMESTAMP WITH TIME ZONE, VARCHAR, VARCHARC, VARGRAPHIC,

VARRAW, VARRAWC

When the character data types (CHARDATE, and numeric EXTERNAL) are specified with delimiters, any lengths specified for these fields are maximum lengths. When specified without delimiters, the size in the record is fixed, but the size of the inserted field may still vary, due to whitespace trimming. So internally, these data types are always treated as varying-length fields—even when they are fixed-length fields.

  1. 每行还会有个长度指示器,用于提供每行字段的实际长度

A length indicator is included for each of these fields in the bind array. The space reserved for the field in the bind array is large enough to hold the longest possible value of the field. The length indicator gives the actual length of the field for each row.

  1. 在conventional path导入时LOBFILE不会包含在BIND ARRAY

  1. Determining the Size of the Length Indicator

Use the control file to determine the size of the length indicator.

On most systems, the size of the length indicator is 2 bytes. On a few systems, it is 3 bytes. To determine its size, use the following control file:

OPTIONS (ROWS=1)

LOAD DATA

INFILE *

APPEND

INTO TABLE DEPT

(deptno POSITION(1:1) CHAR(1))

BEGINDATA

a

This control file loads a 1-byte CHAR using a 1-row bind array. In this example, no data is actually loaded because a conversion error occurs when the character a is loaded into a numeric column (deptno). The bind array size shown in the log file, minus one (the length of the character field) is the value of the length indicator.

Note:

A similar technique can determine bind array size without doing any calculations. Run your control file without any data and with ROWS=1 to determine the memory requirements for a single row of data. Multiply by the number of rows you want in the bind array to determine the bind array size.

  1. Calculating the Size of Field Buffers

"L" is the length specified in the control file. "P" is precision. "S" is the size of the length indicator.

Table 9-3 Fixed-Length Fields

Data Type

Size in Bytes (Operating System-Dependent)

INTEGER

The size of the INT data type, in C

INTEGER(N)

N bytes

SMALLINT

The size of SHORT INT data type, in C

FLOAT

The size of the FLOAT data type, in C

DOUBLE

The size of the DOUBLE data type, in C

BYTEINT

The size of UNSIGNED CHAR, in C

VARRAW

The size of UNSIGNED SHORT, plus 4096 bytes or whatever is specified as max_length

LONG VARRAW

The size of UNSIGNED INT, plus 4096 bytes or whatever is specified as max_length

VARCHARC

Composed of 2 numbers. The first specifies length, and the second (which is optional) specifies max_length(default is 4096 bytes).

VARRAWC

This data type is for RAW data. It is composed of 2 numbers. The first specifies length, and the second (which is optional) specifies max_length (default is 4096 bytes).

Table 9-4 Nongraphic Fields

Data Type

Default Size

Specified Size

(packed) DECIMAL

None

(N+1)/2, rounded up

ZONED

None

P

RAW

None

L

CHAR (no delimiters)

1

L + S

datetime and interval (no delimiters)

None

L + S

numeric EXTERNAL (no delimiters)

None

L + S

Table 9-5 Graphic Fields

Data Type

Default Size

Length Specified with POSITION

Length Specified with DATA TYPE

GRAPHIC

None

L

2*L

GRAPHIC EXTERNAL

None

L - 2

2*(L-2)

VARGRAPHIC

4KB*2

L+S

(2*L)+S

Table 9-6 Variable-Length Fields

Data Type

Default Size

Maximum Length Specified (L)

VARCHAR

4 KB

L+S

CHAR (delimited)

255

L+S

datetime and interval (delimited)

255

L+S

numeric EXTERNAL (delimited)

255

L+S

  1. Minimizing Memory Requirements for Bind Arrays

Pay particular attention to the default sizes allocated for VARCHARVARGRAPHIC, and the delimited forms of CHARDATE, and numeric EXTERNALfields.

字段尽量指定较小的最大值,不要不设置类型长度

They can consume enormous amounts of memory—especially when multiplied by the number of rows in the bind array. It is best to specify the smallest possible maximum length for these fields. Consider the following example:

CHAR(10) TERMINATED BY ","

With byte-length semantics, this example uses (10 + 2) * 64 = 768 bytes in the bind array, assuming that the length indicator is 2 bytes long and that 64 rows are loaded at a time.

With character-length semantics, the same example uses ((10 * s) + 2) * 64 bytes in the bind array, where "s" is the maximum size in bytes of a character in the data file character set.

Now consider the following example:

CHAR TERMINATED BY ","

Regardless of whether byte-length semantics or character-length semantics are used, this example uses (255 + 2) * 64 = 16,448 bytes, because the default maximum size for a delimited field is 255 bytes. This can make a considerable difference in the number of rows that fit into the bind array.

  1. Calculating Bind Array Size for Multiple INTO TABLE Clauses

When calculating a bind array size for a control file that has multiple INTO TABLE clauses, calculate as if the INTO TABLE clauses were not present.

Imagine all of the fields listed in the control file as one, long data structure—that is, the format of a single row in the bind array.

If the same field in the data record is mentioned in multiple INTO TABLE clauses, then additional space in the bind array is required each time it is mentioned. It is especially important to minimize the buffer allocations for such fields.

Note:

Generated data is produced by the SQL*Loader functions CONSTANTEXPRESSIONRECNUMSYSDATE, and SEQUENCE. Such generated data does not require any space in the bind array.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值