第一个代码无法在MonetDB中执行:
SELECT rc0.id as runcat, x0.id as xrtcat
FROM extractedcatalog x0
INNER JOIN image i0
ON i0.id = 1 AND i0.id = x0.image
INNER JOIN runningcatalog rc0
ON rc0.zone BETWEEN x0.zone-1
AND x0.zone+1
AND rc0.wm_decl BETWEEN x0.decl - i0.rb_smaj
AND x0.decl + i0.rb_smaj
AND rc0.x*x0.x +rc0.y*x0.y +rc0.z*x0.z >cos(radians(i0.rb_smaj));
连接已终止!
但是下面的代码可以很快执行,为什么????
SELECT rc0.id as runcat, x0.id as xrtcat
FROM extractedcatalog x0
INNER JOIN image i0
ON i0.id = 1 AND i0.id = x0.image
INNER JOIN runningcatalog rc0
ON rc0.zone BETWEEN x0.zone-1
AND x0.zone+1
AND rc0.wm_decl BETWEEN x0.decl - i0.rb_smaj
AND x0.decl + i0.rb_smaj
AND rc0.x*x0.x +rc0.y*x0.y +rc0.z*x0.z >cos(radians(0.0055));
在表格图片中,只有一行:id = 1,rb_smaj = 0.0055。 非常感谢!
答案 0 :(得分:0)
如果唯一的区别是cos,请将此数字保存为数据库字段并在其上添加索引。
答案 1 :(得分:0)
不同之处在于第一个查询在每个行加入时执行cos()
(可能是数百万次执行,具体取决于行数限定),但第二个执行`cos( )对于整个查询只需一次,所以很多更快。
如果您希望第一个查询快速执行,请尝试将条件移动到WHERE子句,以便cos()
每行image
只需一次:
SELECT rc0.id as runcat, x0.id as xrtcat
FROM extractedcatalog x0
INNER JOIN image i0
ON i0.id = 1 AND i0.id = x0.image
INNER JOIN runningcatalog rc0
ON rc0.zone BETWEEN x0.zone-1 AND x0.zone+1
AND rc0.wm_decl BETWEEN x0.decl - i0.rb_smaj AND x0.decl + i0.rb_smaj
WHERE rc0.x*x0.x +rc0.y*x0.y +rc0.z*x0.z > cos(radians(i0.rb_smaj))
如果这不起作用,请尝试创建内部查询以选择条件中包含的列加上cos()
结果,并在其上放置where子句。