声明查询变量会使它更快吗?

时间:2018-11-02 19:30:52

标签: mysql mariadb query-performance local-variables

我有一个像这样的普通查询

select
    t1c1
from
    t1 
where
    t1c2 <> (select max(t2c1) from t2)
and
    t1c3 < (select max(t2c1) from t2) 
and
    t1c3 >= ((select max(t2c1) from t2) - 20)

但是我想优化它,所以我定义了这样的变量

set @mt2c1 = (select max(t2c1) from t2);

select
    t1c1
from
    t1 
where
    t1c2 <> @mt2c1
and
    t1c3 < @mt2c1
and
    t1c3 >= (@mt2c1 - 20)

定义此变量会使查询更快吗?

0 个答案:

没有答案