aboutsummaryrefslogtreecommitdiff
path: root/contrib/postgres_fdw/postgres_fdw.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-10-04 15:48:17 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-10-04 15:48:17 -0400
commitd73f4c74dd34b19c19839f7ae09fb96442728509 (patch)
treec90ec26d55c24bfca08d92cb6b43873cb64ae848 /contrib/postgres_fdw/postgres_fdw.c
parent9ddef36278a9f676c07d0b4d9f33fa22e48ce3b5 (diff)
downloadpostgresql-d73f4c74dd34b19c19839f7ae09fb96442728509.tar.gz
postgresql-d73f4c74dd34b19c19839f7ae09fb96442728509.zip
In the executor, use an array of pointers to access the rangetable.
Instead of doing a lot of list_nth() accesses to es_range_table, create a flattened pointer array during executor startup and index into that to get at individual RangeTblEntrys. This eliminates one source of O(N^2) behavior with lots of partitions. (I'm not exactly convinced that it's the most important source, but it's an easy one to fix.) Amit Langote and David Rowley Discussion: https://postgr.es/m/468c85d9-540e-66a2-1dde-fec2b741e688@lab.ntt.co.jp
Diffstat (limited to 'contrib/postgres_fdw/postgres_fdw.c')
-rw-r--r--contrib/postgres_fdw/postgres_fdw.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index c02287a55ca..b91b7d27de9 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -1345,7 +1345,7 @@ postgresBeginForeignScan(ForeignScanState *node, int eflags)
rtindex = fsplan->scan.scanrelid;
else
rtindex = bms_next_member(fsplan->fs_relids, -1);
- rte = rt_fetch(rtindex, estate->es_range_table);
+ rte = exec_rt_fetch(rtindex, estate);
userid = rte->checkAsUser ? rte->checkAsUser : GetUserId();
/* Get info about foreign table. */
@@ -1731,8 +1731,8 @@ postgresBeginForeignModify(ModifyTableState *mtstate,
FdwModifyPrivateRetrievedAttrs);
/* Find RTE. */
- rte = rt_fetch(resultRelInfo->ri_RangeTableIndex,
- mtstate->ps.state->es_range_table);
+ rte = exec_rt_fetch(resultRelInfo->ri_RangeTableIndex,
+ mtstate->ps.state);
/* Construct an execution state. */
fmstate = create_foreign_modify(mtstate->ps.state,
@@ -2036,7 +2036,7 @@ postgresBeginForeignInsert(ModifyTableState *mtstate,
* correspond to this partition if it is one of the UPDATE subplan target
* rels; in that case, we can just use the existing RTE as-is.
*/
- rte = list_nth(estate->es_range_table, resultRelation - 1);
+ rte = exec_rt_fetch(resultRelation, estate);
if (rte->relid != RelationGetRelid(rel))
{
rte = copyObject(rte);
@@ -2396,7 +2396,7 @@ postgresBeginDirectModify(ForeignScanState *node, int eflags)
* ExecCheckRTEPerms() does.
*/
rtindex = estate->es_result_relation_info->ri_RangeTableIndex;
- rte = rt_fetch(rtindex, estate->es_range_table);
+ rte = exec_rt_fetch(rtindex, estate);
userid = rte->checkAsUser ? rte->checkAsUser : GetUserId();
/* Get info about foreign table. */
@@ -5752,7 +5752,7 @@ conversion_error_callback(void *arg)
RangeTblEntry *rte;
Var *var = (Var *) tle->expr;
- rte = rt_fetch(var->varno, estate->es_range_table);
+ rte = exec_rt_fetch(var->varno, estate);
if (var->varattno == 0)
is_wholerow = true;