我读过联接比子查询更好。
但
EXPLAIN QUERY PLAN
SELECT Queue.Id, NULL
FROM Queue
INNER JOIN LastQueue
ON Queue.Id=LastQueue.Id
给
Array
(
[0] => Array
(
[selectid] => 0
[order] => 0
[from] => 0
[detail] => SCAN TABLE Queue (~1000000 rows)
)
[1] => Array
(
[selectid] => 0
[order] => 1
[from] => 1
[detail] => SEARCH TABLE LastQueue USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)
)
)
尽管
EXPLAIN QUERY PLAN
SELECT Queue.Id, NULL
FROM Queue
WHERE (SELECT 1 FROM LastQueue WHERE Queue.Id=LastQueue.Id) IS NOT NULL
给
Array
(
[0] => Array
(
[selectid] => 0
[order] => 0
[from] => 0
[detail] => SCAN TABLE Queue (~500000 rows)
)
[1] => Array
(
[selectid] => 0
[order] => 0
[from] => 0
[detail] => EXECUTE CORRELATED SCALAR SUBQUERY 1
)
[2] => Array
(
[selectid] => 1
[order] => 0
[from] => 0
[detail] => SEARCH TABLE LastQueue USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)
)
)
我想我必须乘以行数才能了解成本。我是对的?
然后,
- 使用连接:1000000*1
- 使用子查询:500000*1*1
那么,子查询是不是比join快呢?
有没有很好的教程来学习如何理解EXPLAIN
/EXPLAIN QUERY PLAN
结果?
当该表有 76 行时,为什么它说 SCAN TABLE Queue 为 ~1000000 和 ~500000?