

Even if you improve performance 99 our of 100 queries there are going to be countless users complaining about the change. Make it Plugable Every Major optimizer change causes a lot of pain for some of the users. Here are some general ideas which I think can help to make optimizer in MySQL, MariaDB or Drizzle better. For probably last 10 years I chased first Monty and later Igor with Optimizer complains and suggestions. Their application is alerted that the SQL is done executing and there are rows to be dealt with.I spend large portion of my life working on MySQL Performance Optimization and so MySQL Optimizer is quite important to me. The result set that arrives at statement id 0 is the final result of the execution of the SQL and the rows in here are then passed to the cursor area in the user’s program global area. If the next step is a join type, then it becomes the outer table. These result sets are like temporary tables that are not visible. There are hints to enforce this behavior at each step mentioned or to inhibit the behavior altogether.Įach step of the execution plan produces a result set that is passed to the next step of the plan.

#MYSQL OPTIMIZER COST MODEL CODE#
In addition to the code shuffling of the permutations, Oracle9i introduced query transformations or more aggressive internal rewrites of the SQL. Query transformations introduced in Oracle 9i This process is repeated until Oracle is satisfied that it has tried all combinations of tables and where clause predicates available including trying all three join types (if there are more than one table listed in the SQL). If the new overall cost is lower, the prior permutation is discarded and the current permutation becomes the ‘lowest cost’ SQL. It is this overall cost number that is compared to the additional cost numbers from the prior permutation. The cost number on statement id 0 is the overall cost of the SQL being processed. The CBO is a single code set that takes a SQL statement in and returns an execution plan and cost numbers. The CBO takes longer to hard parse so it is a good practice to use bind variables and other coding techniques to help Oracle find the SQL from prior executions rather than performing this hard parse task for every submitted SQL.


The library cache was smaller and maintaining a high hit ratio of the SQL that had been hard parsed was more of the issue. The time spent hard parsing was not the issue back in the day. The RBO produced an execution plan with a single pass of the SQL text. The SQL with the lowest cost is perceived to be the fastest executing SQL.ĬBO: processes regular queries looking for the overall lowest cost.ĬBO: partitioned queries look for the fastest elapse time. Oracle then shuffles the code, trying different combinations of tables and where clause predicates in an attempt to find the lowest overall cost. Oracle gives the CBO a SQL statement and gets cost numbers and an execution plan back. CBO picks the one with the overall lowest cost. CBO processes multiple iterations of explain plans (called permutations).
