Is there any scope of tuning below query and increase the performance
SELECT
i.store_id,
i.film_id,
COUNT(*) AS total,
COUNT(*) - (
SELECT COUNT(*)
FROM rental
WHERE
inventory_id IN (SELECT inventory_id FROM inventory
WHERE inventory.film_id = i.film_id AND
inventory.store_id = i.store_id)
)
FROM `inventory` i
GROUP BY
i.store_id,
i.film_id
Here I am fetching details on how many are there in store and how may rented out .
In my experience, subselects perform poorly in MySQL. Temporary tables may be a better solution.
Turn IN ( SELECT ... )
into a JOIN.
Add INDEX(store_id, film_id, inventory_id)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.