51
51
52
52
/*
53
53
* Given the graph name and the label name, create a ResultRelInfo for the table
54
- * those to variables represent. Open the Indices too.
54
+ * those two variables represent. Open the Indices too.
55
55
*/
56
56
ResultRelInfo * create_entity_result_rel_info (EState * estate , char * graph_name ,
57
57
char * label_name )
58
58
{
59
- RangeVar * rv ;
60
- Relation label_relation ;
61
- ResultRelInfo * resultRelInfo ;
59
+ RangeVar * rv = NULL ;
60
+ Relation label_relation = NULL ;
61
+ ResultRelInfo * resultRelInfo = NULL ;
62
+ ParseState * pstate = NULL ;
63
+ RangeTblEntry * rte = NULL ;
64
+ int pii = 0 ;
62
65
63
- ParseState * pstate = make_parsestate (NULL );
66
+ /* create a new parse state for this operation */
67
+ pstate = make_parsestate (NULL );
64
68
65
69
resultRelInfo = palloc (sizeof (ResultRelInfo ));
66
70
@@ -75,12 +79,33 @@ ResultRelInfo *create_entity_result_rel_info(EState *estate, char *graph_name,
75
79
76
80
label_relation = parserOpenTable (pstate , rv , RowExclusiveLock );
77
81
78
- // initialize the resultRelInfo
79
- InitResultRelInfo (resultRelInfo , label_relation ,
80
- 0 , NULL ,
82
+ /*
83
+ * Get the rte to determine the correct perminfoindex value. Some rtes
84
+ * may have it set up, some created here (executor) may not.
85
+ *
86
+ * Note: The RTEPermissionInfo structure was added in PostgreSQL version 16.
87
+ *
88
+ * Note: We use the list_length because exec_rt_fetch starts at 1, not 0.
89
+ * Doing this gives us the last rte in the es_range_table list, which
90
+ * is the rte in question.
91
+ *
92
+ * If the rte is created here and doesn't have a perminfoindex, we
93
+ * need to pass on a 0. Otherwise, later on GetResultRTEPermissionInfo
94
+ * will attempt to get the rte's RTEPermissionInfo data, which doesn't
95
+ * exist.
96
+ *
97
+ * TODO: Ideally, we should consider creating the RTEPermissionInfo data,
98
+ * but as this is just a read of the label relation, it is likely
99
+ * unnecessary.
100
+ */
101
+ rte = exec_rt_fetch (list_length (estate -> es_range_table ), estate );
102
+ pii = (rte -> perminfoindex == 0 ) ? 0 : list_length (estate -> es_range_table );
103
+
104
+ /* initialize the resultRelInfo */
105
+ InitResultRelInfo (resultRelInfo , label_relation , pii , NULL ,
81
106
estate -> es_instrument );
82
107
83
- // open the parse state
108
+ /* open the indices */
84
109
ExecOpenIndices (resultRelInfo , false);
85
110
86
111
free_parsestate (pstate );
0 commit comments