以下是引用吹水佬在2021-8-20 20:38:17的发言:
对比测试一下,30W条记录
** 测试数据
CREATE CURSOR ys1 (lxfs C(10))
FOR i=1 TO 300000
INSERT INTO ys1 VALUES (PADL(i,7,"0"))
ENDFOR
CREATE CURSOR fs1 (lxfs C(10))
APPEND FROM DBF("ys1")
SELECT ys1
GO TOP
REPLACE lxfs WITH "ys1_000001"
GO BOTTOM
REPLACE lxfs WITH "ys1_100000"
t = SECONDS()
SELECT ALLTRIM(lxfs) AS MY_KEY from fs1 DIST NOCO INTO TABLE TEMP_KEY
SELECT * FROM ys1 where ALLTRIM(lxfs) NOT in(SELECT MY_KEY FROM TEMP_KEY) NOWAIT
?SECONDS()-t && 5.5s
** 去掉ALLTRIM
t = SECONDS()
SELECT lxfs AS MY_KEY from fs1 DIST NOCO INTO TABLE TEMP_KEY
SELECT * FROM ys1 where lxfs NOT in(SELECT MY_KEY FROM TEMP_KEY) NOWAIT
?SECONDS()-t && 5.0s
t = SECONDS()
SELECT fs1
INDEX on lxfs TAG tag_fs1
SELECT ys1
SET RELATION TO lxfs INTO "fs1"
COPY TO tmp FOR !FOUND("fs1")
SET RELATION TO
?SECONDS()-t && 3.5s
SELECT * FROM tmp NOWAIT
对比测试一下,30W条记录
** 测试数据
CREATE CURSOR ys1 (lxfs C(10))
FOR i=1 TO 300000
INSERT INTO ys1 VALUES (PADL(i,7,"0"))
ENDFOR
CREATE CURSOR fs1 (lxfs C(10))
APPEND FROM DBF("ys1")
SELECT ys1
GO TOP
REPLACE lxfs WITH "ys1_000001"
GO BOTTOM
REPLACE lxfs WITH "ys1_100000"
t = SECONDS()
SELECT ALLTRIM(lxfs) AS MY_KEY from fs1 DIST NOCO INTO TABLE TEMP_KEY
SELECT * FROM ys1 where ALLTRIM(lxfs) NOT in(SELECT MY_KEY FROM TEMP_KEY) NOWAIT
?SECONDS()-t && 5.5s
** 去掉ALLTRIM
t = SECONDS()
SELECT lxfs AS MY_KEY from fs1 DIST NOCO INTO TABLE TEMP_KEY
SELECT * FROM ys1 where lxfs NOT in(SELECT MY_KEY FROM TEMP_KEY) NOWAIT
?SECONDS()-t && 5.0s
t = SECONDS()
SELECT fs1
INDEX on lxfs TAG tag_fs1
SELECT ys1
SET RELATION TO lxfs INTO "fs1"
COPY TO tmp FOR !FOUND("fs1")
SET RELATION TO
?SECONDS()-t && 3.5s
SELECT * FROM tmp NOWAIT
谢谢你的专业指导!!确实不是数据量的问题,是语法有问题,where in()括号里面的子句不能包含alltrim,否则执行不下去。我不知道你用的什么数据测试的,我把对比数据脱敏了,你实测下看看。希望还有人能给出更多的方案!
对比数据.rar
(2.08 MB)
[此贴子已经被作者于2021-8-20 21:21编辑过]
喜欢VFP,就要学懂弄通!