Given an ugly and probably long, inefficient, redundant and complicated looking query, is there a tool that can simplify that for a target database? If not, since the database optimizes queries anyway, is it possible to see the optimized query that the database will use? I’m not interested in the actual query plan but rather the optimized and/or simplified query. Is that possible? I’m interested in answers for any of these databases: MySQL, SQL Server, Postgres, SQLite.
Given an ugly and probably long, inefficient, redundant and complicated looking query, is there
Share
PostgreSQL optimizes the query plan, but that hardly translates to a corresponding SQL query. It’s not the SQL code itself that get re-written. So, no, you cannot derive an optimized SQL query form the optimized query plan unless you have very deep understanding of the inner workings of the query planner.
You can find out whether indexes get used or the query planner chooses a table scan instead and other helpful details by looking at the output of EXPLAIN ANALYZE.