Retired Note one #mysql = Lambda Sql:sql + & #39; Source Code 4 Explain Plan & #39;

Source: Internet
Author: User

The Mysql query run process is broadly divided into 4 stages:


Grammar analysis (sql_parse.cc< lexical analysis, grammar analysis, semantic check >)

>>sql_resolver.cc # Join.prepare

Generate logical Query plan (sql_optimizer.cc)

>># join.optimize

Generate physical query plan (sql_planner.cc)

Run the explain plan (sql_executor.cc) join.exec





Join.prepare ():

Redundant clause elimination for subqueries

In type subquery optimization Resolve_subquery ()

To optimize a simple subquery by converting a all/any type subquery to a MIN/MAX operation


Join.optimize ():

Subquery Pull-up flatten_subqueries ()

Optimize the outer connection for internal connection simplify_joins ()

Eliminate nested connections

WHERE clause, join/on clause, having clause simplification, expression simplification with constants, equation merging Optimize_cond () Opt_sum_query ()

Optimization does not have a GROUP BY clause under the COUNT (*) min () man ()

Determine multi-table connection path Make_join_statistice ()

Optimize distinct

Create temporary table storage temporary results optimized grouping sort Choose_table_order ()


In fact, logical and physical optimization, a bit confusing, not understood,

Is that after the physical query optimization, some logical optimizations are continued.





There are only two types of single-table scans:

Index Scan (others), table Scan (Jt_all)

Opt_range.h > class quick_select_i > Using index to scan total drop interface

See source code for several sub-categories;




Basic classes and structs:

Query Tree Class St_select_lex

Index struct St_key_create_information class Key_part_spec

Connection Table St_join_table

Connection Class Join:public Sql_alloc

Condition Cond_equal

Position struct St_position

Cost Estimation cost_estimate
















SELECT now (), Curdate (), Curtime ()




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.