Chinaunix

标题: 大表装载是否需要先建index ? [打印本页]

作者: welion    时间: 2009-01-16 15:14
标题: 大表装载是否需要先建index ?
table1大表复制,先建另外一个表 table2,先建表,在用insert into table2 select * from table1,再建index。
算下来时间比建表、建index,再insert要慢,奇怪,不是先倒数再建index会快么?

数据如下:

==========先建index,再倒数==============
>time dbaccess test<<!
>create table ....
>create index ....
> insert into table2 select * from table1;
>!

Database selected.

465948 row(s) inserted.

Database closed.

real    6m46.97s
user    0m0.02s
sys     0m0.02s


========== 先倒数,再建index =============

>time dbaccess test<<!
> insert into table2 select * from table1;
> !

Database selected.


465948 row(s) inserted.

Database closed.


real    7m3.23s
user    0m0.03s
sys     0m0.01s


>time dbaccess test<<!
> create unique index ....
.......
> !

Database selected.

Index created.

Index created.

Index created.

Index created.

Index created.

Index created.

Database closed.

real    8m48.85s
user    0m0.03s
sys     0m0.02s
作者: 我是DBA    时间: 2009-01-16 15:49
必须得这样做:
先倒数据再建索引
要不然索引层数过多,效率太低。
作者: welion    时间: 2009-01-16 16:03
标题: 回复 #2 我是DBA 的帖子
单纯对于装载的时间而言,是不是的却先导再建速度慢?
作者: 我是DBA    时间: 2009-01-16 16:38
标题: 回复 #3 welion 的帖子
单纯对于装载时间而言,当然是先建索引再导数据库比较快
先导再建慢。
作者: liaosnet    时间: 2009-01-16 17:23
用onpladm来做吧...不过做完需要0备一次...
作者: 我是DBA    时间: 2009-01-19 08:52
标题: 回复 #5 liaosnet 的帖子
onpladm这个东东好用啊?
我都没用过,改天研究一下。
作者: welion    时间: 2009-01-19 10:36
标题: 回复 #5 liaosnet 的帖子
我试了用HPL,但做到一半就不动了,帮忙看看:

IBM161:informix:/home/informix/test>onpladm create job job_wa1 -d wa1_job.unl -D eaihtest -t wa1 -flu
Successfully created Job job_wa1

IBM161:informix:/home/informix/test>onpladm run job job_wa1 -fu
Connecting to onpload, Please wait...
Successful connection to onpload established
Mon Jan 19 10:21:31 2009

SHMBASE        0x0
CLIENTNUM      0x49010000
Session ID 2

Unload Database -> eaihtest
Query Name      -> job_wa1
Device Array    -> job_wa1
Query Mapping   -> job_wa1
Query           -> select * from wa1 for read only
Convert Reject  -> /tmp/job_wa1.rej
10:21:41 Records Processed ->  10000

一直停在那儿不动了,数据量10多w,生成的文件大小也不动了
-rw-rw----   1 informix informix   55918867 Jan 19 10:21 wa1_job.unl
作者: liaosnet    时间: 2009-01-19 10:43
标题: 回复 #7 welion 的帖子
看一下你的数据库在干什么...
作者: welion    时间: 2009-01-19 12:46
标题: 回复 #8 liaosnet 的帖子
IBM161:informix:/home/informix>onstat -

Informix Dynamic Server Version 9.30.FC2R1   -- On-Line -- Up 00:26:31 -- 690320 Kbytes

IBM161:informix:/home/informix>onstat -g sql

Informix Dynamic Server Version 9.30.FC2R1   -- On-Line -- Up 00:26:34 -- 690320 Kbytes

Sess  SQL            Current            Iso Lock       SQL  ISAM F.E.
Id    Stmt type      Database           Lvl Mode       ERR  ERR  Vers
102   -              onpload            CR  Wait 3     0    0    9.03

IBM161:informix:/home/informix>
IBM161:informix:/home/informix>onstat -g ses

Informix Dynamic Server Version 9.30.FC2R1   -- On-Line -- Up 00:26:40 -- 690320 Kbytes

