Resolving binding variable execution plan skew by rebuilding execution plan causes SQL execution time to be too long

Source: Internet
Author: User

Basic elements (time, user, problem) the user in the 11G environment has a section of SQL statements in the program is very inefficient execution, but in plsql execution is very fast, by looking at the execution plan, found that the use of different indexes caused, the program executes the following:

The effects performed in Plsql are as follows:

You can see the difference, the use of outpatient expense records _IX_ Registration time index is the execution plan in Plsql, the use of outpatient expense records _uq_no is the execution plan in the program, both SQL is exactly the same, the only thing is that the former uses the binding variable, the latter is directly with the parameter value execution. Problem analysisThe problem is obvious, because the binding variable generated by the execution plan and the actual deviation, 11g would have a binding variable snooping function, but obviously there is no use, the analysis is very likely to be a problem with the statistical information, need to re-collect the relevant business table statistics, the corresponding SQL to regenerate the execution plan.
Resolution StepsTo re-collect statistics on related business tables, we should note that the collection of recommendation 100%, if sampled, may not accurately generate histograms, and will also result in execution plan deviations, executing the following statement:
exec dbms_stats.gather_table_stats (ownname = ' zlhis ', tabname = ' outpatient fee record ', estimate_percent = 100,method_opt = ' For all indexed columns size 254 ', no_invalidate = False,cascade = True,force = True,degree =>4);
here we have addedno_invalidate =false, which indicates that the execution plan for the SQL statement that designed the object is regenerated after the statistics have been collected .Once the execution is complete, review the execution plan again and the system is working correctly.
Key points of knowledgeSQL statements that have bound variables, and if there is an execution plan bias, it is recommended that the statistics for the related business tables be re-collected.




Resolving binding variable execution plan skew by rebuilding execution plan causes SQL execution time to be too long

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.