本节简单介绍了postgresq
本节简单介绍了postgresql在执行parse中重要的两个数据结构:SelectStmt&Value.
SelectStmt
“simple” SELECT可转换为SelectStmt节点.包含集合操作(UNION, INTERSECT, EXCEPT)的查询通过SelectStmt节点树来表示,在这棵树中,叶子节点是SELECTs组件,而内部节点表示UNioN, INTERSECT, or EXCEPT操作符.内部节点和叶子节点是相同的节点类型.
typedef enum SetOperation
{
SETOP_NONE = 0,
SETOP_UNION,
SETOP_INTERSECT,
SETOP_EXCEPT
} SetOperation;
typedef struct SelectStmt
{
nodeTag type;
//NULL,DISTINCT ON表达式链表,或者所有(SELECT DISTINCT)的lcons(NIL,NIL)
List *distinctClause;
//SELECT INTO的target
IntoClause *intoClause;
//目标链表(元素为ResTarget)
List *targetList;
//FROM子句
List *fromClause;
//WHERE
Node *whereClause;
//GROUP BY 子句
List *groupClause;
//HAVING条件表达式
Node *havingClause;
//窗口函数链表
List *windowClause;
List *valuesLists;
//排序子句
List *sortClause;
//limit偏移
Node *limitOffset;
//limit个数
Node *limitCount;
//FOR UPDATE
List *lockinGClause;
//CTE
WithClause *withClause;
//操作类型
SetOperation op;
bool all;
//左边树
struct SelectStmt *larg;
//右边树
struct SelectStmt *rarg;
} SelectStmt;
Value
相同的Value结构体用于5中节点类型:T_Integer, T_Float, T_String, T_BitString, T_Null
#ifndef VALUE_H
#define VALUE_H
#include "nodes/nodes.h"
typedef struct Value
{
NodeTag type;
union ValUnion
{
int ival;
char *str;
} val;
} Value;
#define intVal(v) (((Value *)(v))->val.ival)
#define floatVal(v) atof(((Value *)(v))->val.str)
#define strVal(v) (((Value *)(v))->val.str)
extern Value *makeInteger(int i);
extern Value *makeFloat(char *numericStr);
extern Value *makeString(char *str);
extern Value *makeBitString(char *str);
#endif
N/A
-- 用于测试的查询语句
testdb=# select t_dwxx.dwmc,t_grxx.grbh,t_grxx.xm,t_jfxx.ny,t_jfxx.je
testdb-# from t_dwxx,t_grxx,t_jfxx
testdb-# where t_dwxx.dwbh = t_grxx.dwbh
testdb-# and t_grxx.grbh = t_jfxx.grbh
testdb-# and t_dwxx.dwbh IN ('1001','1002')
testdb-# order by t_grxx.grbh
testdb-# limit 8;
dwmc | grbh | xm | ny | je
-----------+------+------+--------+--------
X有限公司 | 901 | 张三 | 201801 | 401.3
X有限公司 | 901 | 张三 | 201802 | 401.3
X有限公司 | 901 | 张三 | 201803 | 401.3
Y有限公司 | 902 | 李四 | 201801 | 513.1
Y有限公司 | 902 | 李四 | 201802 | 513.3
Y有限公司 | 902 | 李四 | 201804 | 513.3
Y有限公司 | 903 | 王五 | 201801 | 372.22
Y有限公司 | 903 | 王五 | 201804 | 372.22
(8 rows)
样例数据如下:
...
(gdb) p *(RawStmt *)(raw_parsetree_list->head.data->ptr_value)
$7 = {type = T_RawStmt, stmt = 0x1a48c00, stmt_location = 0, stmt_len = 232}
(gdb) p *((RawStmt *)(raw_parsetree_list->head.data->ptr_value))->stmt
$8 = {type = T_SelectStmt}
###### 实际类型SelectStmt
(gdb) p *(SelectStmt *)((RawStmt *)(raw_parsetree_list->head.data->ptr_value))->stmt
$16 = {type = T_SelectStmt, distinctClause = 0x0, intoClause = 0x0, targetList = 0x1a47b18,
fromClause = 0x1a48900, whereClause = 0x1a48b40, groupClause = 0x0, havingClause = 0x0, windowClause = 0x0,
valuesLists = 0x0, sortClause = 0x1afd858, limitOffset = 0x0, limitCount = 0x1afd888, lockingClause = 0x0,
withClause = 0x0, op = SETOP_NONE, all = false, larg = 0x0, rarg = 0x0}
N/A
--结束END--
本文标题: PostgreSQL 源码解读(204)- 查询#117(数据结构SelectStmt&Value)
本文链接: https://lsjlt.com/news/46168.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0