Skip to content

Commit 3c92658

Browse files
committed
Remove EState.es_range_table_array.
Now that list_nth is O(1), there's no good reason to maintain a separate array of RTE pointers rather than indexing into estate->es_range_table. Deleting the array doesn't save all that much either; but just on cleanliness grounds, it's better not to have duplicate representations of the identical information. Discussion: https://postgr.es/m/[email protected]
1 parent 5ee190f commit 3c92658

File tree

4 files changed

+6
-22
lines changed

4 files changed

+6
-22
lines changed

src/backend/executor/execMain.c

-1
Original file line numberDiff line numberDiff line change
@@ -2790,7 +2790,6 @@ EvalPlanQualStart(EPQState *epqstate, EState *parentestate, Plan *planTree)
27902790
estate->es_snapshot = parentestate->es_snapshot;
27912791
estate->es_crosscheck_snapshot = parentestate->es_crosscheck_snapshot;
27922792
estate->es_range_table = parentestate->es_range_table;
2793-
estate->es_range_table_array = parentestate->es_range_table_array;
27942793
estate->es_range_table_size = parentestate->es_range_table_size;
27952794
estate->es_relations = parentestate->es_relations;
27962795
estate->es_queryEnv = parentestate->es_queryEnv;

src/backend/executor/execUtils.c

+5-18
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ CreateExecutorState(void)
113113
estate->es_snapshot = InvalidSnapshot; /* caller must initialize this */
114114
estate->es_crosscheck_snapshot = InvalidSnapshot; /* no crosscheck */
115115
estate->es_range_table = NIL;
116-
estate->es_range_table_array = NULL;
117116
estate->es_range_table_size = 0;
118117
estate->es_relations = NULL;
119118
estate->es_rowmarks = NULL;
@@ -720,29 +719,17 @@ ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
720719
* ExecInitRangeTable
721720
* Set up executor's range-table-related data
722721
*
723-
* We build an array from the range table list to allow faster lookup by RTI.
724-
* (The es_range_table field is now somewhat redundant, but we keep it to
725-
* avoid breaking external code unnecessarily.)
726-
* This is also a convenient place to set up the parallel es_relations array.
722+
* In addition to the range table proper, initialize arrays that are
723+
* indexed by rangetable index.
727724
*/
728725
void
729726
ExecInitRangeTable(EState *estate, List *rangeTable)
730727
{
731-
Index rti;
732-
ListCell *lc;
733-
734728
/* Remember the range table List as-is */
735729
estate->es_range_table = rangeTable;
736730

737-
/* Set up the equivalent array representation */
731+
/* Set size of associated arrays */
738732
estate->es_range_table_size = list_length(rangeTable);
739-
estate->es_range_table_array = (RangeTblEntry **)
740-
palloc(estate->es_range_table_size * sizeof(RangeTblEntry *));
741-
rti = 0;
742-
foreach(lc, rangeTable)
743-
{
744-
estate->es_range_table_array[rti++] = lfirst_node(RangeTblEntry, lc);
745-
}
746733

747734
/*
748735
* Allocate an array to store an open Relation corresponding to each
@@ -753,8 +740,8 @@ ExecInitRangeTable(EState *estate, List *rangeTable)
753740
palloc0(estate->es_range_table_size * sizeof(Relation));
754741

755742
/*
756-
* es_rowmarks is also parallel to the es_range_table_array, but it's
757-
* allocated only if needed.
743+
* es_rowmarks is also parallel to the es_range_table, but it's allocated
744+
* only if needed.
758745
*/
759746
estate->es_rowmarks = NULL;
760747
}

src/include/executor/executor.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,7 @@ extern void ExecInitRangeTable(EState *estate, List *rangeTable);
535535
static inline RangeTblEntry *
536536
exec_rt_fetch(Index rti, EState *estate)
537537
{
538-
Assert(rti > 0 && rti <= estate->es_range_table_size);
539-
return estate->es_range_table_array[rti - 1];
538+
return (RangeTblEntry *) list_nth(estate->es_range_table, rti - 1);
540539
}
541540

542541
extern Relation ExecGetRangeTableRelation(EState *estate, Index rti);

src/include/nodes/execnodes.h

-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,6 @@ typedef struct EState
502502
Snapshot es_snapshot; /* time qual to use */
503503
Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */
504504
List *es_range_table; /* List of RangeTblEntry */
505-
struct RangeTblEntry **es_range_table_array; /* equivalent array */
506505
Index es_range_table_size; /* size of the range table arrays */
507506
Relation *es_relations; /* Array of per-range-table-entry Relation
508507
* pointers, or NULL if not yet opened */

0 commit comments

Comments
 (0)