Build a MYSQL Query and Optimise

Job ID: 35129150

Budget: ₹600 – ₹1,500 INR

The MySQL query below takes about 12-14 seconds to execute. Please examine the datatables and the query and share the following -

1. Optimized version of the query with average time taken

2. What do you think was wrong with the existing query ?

Note - please assume all the joins are mandatory in the given query
3. What were the main improvements done ?

Query :
select distinct name ad_type from dim_ad_type x
where exists
( select 1
from sum_adserver_dimensions sum
left join dim_ad_tag_map on dim_ad_tag_map.id=sum.ad_tag_map_id and dim_ad_tag_map.client_id=sum.client_id
left join dim_site on dim_site.id = dim_ad_tag_map.site_id
left join dim_geo on dim_geo.id = sum.geo_id
left join dim_region on dim_region.id=dim_geo.region_id
left join dim_device_category on dim_device_category.id=sum.device_category_id
left join dim_ad_unit on dim_ad_unit.id=dim_ad_tag_map.ad_unit_id
left join dim_monetization_channel on dim_monetization_channel.id=dim_ad_tag_map.monetization_channel_id
left join dim_os on dim_os.id = sum.os_id
left join dim_ad_type on dim_ad_type.id = dim_ad_tag_map.ad_type_id
left join dim_integration_type on dim_integration_type.id = dim_ad_tag_map.integration_type_id
where sum.client_id = 50 and dim_ad_type.id=x.id ) order by 1
Connection details -
hostname: 3.140.81.188:3306
Database: perftestcase
UserID & Password : dwh / cV6!lS9=sQ2^rY9~