次のクエリで常にタイムアウトが発生します。
select * FROM `products`
where
`active`=1
and `group`=6
and `id` not in (select `id` from `purcheased` where `userId`=14 and `price`>100
and `reversed`=0)
order by `price` asc limit 0,500
これは実行に 0.01 秒かかり、この特定のケースでは 0 の結果が返されます。
select `id` from `purcheased` where `userId`=14 and `price`>100 and `reversed`=0
これは .02 秒で実行されます。
select * FROM `products`
where
`active`=1
and `group`= 6
order by `price` asc limit 0,500
完全なクエリ
select * FROM `products`
where
`active` = 1
and `group` = 6
and `id` not in (
select `id` from `purcheased`
where
`userId`=14
and `price` > 100
and `reversed`=0
)
order by `price` asc limit 0,500
60秒実行!
id
select from purcheased
... の各行に対して実行されているため、これが起こっていると思いますproducts
。
私はmysqlでクエリを実行しています。
id
一度選択を実行しpurcheased
て、結果を再利用するように mysql に指示するにはどうすればよいですか?