如何为该查询创建正确的索引?我需要加快此查询的速度。
SELECT q1, q2
LET q1 = (Select ht.* FROM `mybucket` as mb WHERE mb.recdate IN (SELECT RAW MAX(recdate) FROM `mybucket` as mbt WHERE mbt.deviceID = "10101")),
q2 = (Select ht.* FROM `mybucket` as mb WHERE mb.recdate IN (SELECT RAW MAX(recdate) FROM `mybucket` as mbt WHERE mbt.deviceID = "10001"));
答案 0 :(得分:1)
您有两个并行查询,每个查询都有一个子查询。这两个查询非常相似。
您也许可以使用两个索引来做到这一点。
在每种情况下,该查询都适合子查询:
proc.StartInfo.WorkingDirectory = @"c:\new\folder";
在每种情况下,该查询都应适合主要查询:
CREATE INDEX date_deviceid_idx on mybucket(deviceID, recdate)