基本流程

简单的函数调用,最下面为各种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. 未完待续
本文介绍了PostgreSQL中SQL语句的基本执行流程,包括从主函数PostgresMain开始的一系列初始化工作,再到SQL语句如何被转化为命令并进一步解析处理的过程。重点讲解了不同类型的SQL语句如何被解析和执行。
5228

被折叠的 条评论
为什么被折叠?



