Categories: Contributing | Development | MySQLUniversity | Optimizer

How does the MySQL Optimizer work

← Back to MySQL University main page
 Presenter: Timour Katchaounov
 Time: Thursday 29. March 2007 RESCHEDULED to:
 Time: Thursday 05. April 2007, at 6am PST = 9am EST = 15 CET = 16 EET
 Estimated length of Session: '01:30 to 2:00 h'presenter to fill in here - note max 3 hours
 Moderator: Patrik Backman
 Scribe: Paul DuBois
 Attendees: To register for this Session - Please enter your name here: 
 Brian Miezejewski
 Alexander Nozdrin
 Andrey Hristov
 Hakan Kuecuekyilmaz
 Marc Alff
 Sergei Golubchik
 Giuseppe Maxia
 User:TatjanaNurnberg
 Matthias Leich
 Axel Schwenke
 LarsThalmann
 Chris Powers
 IgnacioGalarza
 Jeffrey Pugh
 User:TimSmith
 User:GuilhemBichot
 GeorgiKodinov
 SergeyPetrunia
 Max Mether
 Kristofer Pettersson
 Holyfoot
 Jess Balint
 Oleksandr Byelkin
 David Swain
 Evgeny Potemkin
 Josh Chamas
 David Axmark

Contents

[edit] How_does_the_MySQL_Optimizer_work

https://inside.mysql.com/mywiki/skins/common/images/button_italic.png Presentation slides: PDF slides

[edit] Outline

[edit] “Query optimizer” = “automatic program generator”

[edit] Query execution

[edit] Query Execution Plans as operator trees

[edit] Example: “World” database

[edit] Query Execution Plans as operator sequences

[edit] Basic nested loops join

 procedure nested_loops_join
 input: <OP_i, ..., OP_n> - the remainder of a QEP
                              that has not been computed yet
 {
   if (init_record_scan(Table_i, Access_i, Cond_i) == EOF)
     return
 
   while (curr_row_i = get_next_record(Table_i, Aaccess_i, Cond_i))
   {
     joined_row = <curr_row_1 || ... || curr_row_i>
 
     if JoinCondition_i(joined_row) /* Test the join condition. */
     {
       if joined_row is a complete result tuple (i.e. i = n)
         output joined_row
       else
         nested_loops_join(<OP_[i+1], ..., OP_n>)
     }
   }
 }

[edit] Architecture

[edit] Query engine architecture

[edit] MySQL architecture

[edit] Query optimizer modules: highly interwoven

[edit] Query optimizer outline

[edit] Query optimization: logical transformations

[edit] Equality propagation

[edit] Nested outer join execution, outer => inner transformation

[edit] Cost-based query optimization

[edit] Cost model

[edit] Table-order independent optimization

[edit] The ref optimizer

SELECT * FROM t1,t2,t3 WHERE t1.a = t3.c AND t2.b = t3.c;

Given indexes t1(a), t2(b) and t3(c), the ref optimizer produces the equi-join graph:

   t1-- a ->- c ---    --- c -<- b --- t2
    ^             |    |               ^
    |             |    |               |
     -- a -<- c - v    v-- c ->- b ----|
                    t3

where the arcs mean: [source of lookup value] -> [table/column to lookup]

[edit] Constant table detection/propagation

[edit] The range optimizer

[edit] Cost-based join optimization

[edit] Query optimization - exhaustive search

[edit] Depth-first search illustrated

[edit] The cost of optimization

[edit] The “greedy” search procedure

[edit] Controlling the optimizer

[edit] Plan refinement

[edit] Topics for future presentations



[edit] Session notes

[edit] Questions posted for the Session

SLIDE 8: Basic nested loops join

SLIDE 10: Query engine architecture

timour: Preprocessor ~ JOIN::prepare
timour: Optimizer ~ JOIN::optimize

SLIDE 11: MySQL architecture

SLIDE 17: Cost-based query optimization

SLIDE 24: Query optimization - exhaustive search

SLIDE 27: The "greedy" search procedure

Post-Slide Discussion

joro: here's our optimizer team KB page : https://inside.mysql.com/wiki/OptimizerKBAndTodo

Retrieved from "http://forge.mysql.com/wiki/How_does_the_MySQL_Optimizer_work"

This page has been accessed 2,862 times. This page was last modified 00:38, 31 October 2007.

Find

Browse
MySQLForge
Main Page
Current events
Recent changes
Random page
Help
Edit
Edit this page
Editing help
This page
Discuss this page
Post a comment
Printable version
Context
Page history
What links here
Related changes
My pages
Special pages
New pages
File list
Statistics
Bug reports
More...