**重点内容**_原创文章,转载请注明: 转载自 镜中影的技术博客_
本文链接地址: OceanBase SQL解析源码分析(二)
URL:http://blog.csdn.net/linkpark1904/article/details/50778795
三、OceanBase语法树描述
3.1 语法树节点的定义
OceanBase语法树节点的定义在parse_node.h文件中,具体语法树节点的定义如下代码所示:
typedef struct _ParseNode
{
ObItemType type_;
/* attributes for terminal node, it is real value */
int64_t value_;
const char* str_value_;
/* attributes for non-terninal node, which has children */
int32_t num_child_;
struct _ParseNode** children_;
// BuildPlanFunc m_fnBuildPlan;
} ParseNode;
其中ObItemType表示节点的具体类型,在OceanBase中将语法树节点分为多种多样的类型,在词法分析中可以看出节点类型有T_INT,T_NULL,T_DOUBLE等等,这些语法树节点具体的类型定义在ob_item_type.h文件中,这些类型均属于枚举类型。对于终结节点,int64_t value_以及const char* str_value_存储的是节点具体的值,而对于非终结节点int32_t num_child_和struct_ParseNode** children_分别存储子节点的个数和指向子节点的指针,这样就可以构建出一颗完整的树了。
另外一个相对重要的数据结构是ParseResult,这个是用来存储解析结果的数据结构,也就是解析出的语法树,具体其数据结构设计如下所示:
typedef struct _ParseResult
{
void* yyscan_info_;
ParseNode* result_tree_;
const char* input_sql_;
int input_sql_len_;