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

参考资料

  1. https://github.com/pingcap/tidb
  2. https://www.udacity.com/course/compilers-theory-and-practice–ud168
  3. https://www.icourse163.org/course/HIT-1002123007
  4. https://courses.cs.washington.edu/courses/cse401/16wi/lectures/09-AG-SDT-wi16.pdf
  5. https://courses.cs.washington.edu/courses/cse401/16wi/lectures/10-CYK-Earley-Disambig-wi16.pdf
  6. https://nlogn.art/wp-content/uploads/2023/04/Language-Implementation-Patterns.pdf
  7. https://gist.github.com/tkrs/23ab96cf84284ec6848c1c0a16611e21
  8. https://www.bilibili.com/video/BV1ea41187KK

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注