WIP: 拆解 TiDB Parser & Planner 篇
Parser
Lexer
yylval
yyval
ruleTable & tokenMap & windowFuncTokenMap
Yacc
%union 制定 Lexer 的 yylval
%union {
offset int // offset
item interface{}
ident string
expr ast.ExprNode
statement ast.StmtNode
}
https://github.com/mysql/mysql-server/blob/8.0/sql/sql_yacc.yy
https://github.com/pingcap/tidb/blob/master/parser/parser.y
*session.Parse
Planner
Ranger
Logical Plan
*clientConn.handleStmt -> *TiDBContext.ExecuteStmt -> *session.ExecuteStmt -> *Compiler.Compile
SubstiuteGC
PruneColumns
ResultReorder
BuildKey
Decorrelated
RewriteSemiJoin
RewriteSkewDistinctAggregation
EliminateProjection
EliminateMaxMin
PredicatePushDown
EliminateOuterJoin
ProcessPartition
CollectPredicateColumnsPoint
AggregationPushDown
DeriveTopNFromWindow
PredicateSimplification
OptimizeTopNPushDown
SyncWaitStatsLoadPoint
JoinReorder
SequencePushDown
ResolveExpand
Physical Plan
Cascaded Plan
参考资料
- https://github.com/pingcap/tidb
- https://www.udacity.com/course/compilers-theory-and-practice–ud168
- https://www.icourse163.org/course/HIT-1002123007
- https://courses.cs.washington.edu/courses/cse401/16wi/lectures/09-AG-SDT-wi16.pdf
- https://courses.cs.washington.edu/courses/cse401/16wi/lectures/10-CYK-Earley-Disambig-wi16.pdf
- https://nlogn.art/wp-content/uploads/2023/04/Language-Implementation-Patterns.pdf
- https://gist.github.com/tkrs/23ab96cf84284ec6848c1c0a16611e21
- https://www.bilibili.com/video/BV1ea41187KK