我是 SQL 新手,正在尝试查询大型数据库,因此速度是个问题。我一直在使用如下所示形式的查询(第1行),它工作正常,但是当我修改它(将第1行切换为第2行)以使用常量进行剪切而不是在其中派生的值查询本身然后查询明显变慢(1的运行时间是~1秒,2是几分钟)。我实际上预计它会更快。有人可以解释为什么会发生这种情况或建议我如何更好地重写此查询吗?
谢谢
询问
with local_sample as
( SELECT b.mass, ...various other columns selected...
FROM table1 TAB, table2 b
WHERE ...a few clauses... )
SELECT min(prog.num), LTAB.mass, ...various other columns...
from local_sample LTAB, table2 prog
WHERE ...a few clauses...
[**1**] and prog.mass > LTAB.mass/2.0
[**2**] and prog.mass > 31.62
group by ...columns...