How to see the actual optimized SQL query in a database
Databases usually optimize queries before executing them. For a query issued using JDBC or a command line client is i开发者_StackOverflowt possible to see the actual optimized query that was executed by the database. I am using Oracle Database.
I think you misunderstand - the EXPLAIN PLAN shows you a summarization of what the optimizer sees, not a defacto query:
Rows Execution Plan
-------- ----------------------------------------------------
12 SORT AGGREGATE
2 SORT GROUP BY
76563 NESTED LOOPS
76575 NESTED LOOPS
19 TABLE ACCESS FULL CN_PAYRUNS_ALL
76570 TABLE ACCESS BY INDEX ROWID CN_POSTING_DETAILS_ALL
76570 INDEX RANGE SCAN (object id 178321)
76563 TABLE ACCESS BY INDEX ROWID CN_PAYMENT_WORKSHEETS_ALL
11432983 INDEX RANGE SCAN (object id 186024)
What decisions the optimizer makes, are based on statistics on the tables involved and any indexes. Refreshing statistics can dramatically change if things have changed enough.
精彩评论