Professional Documents
Culture Documents
Explain This - Toad White Paper
Explain This - Toad White Paper
In a well tuned environment, hopefully 9 out of 10 or so of your queries will execute in a reasonable amount of time. If you end up tuning more queries than not, then its likely your problem is with the database and not your SQL. If however, the problem IS with your SQL, then you can ask the database to show you its plan for executing it. Once the plan, or path or strategy to get to the data, is exposed to the user, they can make changes to their query to get the database to take a more efficient route. Oracle has a split second to see your query and come up with a good plan, and then it has to implement the plan, gather the results, and send it back you, the end user. It wont always pick the best plan. There are often many different routes the database can take to get to your data. In the latest versions of Oracle, these paths are chosen based on the metadata collected on the data you are querying. You can influence the route chosen by writing your SQL statement in different ways. If you write your query poorly, its possible Oracle will choose a bad plan. A robust database can often overcome the limitation with poorly written SQL with horsepower or with its self-tuning powered optimizers built into the database. However, there is no such thing YET as the perfect database that allows you to put junk in and get excellence out.
You can also see what a given querys plan was at execution time by viewing a trace file of the appropriate session.
PINNED PLANS
If a query is executed frequently enough, or if it is manually PINNED by a user, Oracle will not generate a plan at execution time. Instead, it will rely on a plan that has already been generated and stored in memory. This memory area is known as the SQL Shared Pool. Toad has a screen (Database Monitor SGA Trace|Optimization that will show you everything in the pool and the statements associated plans. If you are trying to tune a query and do not see the plan changing for your query, you may need to Flush the SGA. This will cause Oracle to re-parse every query submitted and generate new plans on the fly until the Buffer can be built out again. This should not be undertaken lightly as it could cause dramatic performance changes in the short term.
Toads SGA Trace screen shows you all of the cached queries and plans. You can also see execution statistics for each query.
Plan Access Method If you have ever heard or read the words Full Table Scan, then you have some experience with execution plans. Often times this phrase is uttered as a curse or seen as a worst case scenario. Each different type of execution plan step represents a different method for accessing the data. They should not be seen as being inherently good or bad by themselves. If an index is available, then using an index to get to your data CAN be faster than doing a full table scan. However, if you are trying to read in ALL the data from a table, then using an index could generate extra unnecessary work. You may hear things like HASH JOINS are bad, dont ever use those. This probably comes from a place of truth. Your DBA may have seen over the years as they have administered your application that this method is less successful than others. But that doesnt mean it will ALWAYS be bad. So, how can you figure out what each of these plan methods mean? You have two options built into Toad. 1. Knowledge Xpert Available for all commercial Toad users, Knowledge Xpert is a built-in Oracle knowledge repository. Documentation and hints for reading and interpreting execution plans are available by doing a search.
You can bookmark your favorite topics and add custom notes appropriate for your environment.
2. Quest SQL Optimizer When you start a Tuning Lab session (thats right, Toad can tune your queries for you if you have the Xpert edition), the execution plans are also available for review. If you need help interpreting the step, simply mouse-right-click on the step and select the GET HELP ON item.
Excellent documentation for dozens of the most frequently seen execution plan steps is available at the click of a mouse!
Simplify the plan display for easier comprehension In Toad, you can choose to view a plan in several different ways. Your options are available with a mouse-right-click and include: Tree (default) Plain English - Steps listed in numerical order without cost and bytes fields. Graphic Illustration shows the plan in action MS Graphic Execution Plan as seen in MS SQL Server. Tree View:
Graphic View:
MS Graphic View:
2. Toad selectively takes the plan step information from the Plan Table. You may want to see an exhaustive set of information for each step. You can see all of the execution plan data by also right-mouse-clicking in the Explain Plan tab and selecting Single Record View.
3. Save and compare plans. If you are tuning a query, it might be very hard to discern changes between one plan and the next. If you do not have the Xpert edition of Toad (which automatically compares all plans available for a query), you can still use Toad to manually compare 2 plans.