Oracle中增加列大小的影响

时间:2013-05-15 09:26:20

标签: database oracle

我有一个脚本

SQL script: alter table xx_vms.es_lot_updates modify (routing_list varchar2(1000));

此列的先前大小为255.现在我将其大小增加到1000。 但是在此表中,routing_list列通常为NULL。偶尔,它有价值。

此列的增量大小是否会导致性能问题?我很困惑!请帮忙。感谢。

3 个答案:

答案 0 :(得分:3)

不,没有性能问题。您所做的就是允许在该列中插入更大的文本字符串。 请记住,您应该尽可能地对表中允许的内容进行尽可能严格的操作,您可以根据需要随意添加列。 (varchar2最多4000个字节)

答案 1 :(得分:2)

这取决于。带有varchar2(1000)的表使用更大量的数据库块进行存储,因此全表扫描可能会更昂贵,因为您要读取更多块。这是一个简单的测试:

17:48:25 HR@sandbox> create table c1000 (txt varchar2(1000));

Table created.

Elapsed: 00:00:00.21
17:48:37 HR@sandbox> create table c255 (txt varchar2(255));

Table created.

Elapsed: 00:00:00.03

-- for this test we assume that only 10% of columns are filled with data
17:50:21 HR@sandbox> ed
Wrote file S:\spool\sandbox\BUFFER_HR_32.sql

  1   insert into c255
  2   select decode(mod(rownum,10), 0, lpad('x', 255,'x')) from dual
  3*  connect by rownum <= 1e5
17:50:24 HR@sandbox> /

100000 rows created.

Elapsed: 00:00:01.26
17:50:47 HR@sandbox> ed
Wrote file S:\spool\sandbox\BUFFER_HR_32.sql

  1   insert into c1000
  2   select decode(mod(rownum,10), 0, lpad('x', 1000,'x')) from dual
  3*  connect by rownum <= 1e5
17:50:51 HR@sandbox> /

100000 rows created.

Elapsed: 00:00:01.45
17:50:52 HR@sandbox> commit;

Commit complete.

Elapsed: 00:00:00.01
17:51:20 HR@sandbox> select table_name, blocks from user_tables where table_name in ('C255', 'C1000');

TABLE_NAME                         BLOCKS
------------------------------ ----------
C1000                                1756
C255                                  622

Elapsed: 00:00:00.20
17:53:28 HR@sandbox> set autotrace traceonly statistics
17:53:37 HR@sandbox> select * from c1000;

100000 rows selected.

Elapsed: 00:00:01.30

Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
       1901  consistent gets
       1694  physical reads
          0  redo size
   10586458  bytes sent via SQL*Net to client
       2552  bytes received via SQL*Net from client
        201  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
     100000  rows processed

17:53:50 HR@sandbox> select * from c255;

100000 rows selected.

Elapsed: 00:00:00.63

Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
        825  consistent gets
        295  physical reads
          0  redo size
    3107206  bytes sent via SQL*Net to client
       2552  bytes received via SQL*Net from client
        201  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
     100000  rows processed

查看consistent gets stat。与c1000的完整扫描相比,c255的完整扫描的IO值是原来的两倍。

但是,如果您只使用主键选择几行,我认为您不会注意到显着差异。

答案 2 :(得分:0)

不,它与性能无关,varchar2的最大大小为4000。

一旦你改变了表,就要记住编译所有的依赖关系,因为它们将无效,例如

程序和包