文章目录

  • 通过subquery_planner查看rtable是些什么东西
    • select * from test1 , test2 where test1.id2=test2.id2 ;
    • select * from test1 left join test2 on test1.id2=test2.id2 ,test3,test4 where test3.id2=test4.id2 ;
    • 结构体
  • select pg_backend_pid();
  • select * from pg_backend_pid();查看rtable
  • select * from power(1.1,1.2);
  • select * from generate_series(1,20000) as g,floor(random()*100) as gg,floor(random()*100),floor(random()*100) as hh;
  • postgres=# select * from test1,test2 where test1.id1- test1.id3>2*test2.id4;时候的TargetEntry的expr字段是啥?

通过subquery_planner查看rtable是些什么东西

select * from test1 , test2 where test1.id2=test2.id2 ;

  • 就两个范围表
(gdb) print length(parse->rtable)
$26 = 2
(gdb) print *rte
$1 = {type = T_RangeTblEntry, rtekind = RTE_RELATION, relid = 16384, relkind = 114 'r', tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_INNER, joinaliasvars = 0x0, functions = 0x0, funcordinality = false, tablefunc = 0x0, values_lists = 0x0, ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0, enrtuples = 0, alias = 0x0, eref = 0x292f050, lateral = false, inh = true, inFromCl = true, requiredPerms = 2, checkAsUser = 0, selectedCols = 0x29530a8, insertedCols = 0x0, updatedCols = 0x0, securityQuals = 0x0}
(gdb) print *rte
$2 = {type = T_RangeTblEntry, rtekind = RTE_RELATION, relid = 16387, relkind = 114 'r', tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_INNER, joinaliasvars = 0x0, functions = 0x0, funcordinality = false, tablefunc = 0x0, values_lists = 0x0, ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0, enrtuples = 0, alias = 0x0, eref = 0x292f4d0, lateral = false, inh = true, inFromCl = true, requiredPerms = 2, checkAsUser = 0, selectedCols = 0x29533c0, insertedCols = 0x0, updatedCols = 0x0, securityQuals = 0x0}

  • 我顺便要看一下(OpExpr) *(parse->jointree->quals)
(gdb) print (OpExpr) *(parse->jointree->quals)
$18 = {xpr = {type = T_OpExpr}, opno = 96, opfuncid = 65, opresulttype = 16, opretset = false, opcollid = 0, inputcollid = 0, args = 0x2953588, location = 43}
(gdb) 
  • opno=96表示这是个是=
{ oid => '96', oid_symbol => 'Int4EqualOperator', descr => 'equal',oprname => '=', oprcanmerge => 't', oprcanhash => 't', oprleft => 'int4',oprright => 'int4', oprresult => 'bool', oprcom => '=(int4,int4)',oprnegate => '<>(int4,int4)', oprcode => 'int4eq', oprrest => 'eqsel',oprjoin => 'eqjoinsel' },
  • 65表示啥啊不知道呢
{ oid => '65',proname => 'int4eq', proleakproof => 't', prorettype => 'bool',proargtypes => 'int4 int4', prosrc => 'int4eq' },
  • 16
{ oid => '16', descr => 'boolean, \'true\'/\'false\'',typname => 'bool', typlen => '1', typbyval => 't', typcategory => 'B',typispreferred => 't', typarray => '_bool', typinput => 'boolin',typoutput => 'boolout', typreceive => 'boolrecv', typsend => 'boolsend',typalign => 'c' },
  • args里面是两个东西哦

    • 那么这个args里面是啥类型的list呢?
$35 = {xpr = {type = T_Var}, varno = 1, varattno = 2, vartype = 23, vartypmod = -1, varcollid = 0, varlevelsup = 0, varnoold = 1, varoattno = 2, location = 34}
  • 哈哈,原来是Var累心的
typedef struct Var
{Expr       xpr;Index       varno;          /* index of this var's relation in the range* table, or INNER_VAR/OUTER_VAR/INDEX_VAR */AttrNumber varattno;       /* attribute number of this var, or zero for* all attrs ("whole-row Var") */Oid           vartype;        /* pg_type OID for the type of this var */int32     vartypmod;      /* pg_attribute typmod value */Oid          varcollid;      /* OID of collation, or InvalidOid if none */Index      varlevelsup;    /* for subquery variables referencing outer* relations; 0 in a normal var, >0 means N* levels up */Index     varnoold;       /* original value of varno, for debugging */AttrNumber  varoattno;      /* original value of varattno */int         location;       /* token location, or -1 if unknown */
} Var;

