sql优化
程序员文章站
2022-05-12 21:21:28
...
SELECT DISTINCT
t1.no
FROM
tab1e1 t1,
tab1e2 t2
WHERE
t1.code = t2.code
0.01 s
SELECT
t.no
FROM
(
SELECT DISTINCT
t1.no
FROM
table1 t1,
table2 t2
WHERE
t1.code = t2.code
) t limit 0,10;
0.29s
前面查出来的数据, 进行limit 遍历 所以慢
优化为
SELECT
t.no
FROM
(
SELECT DISTINCT
t1.no
FROM
table1 t1,
table2 t2
WHERE
t1.code = t2.code limit 0,10
) t ;
0.01s
t1.no
FROM
tab1e1 t1,
tab1e2 t2
WHERE
t1.code = t2.code
0.01 s
SELECT
t.no
FROM
(
SELECT DISTINCT
t1.no
FROM
table1 t1,
table2 t2
WHERE
t1.code = t2.code
) t limit 0,10;
0.29s
前面查出来的数据, 进行limit 遍历 所以慢
优化为
SELECT
t.no
FROM
(
SELECT DISTINCT
t1.no
FROM
table1 t1,
table2 t2
WHERE
t1.code = t2.code limit 0,10
) t ;
0.01s