Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3ec3c0

Browse files
committed
Remove arbitrary 64K-or-so limit on rangetable size.
Up to now the size of a query's rangetable has been limited by theconstants INNER_VAR et al, which mustn't be equal to any realrangetable index. 65000 doubtless seemed like enough for anybody,and it still is orders of magnitude larger than the number of joinswe can realistically handle. However, we need a rangetable entryfor each child partition that is (or might be) processed by a query.Queries with a few thousand partitions are getting more realistic,so that the day when that limit becomes a problem is in sight,even if it's not here yet. Hence, let's raise the limit.Rather than just increase the values of INNER_VAR et al, this patchadopts the approach of making them small negative values, so thatrangetables could theoretically become as long as INT_MAX.The bulk of the patch is concerned with changing Var.varno and somerelated variables from "Index" (unsigned int) to plain "int". Thisis basically cosmetic, with little actual effect other than to helpdebuggers print their values nicely. As such, I've only botheredwith changing places that could actually see INNER_VAR et al, whichthe parser and most of the planner don't. We do have to be carefulin places that are performing less/greater comparisons on varnos,but there are very few such places, other than the IS_SPECIAL_VARNOmacro itself.A notable side effect of this patch is that while it used to bepossible to add INNER_VAR et al to a Bitmapset, that will nowdraw an error. I don't see any likelihood that it wouldn't be abug to include these fake varnos in a bitmapset of real varnos,so I think this is all to the good.Although this touches outfuncs/readfuncs, I don't think a catversionbump is required, since stored rules would never contain Varswith these fake varnos.Andrey Lepikhov and Tom Lane, after a suggestion by Peter EisentrautDiscussion:https://postgr.es/m/43c7f2f5-1e27-27aa-8c65-c91859d15190@postgrespro.ru
1 parent6fe0eb9 commite3ec3c0

File tree

15 files changed

+48
-57
lines changed

15 files changed

+48
-57
lines changed

