How to optimize this SQL query?
In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
- Description of the steps you can take to speed up the query.
- The optimal indexes for this query, which you can copy and create in your database.
- An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
- Prefer Inner Join Over Left Join (modified query below): We identified that one or more left joined entities (e.g. `region_cuboid`) are used in the 'where' clause, in a way that allows to replace it with an optimized inner join. Inner joins can be fully optimized by the database, while Left joins apply limitations on the database's optimizer.
The optimized query:
ON region.id = region_cuboid.region_id
AND region.world_id = region_cuboid.world_id
ON region.id = lot
region.world_id = 10
AND region_cuboid.world_id = 10