【发布时间】:2015-05-13 07:02:58
【问题描述】:
我有以下 SQL 语句:
select cast (count(*) as bigint) from
(SELECT oldtable.id,oldtable.day,newtable.newid from oldtable
left outer join newtable on oldtable.day between newtable.FROM_DAY
and newtable.TO_DAY and oldtable.id = newtable.id) a
结果为 45 亿
但是当我这样说时:
INSERT INTO AnotherTable
(id, day, newid)
SELECT oldtable.id,oldtable.day,newtable.newid from oldtable
left outer join newtable on oldtable.day between newtable.FROM_DAY
and newtable.TO_DAY and oldtable.id = newtable.id
它只插入了 3 亿条记录(oldtable 包含 45 亿条记录,newtable 包含 4.3 亿条记录)。
为什么?
AnotherTable 的定义:
CREATE MULTISET TABLE AnotherTable ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
DEFAULT MERGEBLOCKRATIO
(
id INTEGER NOT NULL,
day DATE FORMAT 'YYYY-MM-DD',
newid INTEGER NOT NULL
)
PRIMARY INDEX ( id)
PARTITION BY RANGE_N(day BETWEEN DATE '2000-09-20' AND DATE '2030-02-15' EACH INTERVAL '1' DAY );
我做了以下检查:
SELECT oldtable.id,oldtable.day,newtable.newid from oldtable
left outer join newtable on oldtable.day between newtable.FROM_DAY and newtable.TO_DAY
and oldtable.id = newtable.id
where newtable.newid is null
结果是0条记录,所以完全不需要外连接,我这里只是用来说明记录数不同,但应该不是
【问题讨论】:
-
您是否有可能对
newid有非空约束?由于left outer join,这可能为NULL。 -
我做了以下检查:
SELECT oldtable.id,oldtable.day,newtable.newid from oldtable left outer join newtable on oldtable.day between newtable.FROM_DAY and newtable.TO_DAY and oldtable.id = newtable.id where newtable.newid is null结果是0条记录,所以根本不需要外连接,我这里只是用它来证明记录号不同,但它不应该是 -
您是否从数据库服务器收到任何错误消息?是否有任何磁盘存储限制问题?如果它继续失败,也许尝试从您的 SQL 选择中生成插入语句,然后运行插入脚本。
-
没有错误信息。磁盘存储设置绰绰有余。
-
您可以发布
AnotherTable的表定义吗?我有预感,但想先看看表定义。 (如果可以的话,实际上发布所有表定义。)