session                                      #RSAM    total      used      
id       user     tty      pid      hostname threads  memory     memory   
112      informix -        0        -        0        12288      11272     
108      informix -        0        -        0        12288      11272     
103      informix -        0        -        0        12288      11272     
102      informix 10       51986    IBM161   1        61440      45968     
86       informix -        0        -        0        12288      11272     
23       informix -        0        -        0        12288      11272     
22       informix -        0        -        0        16384      12968     
21       informix -        0        -        0        12288      11272     
19       informix -        0        -        0        16384      12968     
18       informix -        0        -        0        12288      11272     
16       informix -        0        -        0        16384      12968     
15       informix -        0        -        0        12288      11272     
13       informix -        0        -        0        16384      12968     
12       informix -        0        -        0        12288      11272     
10       informix -        0        -        0        16384      12968     
9        informix -        0        -        0        12288      11272     
8        informix -        0        -        0        12288      11272     
7        informix -        0        -        0        12288      11272     
6        informix -        0        -        0        12288      11272     
5        informix -        0        -        0        12288      11272     
4        informix -        0        -        0        12288      11272     
3        informix -        0        -        0        12288      11272     
2        informix -        0        -        0        12288      11272     

IBM161:informix:/home/informix>onstat -g ses 102

Informix Dynamic Server Version 9.30.FC2R1   -- On-Line -- Up 00:26:53 -- 690320 Kbytes

session                                      #RSAM    total      used      
id       user     tty      pid      hostname threads  memory     memory   
102      informix 10       51986    IBM161   1        61440      45968     

tid      name     rstcb            flags    curstk   status
138      sqlexec  7000000202619b8  Y--P---  2736     cond wait(sm_read)

Memory pools    count 1
name         class addr             totalsize  freesize   #allocfrag #freefrag
102          V     700000020e40040  61440      15472      88         9         

name           free       used           name           free       used      
overhead       0          3248           scb            0          144      
opentable      0          3624           filetable      0          1056      
log            0          4216           temprec        0          3960      
keys           0          176            gentcb         0          1648      
ostcb          0          3448           sqscb          0          17240     
sql            0          72             rdahead        0          224      
hashfiletab    0          552            osenv          0          2280      
sqtcb          0          3728           fragman        0          352      

Sess  SQL            Current            Iso Lock       SQL  ISAM F.E.
Id    Stmt type      Database           Lvl Mode       ERR  ERR  Vers
102   -              onpload            CR  Wait 3     0    0    9.03

Last parsed SQL statement :
  

IBM161:informix:/home/informix>
作者: welion    时间: 2009-01-19 13:28
标题: 回复 #8 liaosnet 的帖子
对数据库版本有要求么? 我在10上很顺利,但9.30确经常有问题
作者: liaosnet    时间: 2009-01-19 13:33
标题: 回复 #10 welion 的帖子
onpladm在9.40以上顺利,9.30似乎还是用图形界面的那个吧..
作者: 我是DBA    时间: 2009-01-19 13:48
标题: 回复 #11 liaosnet 的帖子
那我的9.21不知道能不能用。
作者: welion    时间: 2009-01-19 16:44
标题: 回复 #11 liaosnet 的帖子
9.30也可以用命令行了,但就不知道为啥老是死掉,空表没问题,包含了byte大数据就死了
作者: test_123    时间: 2009-01-20 11:17
我到一般是先加载,后建索引..............
作者: wolfop    时间: 2009-01-20 14:12
9.30 这个版本能不用就别用了,用10比较好。
作者: star_wm_craft    时间: 2009-04-01 11:08
原帖由 liaosnet 于 2009-1-16 17:23 发表
用onpladm来做吧...不过做完需要0备一次...

請問onpladm怎么樣加入query的條件?
作者: liaosnet    时间: 2009-04-01 11:20
原帖由 star_wm_craft 于 2009-4-1 11:08 发表

請問onpladm怎么樣加入query的條件?


修改onpload库中的query表里的信息即可...这仅适用导出..导入没办法.....
作者: ducduc    时间: 2009-04-02 16:17
大表装载的时候一般都是先彻到索引,然后加载数据,然后加上索引。不然效率非常非常低,试验过的。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2