`
hillmover
  • 浏览: 34473 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

Parser and Optimizer

阅读更多

The MySQL server receives queries in the SQL format. Once a query is received, it first needs to be parsed, which involves translating it from what is essentially a textual format into a combination of internal binary structures that can be easily manipulated by the optimizer.

MySQL's optimizer has several important tasks:
. Determine which keys can be used to retrieve the records from tables, and choose the best one for each table.
. For each table, decide whether a table scan is better than reading on a key. If there are a lot of records that match the key value, the advantages of the key are reduced and the table scan becomes faster.
. Determine the order in which tables should be joined when more than one table is present in the query.
. Rewrite the WHERE clause to eliminate dead code, reducing the unnecessary computations and changing the constraints whenever possible to open the way for using keys.
. Eliminate unused tables from the join.
. Determine whether keys can be  used for ORDER BY and GROUP BY.
. Attempt to replace an outer join with an inner join.
. Attempt to simplify subqueries, as well as determine to what extent their results can be cached.
. Merge views.

Using EXPLAIN to Understand the Optimizer
The MySQL EXPLAIN command tells the optimizer to show its query plan.
E.g,
EXPLAIN SELECT ... \G
Understanding the output of EXPLAIN

EXPLAIN FIELD DESCRIPTION  

id

QueryID. Meaningful only when subqueries are used.

 

 

select_type

Indicates what happens with the result set retrieved from the table. A join not involving subqueries or UNION will have this value set to simple. See the upcoming section "Select types" for details.

 
table The alias the table is referenced by in the query. If no alias is used, the real name of this table.  
type The method used for retrieving the records from the table. See the upcoming section "Record access types" for details.  
possible_keys A list of keys that can be used in conjunction with the WHERE clause to retrieve the records from this table.  
key The name of the key used for retrieving the records. When index_merge optimization is used, contains a list of keys.  
key_len The length of the key used in a query. This does not have to be the full length of the key - it is possible to use only a key prefix.  
ref A list of fields from other tables whose values are involved in an index lookup in this table.  
rows Average estimated number of records in this table to be retrieved on each join iteration.  
Extra Additional comments on the optimization strategy. See the section "Extra field" for details.  

分享到:
评论

相关推荐

    Writing Compiler and Interpreter - A Software Engineering Approach

    - **语法分析器(Parser)**:基于语法规则对词法分析器产生的标记进行分析,构建抽象语法树(AST)。 - **语义分析器(Semantic Analyzer)**:检查源代码是否符合语言的语义规则,并添加必要的符号表信息。 - **代码...

    Mlbase-Evan Spark and Ameet Talwalker UC Berkeley

    为了实现这些目标,MLbase提出了一个框架,其中包含用户、主服务器(Master Server)、元数据(Meta-Data)、机器学习库(ML Library)、统计解析器(Statistics Parser)、执行器/监控器(Executor/Monitoring)等...

    Compilers and Compiler Generators in C++.rar

    - **语法分析器(Parser)**:根据语言的语法规则解析标记流,构建抽象语法树(AST)。 - **语义分析器(Semantic Analyzer)**:检查源代码的语义是否正确,并为后续阶段提供类型信息。 - **优化器(Optimizer)...

    龙书 编译器

    《龙书 编译器》源自著名的计算机科学教材——《Compilers: Principles, Techniques, and Tools》,通常被称为“龙书”。这本书由Alfred V. Aho、Monica S. Lam、Ravi Sethi和Jeffrey D. Ullman四位专家合著,是...

    compass-reference.pdf

    - **Query Parser**:解析查询字符串,将其转换为可执行的搜索命令。 - **Index Structure**:索引结构决定了如何组织和存储索引数据。 - **Transaction**:事务管理是 Compass 中的关键组件之一,确保了数据的一致...

    数据库学习文档

    7. **Cache and Buffer**:MySQL使用多种缓存机制来提升性能,包括查询缓存(Query Cache)、表缓存(Table Cache)、记录缓存(Record Cache)、键缓存(Key Cache)和权限缓存(Permission Cache)。查询缓存尤其...

    图神经网络构建代码

    args.cuda = not args.noCuda and torch.cuda.is_available() torch.manual_seed(args.seed) if args.cuda: torch.cuda.manual_seed(args.seed) if args.hop != 'auto': args.hop = int(args.hop) if args....

    嵌入式数据库SQLITE3使用指南

    - **查询优化器(QueryOptimizer):** 优化虚拟机指令序列,提高执行效率。 后端则涉及: - **虚拟机(VirtualMachine):** 执行虚拟机指令序列。 - **文件系统接口(FilesystemInterface):** 提供文件操作功能...

    hibernate.properties

    ## select the classic query parser #hibernate.query.factory_class org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory ################# ### Platforms ### ################# ## JNDI ...

Global site tag (gtag.js) - Google Analytics