/** OpExpr - expression node for an operator invocation** Semantically, this is essentially the same as a function call.** Note that opfuncid is not necessarily filled in immediately on creation* of the node.  The planner makes sure it is valid before passing the node* tree to the executor, but during parsing/planning opfuncid can be 0.*/
typedef struct OpExpr
{Expr       xpr;Oid         opno;           /* PG_OPERATOR OID of the operator */Oid            opfuncid;       /* PG_PROC OID of underlying function */Oid         opresulttype;   /* PG_TYPE OID of result value */bool       opretset;       /* true if operator returns set */Oid           opcollid;       /* OID of collation of result */Oid         inputcollid;    /* OID of collation that operator should use */List    *args;           /* arguments to the operator (1 or 2) */int         location;       /* token location, or -1 if unknown */
} OpExpr;

select * from test1 left join test2 on test1.id2=test2.id2 ,test3,test4 where test3.id2=test4.id2 ;

  • 他一共有五个RangeTblEntry
  • 为什么RTE_RELATION是JOIN_INNER
    • 因为他默认是零,而0就是JOIN_INNER

(gdb) print *rte
$4 = {type = T_RangeTblEntry, rtekind = RTE_RELATION, relid = 16384, relkind = 114 'r', tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_INNER, joinaliasvars = 0x0, functions = 0x0, funcordinality = false, tablefunc = 0x0, values_lists = 0x0, ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0, enrtuples = 0, alias = 0x0, eref = 0x29e2468, lateral = false, inh = true, inFromCl = true, requiredPerms = 2, checkAsUser = 0, selectedCols = 0x29e2590, insertedCols = 0x0, updatedCols = 0x0, securityQuals = 0x0}
(gdb) print *rte
$6 = {type = T_RangeTblEntry, rtekind = RTE_RELATION, relid = 16387, relkind = 114 'r', tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_INNER, joinaliasvars = 0x0, functions = 0x0, funcordinality = false, tablefunc = 0x0, values_lists = 0x0, ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0, enrtuples = 0, alias = 0x0, eref = 0x29e2728, lateral = false, inh = true, inFromCl = true, requiredPerms = 2, checkAsUser = 0, selectedCols = 0x29e2838, insertedCols = 0x0, updatedCols = 0x0, securityQuals = 0x0}
(gdb) 

$7 = {type = T_RangeTblEntry, rtekind = RTE_JOIN, relid = 0, relkind = 0 '\000', tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_LEFT, joinaliasvars = 0x29e2980, functions = 0x0, funcordinality = false, tablefunc = 0x0, values_lists = 0x0, ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0, enrtuples = 0, alias = 0x0, eref = 0x29e2ad0, lateral = false, inh = false, inFromCl = true, requiredPerms = 2, checkAsUser = 0, selectedCols = 0x0, insertedCols = 0x0, updatedCols = 0x0, securityQuals = 0x0}
(gdb) 

$8 = {type = T_RangeTblEntry, rtekind = RTE_RELATION, relid = 24576, relkind = 114 'r', tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_INNER, joinaliasvars = 0x0, functions = 0x0, funcordinality = false, tablefunc = 0x0, values_lists = 0x0, ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0, enrtuples = 0, alias = 0x0, eref = 0x29e2de0, lateral = false, inh = true, inFromCl = true, requiredPerms = 2, checkAsUser = 0, selectedCols = 0x29e2f08, insertedCols = 0x0, updatedCols = 0x0, securityQuals = 0x0}
$9 = {type = T_RangeTblEntry, rtekind = RTE_RELATION, relid = 24579, relkind = 114 'r', tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_INNER, joinaliasvars = 0x0, functions = 0x0, funcordinality = false, tablefunc = 0x0, values_lists = 0x0, ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0, enrtuples = 0, alias = 0x0, eref = 0x29e3050, lateral = false, inh = true, inFromCl = true, requiredPerms = 2, checkAsUser = 0, selectedCols = 0x29e3178, insertedCols = 0x0, updatedCols = 0x0, securityQuals = 0x0}

