大家都知道varchar2是不定长的,所以存储数据的时候对磁盘数据库来说是根据具体的数据来存储的,但是在TimesTen中,有些不一样,这种差别主要是由于存储的方式不一样导致的。
在TimesTen中,varchar2定义的时候,可以定义为inline,也可以定义为not inline,所谓的inline就是空间的分配和普通的int,char等类型一样,都是放在表所在的连续空间中,当varchar2的长度小于等于128字节时缺省是inline。而not inline则是放在一个另开的空间,比如堆中,当varchar2的长度大于128字节时,缺省是not inline。
在TimesTen中,明确定义了两种模式下的空间消耗:
| VARCHAR2 (n [BYTE|CHAR]) |
For NOT INLINE columns:
On 32-bit platforms, length of value + 20 bytes (minimum of 28 bytes). On 64-bit platforms, length of value + 24 bytes (minimum of 40 bytes).
For INLINE columns:
On 32-bit platforms, n + 4 bytes. On 64-bit platforms, n + 8 bytes. If character semantics, the length of the column (n) is based on length semantics and character set. |
从中可以看出,如果是inline模式,则占用的空间是固定的,即长度+4/8。
试验如下:
Command> create table test ( a varchar2(50));
Command> desc test;
Table TEST.TEST:
Columns:
A VARCHAR2 (50) INLINE
Columns:
A VARCHAR2 (50) INLINE
1 table found.
(primary key columns are indicated with *)
然后通过ttsize验证:
(primary key columns are indicated with *)
然后通过ttsize验证:
[tt705@west-mountain ~]$ ttsize -tbl test -rows 1000 -frac 0.3 ttcore
Rows = 1000
Total in-line row bytes = 77786
Total = 77786
[tt705@west-mountain ~]$ ttsize -tbl test -rows 1000 -frac 0.4 ttcore
Rows = 1000
Total in-line row bytes = 77786
Total = 77786
[tt705@west-mountain ~]$ ttsize -tbl test -rows 1000 -frac 0.5 ttcore
Rows = 1000
Total in-line row bytes = 77786
Total = 77786
可以看出,不管frac如何变化,所占用的空间都是一样的。
但如果我们将varchar2显式定义为 not inline 呢:
Command> create table test11 ( a varchar2(50) not inline);
Command> desc test11;
Command> desc test11;
Table TEST.TEST11:
Columns:
A VARCHAR2 (50) NOT INLINE
Columns:
A VARCHAR2 (50) NOT INLINE
1 table found.
(primary key columns are indicated with *)
(primary key columns are indicated with *)
再通过ttsize验证,发现空间就会随着frac的变化而变化了:
[tt705@west-mountain ~]$ ttsize -tbl test11 -rows 1000 -frac 0.3 ttcore
Rows = 1000
Total in-line row bytes = 24538
Out-of-line columns:
Column A total 36000 avg size 14
Total out-of-line column bytes = 36000
Column A total 36000 avg size 14
Total out-of-line column bytes = 36000
Total = 60538
[tt705@west-mountain ~]$ ttsize -tbl test11 -rows 1000 -frac 0.4 ttcore
Rows = 1000
Total in-line row bytes = 24538
Out-of-line columns:
Column A total 40000 avg size 20
Total out-of-line column bytes = 40000
Column A total 40000 avg size 20
Total out-of-line column bytes = 40000
Total = 64538
[tt705@west-mountain ~]$ ttsize -tbl test11 -rows 1000 -frac 0.5 ttcore
Rows = 1000
Total in-line row bytes = 24538
Out-of-line columns:
Column A total 44000 avg size 25
Total out-of-line column bytes = 44000
Column A total 44000 avg size 25
Total out-of-line column bytes = 44000
Total = 68538
[tt705@west-mountain ~]$
[tt705@west-mountain ~]$
文章 (RSS)