‎src/backend/executor/execScan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ ExecAssignScanProjectionInfo(ScanState *node)
282282
*As above, but caller can specify varno expected in Vars in the tlist.
283283
*/
284284
void
285-
ExecAssignScanProjectionInfoWithVarno(ScanState*node,Indexvarno)
285+
ExecAssignScanProjectionInfoWithVarno(ScanState*node,intvarno)
286286
{
287287
TupleDesctupdesc=node->ss_ScanTupleSlot->tts_tupleDescriptor;
288288

‎src/backend/executor/execUtils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
#include"utils/typcache.h"
6666

6767

68-
staticbooltlist_matches_tupdesc(PlanState*ps,List*tlist,Indexvarno,TupleDesctupdesc);
68+
staticbooltlist_matches_tupdesc(PlanState*ps,List*tlist,intvarno,TupleDesctupdesc);
6969
staticvoidShutdownExprContext(ExprContext*econtext,boolisCommit);
7070

7171

@@ -553,7 +553,7 @@ ExecAssignProjectionInfo(PlanState *planstate,
553553
*/
554554
void
555555
ExecConditionalAssignProjectionInfo(PlanState*planstate,TupleDescinputDesc,
556-
Indexvarno)
556+
intvarno)
557557
{
558558
if (tlist_matches_tupdesc(planstate,
559559
planstate->plan->targetlist,
@@ -579,7 +579,7 @@ ExecConditionalAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc,
579579
}
580580

581581
staticbool
582-
tlist_matches_tupdesc(PlanState*ps,List*tlist,Indexvarno,TupleDesctupdesc)
582+
tlist_matches_tupdesc(PlanState*ps,List*tlist,intvarno,TupleDesctupdesc)
583583
{
584584
intnumattrs=tupdesc->natts;
585585
intattrno;

‎src/backend/executor/nodeCustom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags)
3131
CustomScanState*css;
3232
Relationscan_rel=NULL;
3333
Indexscanrelid=cscan->scan.scanrelid;
34-
Indextlistvarno;
34+
inttlistvarno;
3535

3636
/*
3737
* Allocate the CustomScanState object. We let the custom scan provider

‎src/backend/executor/nodeForeignscan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ ExecInitForeignScan(ForeignScan *node, EState *estate, int eflags)
138138
ForeignScanState*scanstate;
139139
RelationcurrentRelation=NULL;
140140
Indexscanrelid=node->scan.scanrelid;
141-
Indextlistvarno;
141+
inttlistvarno;
142142
FdwRoutine*fdwroutine;
143143

144144
/* check for unsupported flags */

‎src/backend/nodes/makefuncs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ makeSimpleA_Expr(A_Expr_Kind kind, char *name,
6363
* creates a Var node
6464
*/
6565
Var*
66-
makeVar(Indexvarno,
66+
makeVar(intvarno,
6767
AttrNumbervarattno,
6868
Oidvartype,
6969
int32vartypmod,
@@ -85,7 +85,7 @@ makeVar(Index varno,
8585
* them, but just initialize them to the given varno/varattno. This
8686
* reduces code clutter and chance of error for most callers.
8787
*/
88-
var->varnosyn=varno;
88+
var->varnosyn=(Index)varno;
8989
var->varattnosyn=varattno;
9090

9191
/* Likewise, we just set location to "unknown" here */
@@ -100,7 +100,7 @@ makeVar(Index varno,
100100
*TargetEntry
101101
*/
102102
Var*
103-
makeVarFromTargetEntry(Indexvarno,
103+
makeVarFromTargetEntry(intvarno,
104104
TargetEntry*tle)
105105
{
106106
returnmakeVar(varno,
@@ -131,7 +131,7 @@ makeVarFromTargetEntry(Index varno,
131131
*/
132132
Var*
133133
makeWholeRowVar(RangeTblEntry*rte,
134-
Indexvarno,
134+
intvarno,
135135
Indexvarlevelsup,
136136
boolallowScalar)
137137
{

‎src/backend/nodes/outfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ _outVar(StringInfo str, const Var *node)
11231123
{
11241124
WRITE_NODE_TYPE("VAR");
11251125

1126-
WRITE_UINT_FIELD(varno);
1126+
WRITE_INT_FIELD(varno);
11271127
WRITE_INT_FIELD(varattno);
11281128
WRITE_OID_FIELD(vartype);
11291129
WRITE_INT_FIELD(vartypmod);

‎src/backend/nodes/readfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ _readVar(void)
577577
{
578578
READ_LOCALS(Var);
579579

580-
READ_UINT_FIELD(varno);
580+
READ_INT_FIELD(varno);
581581
READ_INT_FIELD(varattno);
582582
READ_OID_FIELD(vartype);
583583
READ_INT_FIELD(vartypmod);

‎src/backend/optimizer/path/costsize.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5961,7 +5961,8 @@ set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
59615961
Assert(var->varlevelsup==0);
59625962

59635963
/* Try to get data from RelOptInfo cache */
5964-
if (var->varno<root->simple_rel_array_size)
5964+
if (!IS_SPECIAL_VARNO(var->varno)&&
5965+
var->varno<root->simple_rel_array_size)
59655966
{
59665967
RelOptInfo*rel=root->simple_rel_array[var->varno];
59675968

‎src/backend/optimizer/plan/createplan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4805,7 +4805,8 @@ replace_nestloop_params_mutator(Node *node, PlannerInfo *root)
48054805
/* Upper-level Vars should be long gone at this point */
48064806
Assert(var->varlevelsup==0);
48074807
/* If not to be replaced, we can just return the Var unmodified */
4808-
if (!bms_is_member(var->varno,root->curOuterRels))
4808+
if (IS_SPECIAL_VARNO(var->varno)||
4809+
!bms_is_member(var->varno,root->curOuterRels))
48094810
returnnode;
48104811
/* Replace the Var with a nestloop Param */
48114812
return (Node*)replace_nestloop_param_var(root,var);

‎src/backend/optimizer/plan/setrefs.c

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
typedefstruct
3333
{
34-
Indexvarno;/* RT index of Var */
34+
intvarno;/* RT index of Var */
3535
AttrNumbervarattno;/* attr number of Var */
3636
AttrNumberresno;/* TLE position of Var */
3737
}tlist_vinfo;
@@ -66,7 +66,7 @@ typedef struct
6666
{
6767
PlannerInfo*root;
6868
indexed_tlist*subplan_itlist;
69-
Indexnewvarno;
69+
intnewvarno;
7070
intrtoffset;
7171
doublenum_exec;
7272
}fix_upper_expr_context;
@@ -143,15 +143,15 @@ static void set_dummy_tlist_references(Plan *plan, int rtoffset);
143143
staticindexed_tlist*build_tlist_index(List*tlist);
144144
staticVar*search_indexed_tlist_for_var(Var*var,
145145
indexed_tlist*itlist,
146-
Indexnewvarno,
146+
intnewvarno,
147147
intrtoffset);
148148
staticVar*search_indexed_tlist_for_non_var(Expr*node,
149149
indexed_tlist*itlist,
150-
Indexnewvarno);
150+
intnewvarno);
151151
staticVar*search_indexed_tlist_for_sortgroupref(Expr*node,
152152
Indexsortgroupref,
153153
indexed_tlist*itlist,
154-
Indexnewvarno);
154+
intnewvarno);
155155
staticList*fix_join_expr(PlannerInfo*root,
156156
List*clauses,
157157
indexed_tlist*outer_itlist,
@@ -163,7 +163,7 @@ static Node *fix_join_expr_mutator(Node *node,
163163
staticNode*fix_upper_expr(PlannerInfo*root,
164164
Node*node,
165165
indexed_tlist*subplan_itlist,
166-
Indexnewvarno,
166+
intnewvarno,
167167
intrtoffset,doublenum_exec);
168168
staticNode*fix_upper_expr_mutator(Node*node,
169169
fix_upper_expr_context*context);
@@ -505,16 +505,6 @@ add_rte_to_flat_rtable(PlannerGlobal *glob, RangeTblEntry *rte)
505505

506506
glob->finalrtable=lappend(glob->finalrtable,newrte);
507507

508-
/*
509-
* Check for RT index overflow; it's very unlikely, but if it did happen,
510-
* the executor would get confused by varnos that match the special varno
511-
* values.
512-
*/
513-
if (IS_SPECIAL_VARNO(list_length(glob->finalrtable)))
514-
ereport(ERROR,
515-
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
516-
errmsg("too many range table entries")));
517-
518508
/*
519509
* If it's a plain relation RTE, add the table to relationOids.
520510
*
@@ -1947,10 +1937,8 @@ fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context)
19471937
{
19481938
CurrentOfExpr*cexpr= (CurrentOfExpr*)copyObject(node);
19491939

1950-
Assert(cexpr->cvarno!=INNER_VAR);
1951-
Assert(cexpr->cvarno!=OUTER_VAR);
1952-
if (!IS_SPECIAL_VARNO(cexpr->cvarno))
1953-
cexpr->cvarno+=context->rtoffset;
1940+
Assert(!IS_SPECIAL_VARNO(cexpr->cvarno));
1941+
cexpr->cvarno+=context->rtoffset;
19541942
return (Node*)cexpr;
19551943
}
19561944
if (IsA(node,PlaceHolderVar))
@@ -2447,7 +2435,7 @@ build_tlist_index(List *tlist)
24472435
* (so nothing other than Vars and PlaceHolderVars can be matched).
24482436
*/
24492437
staticindexed_tlist*
2450-
build_tlist_index_other_vars(List*tlist,Indexignore_rel)
2438+
build_tlist_index_other_vars(List*tlist,intignore_rel)
24512439
{
24522440
indexed_tlist*itlist;
24532441
tlist_vinfo*vinfo;
@@ -2499,9 +2487,9 @@ build_tlist_index_other_vars(List *tlist, Index ignore_rel)
24992487
*/
25002488
staticVar*
25012489
search_indexed_tlist_for_var(Var*var,indexed_tlist*itlist,
2502-
Indexnewvarno,intrtoffset)
2490+
intnewvarno,intrtoffset)
25032491
{
2504-
Indexvarno=var->varno;
2492+
intvarno=var->varno;
25052493
AttrNumbervarattno=var->varattno;
25062494
tlist_vinfo*vinfo;
25072495
inti;
@@ -2539,7 +2527,7 @@ search_indexed_tlist_for_var(Var *var, indexed_tlist *itlist,
25392527
*/
25402528
staticVar*
25412529
search_indexed_tlist_for_non_var(Expr*node,
2542-
indexed_tlist*itlist,Indexnewvarno)
2530+
indexed_tlist*itlist,intnewvarno)
25432531
{
25442532
TargetEntry*tle;
25452533

@@ -2581,7 +2569,7 @@ static Var *
25812569
search_indexed_tlist_for_sortgroupref(Expr*node,
25822570
Indexsortgroupref,
25832571
indexed_tlist*itlist,
2584-
Indexnewvarno)
2572+
intnewvarno)
25852573
{
25862574
ListCell*lc;
25872575

@@ -2799,7 +2787,7 @@ static Node *
27992787
fix_upper_expr(PlannerInfo*root,
28002788
Node*node,
28012789
indexed_tlist*subplan_itlist,
2802-
Indexnewvarno,
2790+
intnewvarno,
28032791
intrtoffset,
28042792
doublenum_exec)
28052793
{

‎src/backend/optimizer/prep/prepjointree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static Node *pull_up_simple_union_all(PlannerInfo *root, Node *jtnode,
8080
staticvoidpull_up_union_leaf_queries(Node*setOp,PlannerInfo*root,
8181
intparentRTindex,Query*setOpQuery,
8282
intchildRToffset);
83-
staticvoidmake_setop_translation_list(Query*query,Indexnewvarno,
83+
staticvoidmake_setop_translation_list(Query*query,intnewvarno,
8484
AppendRelInfo*appinfo);
8585
staticboolis_simple_subquery(PlannerInfo*root,Query*subquery,
8686
RangeTblEntry*rte,
@@ -1372,7 +1372,7 @@ pull_up_union_leaf_queries(Node *setOp, PlannerInfo *root, int parentRTindex,
13721372
* Also create the rather trivial reverse-translation array.
13731373
*/
13741374
staticvoid
1375-
make_setop_translation_list(Query*query,Indexnewvarno,
1375+
make_setop_translation_list(Query*query,intnewvarno,
13761376
AppendRelInfo*appinfo)
13771377
{
13781378
List*vars=NIL;

‎src/backend/utils/adt/ruleutils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6949,7 +6949,7 @@ get_variable(Var *var, int levelsup, bool istoplevel, deparse_context *context)
69496949
AttrNumberattnum;
69506950
intnetlevelsup;
69516951
deparse_namespace*dpns;
6952-
Indexvarno;
6952+
intvarno;
69536953
AttrNumbervarattno;
69546954
deparse_columns*colinfo;
69556955
char*refname;
@@ -6995,7 +6995,7 @@ get_variable(Var *var, int levelsup, bool istoplevel, deparse_context *context)
69956995
*/
69966996
if (context->appendparents&&dpns->appendrels)
69976997
{
6998-
Indexpvarno=varno;
6998+
intpvarno=varno;
69996999
AttrNumberpvarattno=varattno;
70007000
AppendRelInfo*appinfo=dpns->appendrels[pvarno];
70017001
boolfound= false;
@@ -7305,7 +7305,7 @@ get_name_for_var_field(Var *var, int fieldno,
73057305
AttrNumberattnum;
73067306
intnetlevelsup;
73077307
deparse_namespace*dpns;
7308-
Indexvarno;
7308+
intvarno;
73097309
AttrNumbervarattno;
73107310
TupleDesctupleDesc;
73117311
Node*expr;

‎src/include/executor/executor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ typedef bool (*ExecScanRecheckMtd) (ScanState *node, TupleTableSlot *slot);
459459
externTupleTableSlot*ExecScan(ScanState*node,ExecScanAccessMtdaccessMtd,
460460
ExecScanRecheckMtdrecheckMtd);
461461
externvoidExecAssignScanProjectionInfo(ScanState*node);
462-
externvoidExecAssignScanProjectionInfoWithVarno(ScanState*node,Indexvarno);
462+
externvoidExecAssignScanProjectionInfoWithVarno(ScanState*node,intvarno);
463463
externvoidExecScanReScan(ScanState*node);
464464

465465
/*
@@ -552,7 +552,7 @@ extern const TupleTableSlotOps *ExecGetResultSlotOps(PlanState *planstate,
552552
externvoidExecAssignProjectionInfo(PlanState*planstate,
553553
TupleDescinputDesc);
554554
externvoidExecConditionalAssignProjectionInfo(PlanState*planstate,
555-
TupleDescinputDesc,Indexvarno);
555+
TupleDescinputDesc,intvarno);
556556
externvoidExecFreeExprContext(PlanState*planstate);
557557
externvoidExecAssignScanType(ScanState*scanstate,TupleDesctupDesc);
558558
externvoidExecCreateScanSlotFromOuterPlan(EState*estate,

‎src/include/nodes/makefuncs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ extern A_Expr *makeA_Expr(A_Expr_Kind kind, List *name,
2424
externA_Expr*makeSimpleA_Expr(A_Expr_Kindkind,char*name,
2525
Node*lexpr,Node*rexpr,intlocation);
2626

27-
externVar*makeVar(Indexvarno,
27+
externVar*makeVar(intvarno,
2828
AttrNumbervarattno,
2929
Oidvartype,
3030
int32vartypmod,
3131
Oidvarcollid,
3232
Indexvarlevelsup);
3333

34-
externVar*makeVarFromTargetEntry(Indexvarno,
34+
externVar*makeVarFromTargetEntry(intvarno,
3535
TargetEntry*tle);
3636

3737
externVar*makeWholeRowVar(RangeTblEntry*rte,
38-
Indexvarno,
38+
intvarno,
3939
Indexvarlevelsup,
4040
boolallowScalar);
4141

‎src/include/nodes/primnodes.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ typedef struct Expr
172172
* in the planner and doesn't correspond to any simple relation column may
173173
* have varnosyn = varattnosyn = 0.
174174
*/
175-
#defineINNER_VAR65000/* reference to inner subplan */
176-
#defineOUTER_VAR65001/* reference to outer subplan */
177-
#defineINDEX_VAR65002/* reference to index column */
178-
#defineROWID_VAR65003/* row identity column during planning */
175+
#defineINNER_VAR(-1)/* reference to inner subplan */
176+
#defineOUTER_VAR(-2)/* reference to outer subplan */
177+
#defineINDEX_VAR(-3)/* reference to index column */
178+
#defineROWID_VAR(-4)/* row identity column during planning */
179179

180-
#defineIS_SPECIAL_VARNO(varno)((varno)>= INNER_VAR)
180+
#defineIS_SPECIAL_VARNO(varno)((int) (varno)< 0)
181181

182182
/* Symbols for the indexes of the special RTE entries in rules */
183183
#definePRS2_OLD_VARNO1
@@ -186,8 +186,8 @@ typedef struct Expr
186186
typedefstructVar
187187
{
188188
Exprxpr;
189-
Indexvarno;/* index of this var's relation in the range
190-
* table, or INNER_VAR/OUTER_VAR/INDEX_VAR */
189+
intvarno;/* index of this var's relation in the range
190+
* table, or INNER_VAR/OUTER_VAR/etc */
191191
AttrNumbervarattno;/* attribute number of this var, or zero for
192192
* all attrs ("whole-row Var") */
193193
Oidvartype;/* pg_type OID for the type of this var */
@@ -1351,6 +1351,7 @@ typedef struct SetToDefault
13511351
* of the target relation being constrained; this aids placing the expression
13521352
* correctly during planning. We can assume however that its "levelsup" is
13531353
* always zero, due to the syntactic constraints on where it can appear.
1354+
* Also, cvarno will always be a true RT index, never INNER_VAR etc.
13541355
*
13551356
* The referenced cursor can be represented either as a hardwired string
13561357
* or as a reference to a run-time parameter of type REFCURSOR. The latter

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp