开发者

Issue with creating index organized table

I'm having a weird problem with index organized table. I'm running Oracle 11g standard.

i have a table src_table

SQL> desc src_table;
 Name            Null?    Type
 --------------- -------- ----------------------------
 ID     NOT NULL   NUMBER(16)
 HASH       NOT NULL   NUMBER(3)
 ........

SQL> select count(*) from src_table;
  COUNT(*)
----------
  21108244

now let's create another table and copy 2 columns from src_table

set timing on
SQL> create table dest_table(id number(16), hash number(20), type number(1));
Table created.
Elapsed: 00:00:00.01

SQL> insert /*+ APPEND */ into dest_table (id,hash,type) select id, hash, 1 from src_table;
21108244 rows created.
Elapsed: 00:00:15.25

SQL> ALTER TABLE dest_table ADD ( CONSTRAINT dest_table_pk PRIMARY KEY (HASH, id, TYPE));
Table altered.
Elapsed: 00:01:17.35

It took Oracle < 2 min.

now same exercise but with IOT table

SQL> CREATE TABLE dest_table_iot (
       id     NUMBER(16) NOT NULL,
       hash  NUMBER(20) NOT NULL,
       type  NUMBER(1)  NOT NULL,
       CONSTRAINT dest_table_iot_PK PRIMARY KEY (HASH, id, TYPE)
    ) ORGANIZATION INDEX;

Table created.
Elapsed: 00:00:00.03

SQL> INSERT /*+ APPEND */ INTO dest_table_iot (HASH,id,TYPE)
    SELECT  HASH, id, 1 
    FROM src_table; 

"insert" into IOT takes 18 hours !!! I have tried 开发者_运维百科it on 2 different instances of Oracle running on win and linux and got same results.

What is going on here ? Why is it taking so long ?


The APPEND hint is only useful for a heap-organized table.

When you insert into an IOT, I suspect that each row has to be inserted into the real index structure separately, causing a lot of re-balancing of the index.

When you build the index on a heap table, a temp segment is used and I'm guessing that this allows it to reduce the re-balancing overhead that would otherwise take place.

I suspect that if you created an empty, heap-organized table with the primary key, and did the same insert without the APPEND hint, it would take more like the 18 hours.

You might try putting an ORDER BY on your SELECT and see how that affects the performance of the insert into the IOT. It's not guaranteed to be an improvement by any means, but it might be.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