我有以下SQL语句:插入从选择(Teradata数据)
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
这导致4.5十亿
,但是当我这样说:
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亿条记录(旧表包含45亿条记录,新增4.3亿条记录)。
为什么?
AnotherTable的definiton:
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'有非NULL约束?由于“left outer join”,这可能是NULL。 – 2013-04-29 13:01:50
我提出了以下检查: 'SELECT oldtable.id,oldtable.day,newtable.newid从oldtable 左外连接newtable的上newtable.FROM_DAY 和newtable.TO_DAY和oldtable.id = newtable的之间oldtable.day。id where newtable.newid is null' 它导致了0条记录,所以根本不需要外部连接,我只是在这里用它来证明记录号是不同的,但它不应该是 – 2013-04-29 13:05:55
您是否收到任何来自数据库服务器的错误消息?是否有任何磁盘存储限制问题?如果它继续失败,可能尝试从SQL select中生成插入语句,然后再运行插入脚本。 – 2013-04-29 13:16:16