基本流程
简单的函数调用,最下面为各种SQL语句的具体处理。
函数及说明
首先进入主函数PostgresMain,经过一系列初始化等准备工作以后,进入这个循环:
for (;;)
下面这个函数将select等SQL语句转化成命令:
firstchar = ReadCommand(&input_message);
firestchar其实就是一个asc码值,被下面的switch所用:
switch (firstchar)
每个case对应一个命令,绝大多数的SQL进入到exec_simple_query函数进行解析
exec_simple_query(const char *query_string)
进入pg_analyze_rewrite函数,生成querytree
querytree_list = pg_analyze_and_rewrite(parsetree, query_string,NULL, 0);
parser_analyze函数,解析一个parser tree,转换成Query结构
query = parse_analyze(parsetree, query_string, paramTypes, numParams);
处理SELECT ... INTO into CREATE TABLE AS
transformTopLevelStmt(ParseState *pstate, Node *parseTree)
处理除上述语句以外的其他SQL,包含insert,delete,update,select,explain等等。。。
transformStmt(ParseState *pstate, Node *parseTree)
3. 未完待续