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

Commitd6a3aeb

Browse files
committed
Convert planner's AggInfo and AggTransInfo structs to proper Nodes.
This is mostly just to get outfuncs.c support for them, so thatthe agginfos and aggtransinfos lists can be dumped when dumpingthe contents of PlannerInfo.While here, improve some related comments; notably, clean upobsolete comments left over from when preprocess_minmax_aggregateshad to make its own scan of the query tree.Discussion:https://postgr.es/m/742479.1658160504@sss.pgh.pa.us
1 parente2f6c30 commitd6a3aeb

File tree

3 files changed

+45
-33
lines changed

3 files changed

+45
-33
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ preprocess_minmax_aggregates(PlannerInfo *root)
137137
return;
138138

139139
/*
140-
*Scanthetlist andHAVING qual to findalltheaggregates and verify
141-
*all are MIN/MAX aggregates. Stopas soon as we find one that isn't.
140+
*Examine alltheaggregates andverifyallare MIN/MAXaggregates. Stop
141+
* as soon as we find one that isn't.
142142
*/
143143
aggs_list=NIL;
144144
if (!can_minmax_aggs(root,&aggs_list))
@@ -227,24 +227,24 @@ preprocess_minmax_aggregates(PlannerInfo *root)
227227

228228
/*
229229
* can_minmax_aggs
230-
*Walk throughall the aggregates in the query, and check
231-
*if they areall MIN/MAX aggregates. If so, build a list ofthe
232-
*distinct aggregate calls in the tree.
230+
*Examineall the aggregates in the query, and check if they are
231+
*all MIN/MAX aggregates. If so, build a list ofMinMaxAggInfo
232+
*nodes for them.
233233
*
234234
* Returns false if a non-MIN/MAX aggregate is found, true otherwise.
235-
*
236-
* This does not descend into subqueries, and so should be used only after
237-
* reduction of sublinks to subplans. There mustn't be outer-aggregate
238-
* references either.
239235
*/
240236
staticbool
241237
can_minmax_aggs(PlannerInfo*root,List**context)
242238
{
243239
ListCell*lc;
244240

241+
/*
242+
* This function used to have to scan the query for itself, but now we can
243+
* just thumb through the AggInfo list made by preprocess_aggrefs.
244+
*/
245245
foreach(lc,root->agginfos)
246246
{
247-
AggInfo*agginfo= (AggInfo*)lfirst(lc);
247+
AggInfo*agginfo=lfirst_node(AggInfo,lc);
248248
Aggref*aggref=agginfo->representative_aggref;
249249
Oidaggsortop;
250250
TargetEntry*curTarget;

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ preprocess_aggref(Aggref *aggref, PlannerInfo *root)
223223
aggno=find_compatible_agg(root,aggref,&same_input_transnos);
224224
if (aggno!=-1)
225225
{
226-
AggInfo*agginfo=list_nth(root->agginfos,aggno);
226+
AggInfo*agginfo=list_nth_node(AggInfo,root->agginfos,aggno);
227227

228228
transno=agginfo->transno;
229229
}
230230
else
231231
{
232-
AggInfo*agginfo=palloc(sizeof(AggInfo));
232+
AggInfo*agginfo=makeNode(AggInfo);
233233

234234
agginfo->finalfn_oid=aggfinalfn;
235235
agginfo->representative_aggref=aggref;
@@ -266,7 +266,7 @@ preprocess_aggref(Aggref *aggref, PlannerInfo *root)
266266
same_input_transnos);
267267
if (transno==-1)
268268
{
269-
AggTransInfo*transinfo=palloc(sizeof(AggTransInfo));
269+
AggTransInfo*transinfo=makeNode(AggTransInfo);
270270

271271
transinfo->args=aggref->args;
272272
transinfo->aggfilter=aggref->aggfilter;
@@ -381,7 +381,7 @@ find_compatible_agg(PlannerInfo *root, Aggref *newagg,
381381
aggno=-1;
382382
foreach(lc,root->agginfos)
383383
{
384-
AggInfo*agginfo= (AggInfo*)lfirst(lc);
384+
AggInfo*agginfo=lfirst_node(AggInfo,lc);
385385
Aggref*existingRef;
386386

387387
aggno++;
@@ -452,7 +452,9 @@ find_compatible_trans(PlannerInfo *root, Aggref *newagg, bool shareable,
452452
foreach(lc,transnos)
453453
{
454454
inttransno=lfirst_int(lc);
455-
AggTransInfo*pertrans= (AggTransInfo*)list_nth(root->aggtransinfos,transno);
455+
AggTransInfo*pertrans=list_nth_node(AggTransInfo,
456+
root->aggtransinfos,
457+
transno);
456458

457459
/*
458460
* if the transfns or transition state types are not the same then the
@@ -541,7 +543,7 @@ get_agg_clause_costs(PlannerInfo *root, AggSplit aggsplit, AggClauseCosts *costs
541543

542544
foreach(lc,root->aggtransinfos)
543545
{
544-
AggTransInfo*transinfo= (AggTransInfo*)lfirst(lc);
546+
AggTransInfo*transinfo=lfirst_node(AggTransInfo,lc);
545547

546548
/*
547549
* Add the appropriate component function execution costs to
@@ -645,7 +647,7 @@ get_agg_clause_costs(PlannerInfo *root, AggSplit aggsplit, AggClauseCosts *costs
645647

646648
foreach(lc,root->agginfos)
647649
{
648-
AggInfo*agginfo= (AggInfo*)lfirst(lc);
650+
AggInfo*agginfo=lfirst_node(AggInfo,lc);
649651
Aggref*aggref=agginfo->representative_aggref;
650652

651653
/*

‎src/include/nodes/pathnodes.h

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -442,15 +442,15 @@ struct PlannerInfo
442442
* Information about aggregates. Filled by preprocess_aggrefs().
443443
*/
444444
/* AggInfo structs */
445-
List*agginfospg_node_attr(read_write_ignore);
445+
List*agginfos;
446446
/* AggTransInfo structs */
447-
List*aggtransinfospg_node_attr(read_write_ignore);
448-
/* numberw/ DISTINCT/ORDER BY/WITHIN GROUP */
449-
intnumOrderedAggspg_node_attr(read_write_ignore);
447+
List*aggtransinfos;
448+
/* numberof aggs with DISTINCT/ORDER BY/WITHIN GROUP */
449+
intnumOrderedAggs;
450450
/* does any agg not support partial mode? */
451-
boolhasNonPartialAggspg_node_attr(read_write_ignore);
451+
boolhasNonPartialAggs;
452452
/* is any partial agg non-serializable? */
453-
boolhasNonSerialAggspg_node_attr(read_write_ignore);
453+
boolhasNonSerialAggs;
454454

455455
/*
456456
* These fields are used only when hasRecursion is true:
@@ -3121,6 +3121,10 @@ typedef struct JoinCostWorkspace
31213121
*/
31223122
typedefstructAggInfo
31233123
{
3124+
pg_node_attr(no_copy_equal,no_read)
3125+
3126+
NodeTagtype;
3127+
31243128
/*
31253129
* Link to an Aggref expr this state value is for.
31263130
*
@@ -3129,6 +3133,7 @@ typedef struct AggInfo
31293133
*/
31303134
Aggref*representative_aggref;
31313135

3136+
/* Transition state number for this aggregate */
31323137
inttransno;
31333138

31343139
/*
@@ -3137,9 +3142,8 @@ typedef struct AggInfo
31373142
*/
31383143
boolshareable;
31393144

3140-
/* Oid of the final function or InvalidOid */
3145+
/* Oid of the final function, or InvalidOid if none */
31413146
Oidfinalfn_oid;
3142-
31433147
}AggInfo;
31443148

31453149
/*
@@ -3151,34 +3155,40 @@ typedef struct AggInfo
31513155
*/
31523156
typedefstructAggTransInfo
31533157
{
3158+
pg_node_attr(no_copy_equal,no_read)
3159+
3160+
NodeTagtype;
3161+
3162+
/* Inputs for this transition state */
31543163
List*args;
31553164
Expr*aggfilter;
31563165

31573166
/* Oid of the state transition function */
31583167
Oidtransfn_oid;
31593168

3160-
/* Oid of the serialization function or InvalidOid */
3169+
/* Oid of the serialization function, or InvalidOid if none */
31613170
Oidserialfn_oid;
31623171

3163-
/* Oid of the deserialization function or InvalidOid */
3172+
/* Oid of the deserialization function, or InvalidOid if none */
31643173
Oiddeserialfn_oid;
31653174

3166-
/* Oid of the combine function or InvalidOid */
3175+
/* Oid of the combine function, or InvalidOid if none */
31673176
Oidcombinefn_oid;
31683177

31693178
/* Oid of state value's datatype */
31703179
Oidaggtranstype;
3180+
3181+
/* Additional data about transtype */
31713182
int32aggtranstypmod;
31723183
inttranstypeLen;
31733184
booltranstypeByVal;
3185+
3186+
/* Space-consumption estimate */
31743187
int32aggtransspace;
31753188

3176-
/*
3177-
* initial value from pg_aggregate entry
3178-
*/
3179-
DatuminitValue;
3189+
/* Initial value from pg_aggregate entry */
3190+
DatuminitValuepg_node_attr(read_write_ignore);
31803191
boolinitValueIsNull;
3181-
31823192
}AggTransInfo;
31833193

31843194
#endif/* PATHNODES_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp