您的位置:首页 > 数据库

postgresql内核分析之SQL解析(1)

2016-01-07 00:00 113 查看
摘要: 本文主要介绍postgres启动以后,SQL语句的处理流程。

基本流程



简单的函数调用,最下面为各种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. 未完待续
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息