Access root->simple_rte_array instead of Query->rtable for 2 more cases.

Started by Andy Fanover 4 years ago2 messages
#1Andy Fan
zhihui.fan1213@gmail.com
1 attachment(s)

When I am understanding the relationship between Query->rtable and
root->simple_rte_array, I'd like to assume that Query->rtable should be
never used
when root->simple_rte_array is ready. I mainly checked two places,
make_one_rel and
create_plan with the below hacks.

{
List *l = root->parse->rtable;
root->parse->rtable = NIL;
make_one_rel.. or create_plan_recurse..
root->parse->rtable = l;
}

Then I found adjust_appendrel_attrs_mutator and infer_arbiter_indexes still
use it. The attached patch fixed it by replacing the rt_fetch with
planner_rt_fetch,
all the tests passed.

--
Best Regards
Andy Fan (https://www.aliyun.com/)

Attachments:

v1-0001-Use-planner_rt_fetch-instead-of-rt_fetch-when-roo.patchapplication/octet-stream; name=v1-0001-Use-planner_rt_fetch-instead-of-rt_fetch-when-roo.patchDownload
From c18539d49a5f863e30a1379a5cc6a6b03504f5cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=80=E6=8C=83?= <yizhi.fzh@alibaba-inc.com>
Date: Wed, 26 May 2021 01:47:29 +0800
Subject: [PATCH v1] Use planner_rt_fetch instead of rt_fetch when
 root->simple_rte_array

is there.
---
 src/backend/optimizer/util/appendinfo.c | 4 ++--
 src/backend/optimizer/util/plancat.c    | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/backend/optimizer/util/appendinfo.c b/src/backend/optimizer/util/appendinfo.c
index af46f581ac..552a516e87 100644
--- a/src/backend/optimizer/util/appendinfo.c
+++ b/src/backend/optimizer/util/appendinfo.c
@@ -298,8 +298,8 @@ adjust_appendrel_attrs_mutator(Node *node,
 					List	   *fields;
 					RangeTblEntry *rte;
 
-					rte = rt_fetch(appinfo->parent_relid,
-								   context->root->parse->rtable);
+					rte = planner_rt_fetch(appinfo->parent_relid,
+										   context->root);
 					fields = copyObject(appinfo->translated_vars);
 					rowexpr = makeNode(RowExpr);
 					rowexpr->args = fields;
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index c5194fdbbf..efae0fb82d 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -641,7 +641,7 @@ infer_arbiter_indexes(PlannerInfo *root)
 	 * the rewriter or when expand_inherited_rtentry() added it to the query's
 	 * rangetable.
 	 */
-	rte = rt_fetch(root->parse->resultRelation, root->parse->rtable);
+	rte = planner_rt_fetch(root->parse->resultRelation, root);
 
 	relation = table_open(rte->relid, NoLock);
 
-- 
2.21.0

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andy Fan (#1)
Re: Access root->simple_rte_array instead of Query->rtable for 2 more cases.

Andy Fan <zhihui.fan1213@gmail.com> writes:

When I am understanding the relationship between Query->rtable and
root->simple_rte_array, I'd like to assume that Query->rtable should be
never used
when root->simple_rte_array is ready.

TBH, now that Lists are really arrays, there's basically no performance
advantage to be gained by fooling with this. I've considered ripping
out simple_rte_array, but haven't felt that the code churn would be
worth it.

regards, tom lane