我有一个大约有 1 亿行的表。必须使用 BETWEEN 运算符。我看到查询运行得很慢。
我在 t.name 上的交易者表第一个上添加了 2 个索引,第二个索引是 t.amount 和 t.price。
查询执行非常缓慢。使用 BETWEEN 运算符时,对价格和金额进行索引是否有帮助。另外,我该如何优化呢?
select t.trader_id, t.name, t.city, t.state
from trader t where exists
(
SELECT null
FROM city_present p,city_state c
WHERE p.name = 'TEST_TEST'
AND c.city = p.city
AND c.state = p.state
AND t.city = c.city
AND t.state = c.state
AND t.price IS NOT NULL
AND t.price between (25.00000 , 58.000000)
AND t.amount IS NOT NULL
AND t.amount BETWEEN (-2500.0000 , 2800.000)
)
AND t.name = 'john test'
AND t.is_valid= 1