结构体


typedef struct RangeTblEntry
{NodeTag        type;RTEKind        rtekind;        /* see above *//** XXX the fields applicable to only some rte kinds should be merged into* a union.  I didn't do this yet because the diffs would impact a lot of* code that is being actively worked on.  FIXME someday.*//** Fields valid for a plain relation RTE (else zero):** As a special case, RTE_NAMEDTUPLESTORE can also set relid to indicate* that the tuple format of the tuplestore is the same as the referenced* relation.  This allows plans referencing AFTER trigger transition* tables to be invalidated if the underlying table is altered.*/Oid         relid;          /* OID of the relation */char       relkind;        /* relation kind (see pg_class.relkind) */struct TableSampleClause *tablesample;    /* sampling info, or NULL *//** Fields valid for a subquery RTE (else NULL):*/Query    *subquery;       /* the sub-query */bool     security_barrier;   /* is from security_barrier view? *//** Fields valid for a join RTE (else NULL/zero):** joinaliasvars is a list of (usually) Vars corresponding to the columns* of the join result.  An alias Var referencing column K of the join* result can be replaced by the K'th element of joinaliasvars --- but to* simplify the task of reverse-listing aliases correctly, we do not do* that until planning time.  In detail: an element of joinaliasvars can* be a Var of one of the join's input relations, or such a Var with an* implicit coercion to the join's output column type, or a COALESCE* expression containing the two input column Vars (possibly coerced).* Within a Query loaded from a stored rule, it is also possible for* joinaliasvars items to be null pointers, which are placeholders for* (necessarily unreferenced) columns dropped since the rule was made.* Also, once planning begins, joinaliasvars items can be almost anything,* as a result of subquery-flattening substitutions.*/JoinType jointype;       /* type of join */List     *joinaliasvars;  /* list of alias-var expansions *//** Fields valid for a function RTE (else NIL/zero):** When funcordinality is true, the eref->colnames list includes an alias* for the ordinality column.  The ordinality column is otherwise* implicit, and must be accounted for "by hand" in places such as* expandRTE().*/List      *functions;      /* list of RangeTblFunction nodes */bool        funcordinality; /* is this called WITH ORDINALITY? *//** Fields valid for a TableFunc RTE (else NULL):*/TableFunc  *tablefunc;/** Fields valid for a values RTE (else NIL):*/List      *values_lists;   /* list of expression lists *//** Fields valid for a CTE RTE (else NULL/zero):*/char       *ctename;        /* name of the WITH list item */Index       ctelevelsup;    /* number of query levels up */bool     self_reference; /* is this a recursive self-reference? *//** Fields valid for CTE, VALUES, ENR, and TableFunc RTEs (else NIL):** We need these for CTE RTEs so that the types of self-referential* columns are well-defined.  For VALUES RTEs, storing these explicitly* saves having to re-determine the info by scanning the values_lists. For* ENRs, we store the types explicitly here (we could get the information* from the catalogs if 'relid' was supplied, but we'd still need these* for TupleDesc-based ENRs, so we might as well always store the type* info here).  For TableFuncs, these fields are redundant with data in* the TableFunc node, but keeping them here allows some code sharing with* the other cases.** For ENRs only, we have to consider the possibility of dropped columns.* A dropped column is included in these lists, but it will have zeroes in* all three lists (as well as an empty-string entry in eref).  Testing* for zero coltype is the standard way to detect a dropped column.*/List    *coltypes;       /* OID list of column type OIDs */List     *coltypmods;     /* integer list of column typmods */List       *colcollations;  /* OID list of column collation OIDs *//** Fields valid for ENR RTEs (else NULL/zero):*/char       *enrname;        /* name of ephemeral named relation */double        enrtuples;      /* estimated or actual from caller *//** Fields valid in all RTEs:*/Alias      *alias;          /* user-written alias clause, if any */Alias       *eref;           /* expanded reference names */bool      lateral;        /* subquery, function, or values is LATERAL? */bool     inh;            /* inheritance requested? */bool        inFromCl;       /* present in FROM clause? */AclMode        requiredPerms;  /* bitmask of required access permissions */Oid         checkAsUser;    /* if valid, check access as this role */Bitmapset  *selectedCols;  /* columns needing SELECT permission */Bitmapset  *insertedCols;    /* columns needing INSERT permission */Bitmapset  *updatedCols; /* columns needing UPDATE permission */List    *securityQuals;  /* security barrier quals to apply, if any */
} RangeTblEntry;

