我有以下 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 亿条记录)。
为什么?
另一个表的定义:
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条记录,所以根本不需要外连接,我这里只是用来说明记录号不一样,但不应该