为什么 CREATE Temporary TABLE 然后 INSERT INTO Temporary TABLE SELECT... FROM (方式1) 的速度比 SELECT... INTO T...

为什么 CREATE Temporary TABLE 然后 INSERT INTO Temporary TABLE SELECT... FROM (方式1) 的速度比 SELECT... INTO TEMP (方式2)慢很多[@more@]

为什么 CREATE Temporary TABLE 然后 INSERT INTO Temporary TABLE SELECT... FROM (方式1) 的速度比 SELECT... INTO TEMP (方式2)慢很多

如果配置参数 DBSPACETEMP 指定两个及以上的数据库空间

一、 以方式1创建的临时表将在某个指定的数据库空间创建临时表。
以上见:《IBM Informix SQL 指南:语法.pdf》11.50版本中的第273页

如果创建多个临时表,则临时表会分别创建在不同的数据库空间上。

举例:
% dbaccess fmdb -

Database selected.

> create temp table t1(c1 int);

Temporary table created.

> create temp table t2(c1 int);

Temporary table created.

> SELECT trim(n.dbsname) type,
> trim(n.owner) users,
> trim(n.tabname) table,
> trim(dbinfo('DBSPACE', i.ti_partnum)) dbspace,
> round(i.ti_nptotal*4,0) kb -- 4 for AIX, 2 for HP-UX
> FROM sysmaster:systabnames n, sysmaster:systabinfo i
> WHERE (sysmaster:bitval(i.ti_flags, 32) = 1
> OR sysmaster:bitval(i.ti_flags, 64) = 1
> OR sysmaster:bitval(i.ti_flags, 128) = 1)
> AND i.ti_partnum = n.partnum
> ;

type fmdb
users informix
table t1dbspace tmpdbs01
kb 32

type fmdb
users informix
table t2dbspace tmpdbs02kb 32

2 row(s) retrieved.

>

可见:每一次创建临时表时所使用的数据库空间都会与上一次创建临时表的数据库空间不一样。

二、 以方式2创建表则临时表会循环分片存贮在 DBSPACETEMP 指定的数据库空间上。
以上见:《IBM Informix SQL 指南:语法.pdf》11.50版本中的第273页

举例:
% dbaccess fmdb -

Database selected.

> select * from systables into temp t1;

88 row(s) retrieved into temp table.

> SELECT trim(n.dbsname) type,
> trim(n.owner) users,
> trim(n.tabname) table,
> trim(dbinfo('DBSPACE', i.ti_partnum)) dbspace,
> round(i.ti_nptotal*4,0) kb -- 4 for AIX, 2 for HP-UX
> FROM sysmaster:systabnames n, sysmaster:systabinfo i
> WHERE (sysmaster:bitval(i.ti_flags, 32) = 1
> OR sysmaster:bitval(i.ti_flags, 64) = 1
> OR sysmaster:bitval(i.ti_flags, 128) = 1)
> AND i.ti_partnum = n.partnum
> ;

type fmdb
users informix
table t1dbspace tmpdbs01kb 32

type fmdb
users informix
table t1dbspace tmpdbs02kb 32

type fmdb
users informix
table t1dbspace tmpdbs03kb 32

3 row(s) retrieved.

>

可见:临时表 t1 被分片到 3 个数据库空间上。

对存储过程 sysmaster:bitval 的说明:
{ Stored procedure for setting boolean 'columns' in views for flags values }
create procedure bitval ( bitset int, bitmask int) returning int;
if (bitset < 0) then
if (bitmask < 0) then
return 1;
end if;
let bitset = bitset + 2147483648;
end if;
if (bitset > 1073741824) then
if (bitmask = 1073741824) then
return 1;
end if;
end if
if (mod(bitset,2*bitmask) >= bitmask) then
return 1;
end if
return 0;
end procedure;
grant execute on bitval to public;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22565551/viewspace-1033310/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22565551/viewspace-1033310/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值