语句优化,求解
--两表结构完全相同,数据量都在500万以上,有什么办法能提高这条语句的查询速度
SELECT *
FROM T_AAA A, T_BBB B
WHERE A.ID = B.ID
AND ABS(A.FIELD1 - B.FIELD1) <= 10
AND ABS(B.FIELD2 - B.FIELD2) <= 100;
慢就慢在
AND ABS(A.FIELD1 - B.FIELD1) <= 10
AND ABS(B.FIELD2 - B.FIELD2) <= 100;
这两句话了,求如何改善语句提高查询速度
------解决方案--------------------新建一个统计表,保存SELECT *
FROM T_AAA A, T_BBB B
WHERE A.ID = B.ID
将计算结果ABS(A.FIELD1 - B.FIELD1)保存到统计表中
------解决方案--------------------1.
ABS(B.FIELD2 - B.FIELD2) <= 100;
这个有点问题吧,其结果始终是0
2.
FIELD2,FIELD1的值的分布情况大概说一下,比如说正负情况
------解决方案--------------------
AND ABS(A.FIELD1 - B.FIELD1) <= 10
AND ABS(a.FIELD2 - B.FIELD2) <= 100;
改成
and a.field1<=b.field1+10 and a.field1>=b.field1-10
and a.field2<=b.field2+100 and a.field2>=b.field2-100
试试,建a表中field1和field2、id的联合索引