The front-end is based on an abstract syntax tree (AST). The parser creates the AST, the analyzer decorates it with semantic information, and the planner creates a plan for it.
At present, the class hierarchy looks like this:
This is a nuisance because the only common base class for all statement-like nodes is the ParseNode, which is also the common base class or expressions. However, expressions and statement-like nodes behave differently during analysis, SQL generation, and so on.
We propose to refactor the tree to introduce a new StmtNode interface or class that defines the statement-like semantics, leaving Expr to define the expression-like semantics. The methods then move out of ParseNode.
This change all allow revising the analysis step as follows:
- Analysis of statement-like nodes is done "in place"
- Analysis of expression nodes may result in replacing one node with a rewritten version
Similarly, when generating SQL:
- Statements provide the option of generating before- or after-rewrite SQL.
- Expressions can only generate SQL for what they are; they have no concept of before- or after- rewrites.
It may be useful to introduce a ClauseNode, but we'll see if that is actually helpful as we do the refactoring: