Eversql Report Query 60923672
Eversql Report Query 60923672
This optimization report was generated by EverSQL, your new personal and automatic DBA. The
report includes the original SQL query, the optimized SQL query, and the indexes we recommend
to create to optimize this query. Please make sure you test the recommendations for both
correctness and performance before applying any changes.
Original Query
WITH t AS (SELECT
temp_cust_film_loc.*,
film_lang.language_id,
film_lang.`name`
FROM
(SELECT
temp_cust_film.*,
city.city,
city.city_id,
country.country_id
FROM
(SELECT
temp_film.*,
inventory.inventory_id,
rental.rental_id,
customer.customer_id,
customer.first_name,
customer.address_id,
customer.last_name,
payment.payment_id,
payment.amount,
payment.payment_date
FROM
(SELECT
film.film_id,
film.title,
category.`name`,
COUNT(film_actor.actor_id) num_of_actors
FROM
film
JOIN
film_actor
ON film.film_id = film_actor.film_id
JOIN
film_category
ON film.film_id = film_category.film_id
JOIN
category
ON category.category_id = film_category.category_id
GROUP BY
film.film_id,
category.`name`) AS temp_film,
payment,
inventory,
rental,
customer
WHERE
temp_film.film_id = inventory.film_id
AND inventory.inventory_id = rental.inventory_id
AND rental.customer_id = customer.customer_id
AND customer.customer_id = payment.customer_id) AS temp_cust_film, address, city, country
WHERE
address.address_id = temp_cust_film.address_id
AND city.city_id = address.city_id
AND country.country_id = city.country_id) AS temp_cust_film_loc,
(SELECT
film.film_id,
"language".language_id,
"language".`name`
FROM
film
JOIN
"language"
ON film.language_id = "language".language_id) AS film_lang
WHERE
temp_cust_film_loc.film_id = film_lang.film_id
ORDER BY
temp_cust_film_loc.title) SELECT
*
FROM
t
Indexing recommendations
These indexes are an integral part of this optimization effort and should be created before testing
the execution duration of the optimized query.
Optimized Query
WITH t AS (SELECT
temp_cust_film_loc.*,
film_lang.language_id,
film_lang.`name`
FROM
(SELECT
temp_cust_film.*,
city.city,
city.city_id,
country.country_id
FROM
(SELECT
temp_film.*,
inventory.inventory_id,
rental.rental_id,
customer.customer_id,
customer.first_name,
customer.address_id,
customer.last_name,
payment.payment_id,
payment.amount,
payment.payment_date
FROM
(SELECT
film.film_id,
film.title,
category.`name`,
COUNT(film_actor.actor_id) num_of_actors
FROM
film
JOIN
film_actor
ON film.film_id = film_actor.film_id
JOIN
film_category
ON film.film_id = film_category.film_id
JOIN
category
ON category.category_id = film_category.category_id
GROUP BY
film.film_id,
category.`name`) AS temp_film,
payment,
inventory,
rental,
customer
WHERE
temp_film.film_id = inventory.film_id
AND inventory.inventory_id = rental.inventory_id
AND rental.customer_id = customer.customer_id
AND customer.customer_id = payment.customer_id) AS temp_cust_film, address, city, country
WHERE
address.address_id = temp_cust_film.address_id
AND city.city_id = address.city_id
AND country.country_id = city.country_id) AS temp_cust_film_loc,
(SELECT
film.film_id,
"language".language_id,
"language".`name`
FROM
film
JOIN
"language"
ON film.language_id = "language".language_id) AS film_lang
WHERE
temp_cust_film_loc.film_id = film_lang.film_id
ORDER BY
temp_cust_film_loc.title) SELECT
*
FROM
t