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

Commit356687b

Browse files
committed
Reset, not recreate, execGrouping.c style hashtables.
This uses the facility added in the preceding commit to fixperformance issues caused by rebuilding the hashtable (with itscomparator expression being the most expensive bit), after everyreset. That's especially important when the comparator is JITcompiled.Bug: #15592 #15486Reported-By: Jakub Janeček, Dmitry MarakasovAuthor: Andres FreundDiscussion:https://postgr.es/m/15486-05850f065da42931@postgresql.orghttps://postgr.es/m/20190114180423.ywhdg2iagzvh43we@alap3.anarazel.deBackpatch: 11, where I broke this inbf6c614
1 parent317ffdf commit356687b

File tree

4 files changed

+79
-64
lines changed

4 files changed

+79
-64
lines changed

‎src/backend/executor/nodeAgg.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ find_unaggregated_cols_walker(Node *node, Bitmapset **colnos)
12461246
}
12471247

12481248
/*
1249-
*Initialize the hash table(s) to empty.
1249+
*(Re-)initialize the hash table(s) to empty.
12501250
*
12511251
* To implement hashed aggregation, we need a hashtable that stores a
12521252
* representative tuple and an array of AggStatePerGroup structs for each
@@ -1257,9 +1257,9 @@ find_unaggregated_cols_walker(Node *node, Bitmapset **colnos)
12571257
* We have a separate hashtable and associated perhash data structure for each
12581258
* grouping set for which we're doing hashing.
12591259
*
1260-
* The hash tables always live in the hashcontext's per-tuple memory context
1261-
* (there is only one of these for all tables together, since they are all
1262-
* reset at the same time).
1260+
* Thecontents of thehash tables always live in the hashcontext's per-tuple
1261+
*memory context(there is only one of these for all tables together, since
1262+
*they are allreset at the same time).
12631263
*/
12641264
staticvoid
12651265
build_hash_table(AggState*aggstate)
@@ -1278,17 +1278,21 @@ build_hash_table(AggState *aggstate)
12781278

12791279
Assert(perhash->aggnode->numGroups>0);
12801280

1281-
perhash->hashtable=BuildTupleHashTable(&aggstate->ss.ps,
1282-
perhash->hashslot->tts_tupleDescriptor,
1283-
perhash->numCols,
1284-
perhash->hashGrpColIdxHash,
1285-
perhash->eqfuncoids,
1286-
perhash->hashfunctions,
1287-
perhash->aggnode->numGroups,
1288-
additionalsize,
1289-
aggstate->hashcontext->ecxt_per_tuple_memory,
1290-
tmpmem,
1291-
DO_AGGSPLIT_SKIPFINAL(aggstate->aggsplit));
1281+
if (perhash->hashtable)
1282+
ResetTupleHashTable(perhash->hashtable);
1283+
else
1284+
perhash->hashtable=BuildTupleHashTableExt(&aggstate->ss.ps,
1285+
perhash->hashslot->tts_tupleDescriptor,
1286+
perhash->numCols,
1287+
perhash->hashGrpColIdxHash,
1288+
perhash->eqfuncoids,
1289+
perhash->hashfunctions,
1290+
perhash->aggnode->numGroups,
1291+
additionalsize,
1292+
aggstate->ss.ps.state->es_query_cxt,
1293+
aggstate->hashcontext->ecxt_per_tuple_memory,
1294+
tmpmem,
1295+
DO_AGGSPLIT_SKIPFINAL(aggstate->aggsplit));
12921296
}
12931297
}
12941298

‎src/backend/executor/nodeRecursiveunion.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,18 @@ build_hash_table(RecursiveUnionState *rustate)
3737
Assert(node->numCols>0);
3838
Assert(node->numGroups>0);
3939

40-
rustate->hashtable=BuildTupleHashTable(&rustate->ps,
41-
desc,
42-
node->numCols,
43-
node->dupColIdx,
44-
rustate->eqfuncoids,
45-
rustate->hashfunctions,
46-
node->numGroups,
47-
0,
48-
rustate->tableContext,
49-
rustate->tempContext,
50-
false);
40+
rustate->hashtable=BuildTupleHashTableExt(&rustate->ps,
41+
desc,
42+
node->numCols,
43+
node->dupColIdx,
44+
rustate->eqfuncoids,
45+
rustate->hashfunctions,
46+
node->numGroups,
47+
0,
48+
rustate->ps.state->es_query_cxt,
49+
rustate->tableContext,
50+
rustate->tempContext,
51+
false);
5152
}
5253

5354

@@ -317,9 +318,9 @@ ExecReScanRecursiveUnion(RecursiveUnionState *node)
317318
if (node->tableContext)
318319
MemoryContextResetAndDeleteChildren(node->tableContext);
319320