select pg_backend_pid();

  • rtable是个空的啊!!

  • 下面这个也是空的!

select generate_series(1,20000) as g,floor(random()*100) as gg,
floor(random()*100),floor(random()*100);

select * from pg_backend_pid();查看rtable

select * from pg_backend_pid();
  • 果然是RTE_FUNCTION啊!
687          if (rte->rtekind == RTE_JOIN)
(gdb) p *rte
$11 = {type = T_RangeTblEntry, rtekind = RTE_FUNCTION, relid = 0, relkind = 0 '\000', tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_INNER, joinaliasvars = 0x0, functions = 0x2712ee8, funcordinality = false, tablefunc = 0x0, values_lists = 0x0, ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0, enrtuples = 0, alias = 0x0, eref = 0x2712d00, lateral = false, inh = false, inFromCl = true, requiredPerms = 2, checkAsUser = 0, selectedCols = 0x0, insertedCols = 0x0, updatedCols = 0x0, securityQuals = 0x0}
(gdb)

select * from power(1.1,1.2);

  • 这也是RTE_FUNCTION了!

select * from generate_series(1,20000) as g,floor(random()*100) as gg,floor(random()*100),floor(random()*100) as hh;

  • 上面的rtable是4个RTE_FUNCTION啊!
postgres=#  select * from generate_series(1,20000) as g,floor(random()*100) as gg,floor(random()*100),floor(random()*100) as hh;g   | gg | floor | hh
-------+----+-------+----1 | 30 |    96 | 962 | 30 |    96 | 963 | 30 |    96 | 964 | 30 |    96 | 965 | 30 |    96 | 966 | 30 |    96 | 967 | 30 |    96 | 968 | 30 |    96 | 969 | 30 |    96 | 9610 | 30 |    96 | 9611 | 30 |    96 | 9612 | 30 |    96 | 96

postgres=# select * from test1,test2 where test1.id1- test1.id3>2*test2.id4;时候的TargetEntry的expr字段是啥?


(gdb) p length(parse->targetList)
$3 = 6
(gdb) print ((Node *)(list_head(parse->targetList)->data.ptr_value))->type
$4 = T_TargetEntry
(gdb) print ((TargetEntry *)(list_head(parse->targetList)->data.ptr_value))
$5 = (TargetEntry *) 0x1a474d0
(gdb) p ($5->expr)
$6 = (Expr *) 0x1a24ff0
(gdb) p ($5->expr)->type
$7 = T_Var
(gdb) p (Var)($5->expr)->type
$8 = {xpr = {type = T_Var}, varno = 1, varattno = 1, vartype = 23, vartypmod = -1, varcollid = 0, varlevelsup = 0, varnoold = 1, varoattno = 1, location = 7}
(gdb) 

通过subquery_planner查看rtable是些什么东西相关推荐

  1. 研究生念了些什么东西?

    在这里不知道是不是自己走错了路,或者是没有认识到这种未知的价值,两年时间过去了,付出了什么, 得到了什么?自己在问自己念研究生能学到什么, 短短的两年时间,上课学不到多少有用的,有些课甚至也没有上,科 ...

  2. G++ 4.4.7 无法编译模板程序,Vs可以,和解?智者尾部留言,本人第一次使用vs pro,通常并且习惯在linux下写些小东西,虽然程序简单;...

    G++ 4.4.7 无法编译模板程序,Vs可以,和解?智者尾部留言,本人第一次使用vs pro,通常并且习惯在linux下写些小东西,虽然程序简单; vs 模板编译运行Ok \ linux g++ 4 ...

  3. MySql中管理百万级要注意些什么东西(转载)

    一.我们可以且应该优化什么? 硬件 操作系统/软件库 SQL服务器(设置和查询) 应 用编程接口(API) 应用程序 二.优化硬件 如果你需要庞大的数据库表 (>2G),你应该考虑使用64位的硬 ...

  4. 树莓派能做什么知乎_大家用树莓派做过什么实用些的东西,能否分享一下 ?...

    1.网站服务器 在树莓派上搭建了一个博客网站,树莓派就放在家里,常年开机,使用内网穿透技术使得任何地方都可以访问我的博客,节省了服务器费用.虽然树莓派的性能比较差,但是当一个基本的服务器也足够了.树莓 ...

  5. 在ddms 里面查看data/data里面的东西 不显示data/data

    今天我要查看data/anr/tarces.txt,没办法,我只有root手机. 可是root之后,我发现还是不能查看或者导出traces.txt. 后来我才知道,root之后,文件夹权限没有变,所以 ...

  6. 机器学习常用性能度量中的Accuracy、Precision、Recall、ROC、F score等都是些什么东西?...

    一篇文章就搞懂啦,这个必须收藏! 我们以图片分类来举例,当然换成文本.语音等也是一样的. Positive 正样本.比如你要识别一组图片是不是猫,那么你预测某张图片是猫,这张图片就被预测成了正样本. ...

  7. 计算机基础知识考什么,我想请问下,计算机初级考试考些什么东西?

    初级考核内容为:计算机基础知识.操作系统.字处理软件的使用(WORD).电子表格的使用(Excel).计算机网络知识共五部分内容 考试内容 (一).计算机系统的基本知识 1.计算机系统的组成,主要部件 ...

  8. 专用播放器到底是些什么东西?

    宅男.上网.上H网,这个都知道,不细说了,下面这位小犀利 哥的杯具故事,就当是个教训吧. 一.必须安装的专用播放器 色既是空,空既是色.宅男自封小犀利,成天无事就找小电影,一路顺着百度的指引来到某站. ...

  9. JVM_Parallel Scavenge 实例证明,说些你不知道的东西,大对象的规则!!策略的验证

    前言 最近几天学了JVM的几种GC还有内存分配,<深入理解JVM>的日志部分是Serial 收集器,由于JAVA8的默认是ParallelGC 所以,自己测试并且阅读ParallelGC的 ...

最新文章

  1. 2022-2028年中国场景金融行业深度调研及投资前景预测报告
  2. 图像二值形态学——腐蚀和膨胀的C语言实现
  3. android加载转圈动画,android 围绕中心旋转动画
  4. stream 过滤俩个字段_Java8 Stream:2万字20个实例,玩转集合的筛选、归约、分组、聚合...
  5. 基于Taro开发小程序笔记--04路由跳转的几种方式
  6. HBase的java操作,最新API。(查询指定行、列、插入数据等)
  7. maven 简单实用教程
  8. MATLAB: 你不知道的12个基础知识
  9. cortana 无法使用_如何使用Cortana创建和编辑列表(并将它们与Wunderlist同步)
  10. linux搭建MinIO集群
  11. Randao 可证公平随机数(VRF)白皮书
  12. 微波雷达感应模块,智能马桶传感方案,智能化生活
  13. 简单粗暴的动态气泡图
  14. 信用卡账单采集解析系统设计
  15. android 延时拍照,手机如何延时拍摄 手机延时拍摄技巧有哪些
  16. securecrt修改服务器密码,securecrt怎么修改密码
  17. 三次握手四次挥手详解
  18. bloomFilter和哈希函数murmur3
  19. 初学编程 第一个小程序Android studio实现计算器功能
  20. 【权限提升】61 Redis Postgresql数据库提权

热门文章

  1. 基于 React hooks + Typescript + Cesium 场景暗角效果
  2. 《HTML5+CSS3网页布局和样式精粹》.(张亚飞).[PDF]ckook
  3. B-Traveling Salesman Problem[CF-Gym-102134][2016-2017 7th BSUIR Open Programming Contest]
  4. java cmd进入目录_cmd进入某个目录
  5. 单向能ping通,反向不通故障解决过程
  6. 全世界好老男人的女人都该去看“边境风云”(剧透慎入)
  7. 完美解决iphone连电脑蓝牙出现bluetooth外围设备无法正确安装
  8. 职场技巧:如何跟老板谈涨工资?
  9. ACM解题的一些技巧和方法
  10. 记录一次产线502错误