320-
/*And rebuild empty hashtable if needed */
321+
/*Empty hashtable if needed */
321322
if (plan->numCols>0)
322-
build_hash_table(node);
323+
ResetTupleHashTable(node->hashtable);
323324

324325
/* reset processing state */
325326
node->recursing= false;

‎src/backend/executor/nodeSetOp.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,18 @@ build_hash_table(SetOpState *setopstate)
126126
Assert(node->strategy==SETOP_HASHED);
127127
Assert(node->numGroups>0);
128128

129-
setopstate->hashtable=BuildTupleHashTable(&setopstate->ps,
130-
desc,
131-
node->numCols,
132-
node->dupColIdx,
133-
setopstate->eqfuncoids,
134-
setopstate->hashfunctions,
135-
node->numGroups,
136-
0,
137-
setopstate->tableContext,
138-
econtext->ecxt_per_tuple_memory,
139-
false);
129+
setopstate->hashtable=BuildTupleHashTableExt(&setopstate->ps,
130+
desc,
131+
node->numCols,
132+
node->dupColIdx,
133+
setopstate->eqfuncoids,
134+
setopstate->hashfunctions,
135+
node->numGroups,
136+
0,
137+
setopstate->ps.state->es_query_cxt,
138+
setopstate->tableContext,
139+
econtext->ecxt_per_tuple_memory,
140+
false);
140141
}
141142

142143
/*
@@ -635,7 +636,7 @@ ExecReScanSetOp(SetOpState *node)
635636
/* And rebuild empty hashtable if needed */
636637
if (((SetOp*)node->ps.plan)->strategy==SETOP_HASHED)
637638
{
638-
build_hash_table(node);
639+
ResetTupleHashTable(node->hashtable);
639640
node->table_filled= false;
640641
}
641642

‎src/backend/executor/nodeSubplan.c

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ buildSubPlanHash(SubPlanState *node, ExprContext *econtext)
481481
Assert(subplan->subLinkType==ANY_SUBLINK);
482482

483483
/*
484-
* If we already had any hash tables,destroy 'em;then create empty hash
485-
* table(s).
484+
* If we already had any hash tables,reset 'em;otherwise create empty
485+
*hashtable(s).
486486
*
487487
* If we need to distinguish accurately between FALSE and UNKNOWN (i.e.,
488488
* NULL) results of the IN operation, then we have to store subplan output
@@ -505,17 +505,21 @@ buildSubPlanHash(SubPlanState *node, ExprContext *econtext)
505505
if (nbuckets<1)
506506
nbuckets=1;
507507

508-
node->hashtable=BuildTupleHashTable(node->parent,
509-
node->descRight,
510-
ncols,
511-
node->keyColIdx,
512-
node->tab_eq_funcoids,
513-
node->tab_hash_funcs,
514-
nbuckets,
515-
0,
516-
node->hashtablecxt,
517-
node->hashtempcxt,
518-
false);
508+
if (node->hashtable)
509+
ResetTupleHashTable(node->hashtable);
510+
else
511+
node->hashtable=BuildTupleHashTableExt(node->parent,
512+
node->descRight,
513+
ncols,
514+
node->keyColIdx,
515+
node->tab_eq_funcoids,
516+
node->tab_hash_funcs,
517+
nbuckets,
518+
0,
519+
node->planstate->state->es_query_cxt,
520+
node->hashtablecxt,
521+
node->hashtempcxt,
522+
false);
519523

520524
if (!subplan->unknownEqFalse)
521525
{
@@ -527,17 +531,22 @@ buildSubPlanHash(SubPlanState *node, ExprContext *econtext)
527531
if (nbuckets<1)
528532
nbuckets=1;
529533
}
530-
node->hashnulls=BuildTupleHashTable(node->parent,
531-
node->descRight,
532-
ncols,
533-
node->keyColIdx,
534-
node->tab_eq_funcoids,
535-
node->tab_hash_funcs,
536-
nbuckets,
537-
0,
538-
node->hashtablecxt,
539-
node->hashtempcxt,
540-
false);
534+
535+
if (node->hashnulls)
536+
ResetTupleHashTable(node->hashtable);
537+
else
538+
node->hashnulls=BuildTupleHashTableExt(node->parent,
539+
node->descRight,
540+
ncols,
541+
node->keyColIdx,
542+
node->tab_eq_funcoids,
543+
node->tab_hash_funcs,
544+
nbuckets,
545+
0,
546+
node->planstate->state->es_query_cxt,
547+
node->hashtablecxt,
548+
node->hashtempcxt,
549+
false);
541550
}
542551

543552
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp