@@ -4850,11 +4850,10 @@ create_distinct_paths(PlannerInfo *root,
4850
4850
* Consider hash-based implementations of DISTINCT, if possible.
4851
4851
*
4852
4852
* If we were not able to make any other types of path, we *must* hash or
4853
- * die trying. If we do have other choices, there are several things that
4853
+ * die trying. If we do have other choices, there are two things that
4854
4854
* should prevent selection of hashing: if the query uses DISTINCT ON
4855
4855
* (because it won't really have the expected behavior if we hash), or if
4856
- * enable_hashagg is off, or if it looks like the hashtable will exceed
4857
- * work_mem.
4856
+ * enable_hashagg is off.
4858
4857
*
4859
4858
* Note: grouping_is_hashable() is much more expensive to check than the
4860
4859
* other gating conditions, so we want to do it last.
@@ -4864,12 +4863,7 @@ create_distinct_paths(PlannerInfo *root,
4864
4863
else if (parse -> hasDistinctOn || !enable_hashagg )
4865
4864
allow_hash = false; /* policy-based decision not to hash */
4866
4865
else
4867
- {
4868
- Size hashentrysize = hash_agg_entry_size (0 , cheapest_input_path -> pathtarget -> width , 0 );
4869
-
4870
- allow_hash = !hashagg_avoid_disk_plan ||
4871
- (hashentrysize * numDistinctRows <= work_mem * 1024L );
4872
- }
4866
+ allow_hash = true; /* default */
4873
4867
4874
4868
if (allow_hash && grouping_is_hashable (parse -> distinctClause ))
4875
4869
{
@@ -6749,8 +6743,6 @@ add_paths_to_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel,
6749
6743
6750
6744
if (can_hash )
6751
6745
{
6752
- double hashaggtablesize ;
6753
-
6754
6746
if (parse -> groupingSets )
6755
6747
{
6756
6748
/*
@@ -6762,63 +6754,41 @@ add_paths_to_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel,
6762
6754
}
6763
6755
else
6764
6756
{
6765
- hashaggtablesize = estimate_hashagg_tablesize (cheapest_path ,
6766
- agg_costs ,
6767
- dNumGroups );
6768
-
6769
6757
/*
6770
- * Provided that the estimated size of the hashtable does not
6771
- * exceed work_mem, we'll generate a HashAgg Path, although if we
6772
- * were unable to sort above, then we'd better generate a Path, so
6773
- * that we at least have one.
6758
+ * Generate a HashAgg Path. We just need an Agg over the
6759
+ * cheapest-total input path, since input order won't matter.
6774
6760
*/
6775
- if (!hashagg_avoid_disk_plan ||
6776
- hashaggtablesize < work_mem * 1024L ||
6777
- grouped_rel -> pathlist == NIL )
6778
- {
6779
- /*
6780
- * We just need an Agg over the cheapest-total input path,
6781
- * since input order won't matter.
6782
- */
6783
- add_path (grouped_rel , (Path * )
6784
- create_agg_path (root , grouped_rel ,
6785
- cheapest_path ,
6786
- grouped_rel -> reltarget ,
6787
- AGG_HASHED ,
6788
- AGGSPLIT_SIMPLE ,
6789
- parse -> groupClause ,
6790
- havingQual ,
6791
- agg_costs ,
6792
- dNumGroups ));
6793
- }
6761
+ add_path (grouped_rel , (Path * )
6762
+ create_agg_path (root , grouped_rel ,
6763
+ cheapest_path ,
6764
+ grouped_rel -> reltarget ,
6765
+ AGG_HASHED ,
6766
+ AGGSPLIT_SIMPLE ,
6767
+ parse -> groupClause ,
6768
+ havingQual ,
6769
+ agg_costs ,
6770
+ dNumGroups ));
6794
6771
}
6795
6772
6796
6773
/*
6797
6774
* Generate a Finalize HashAgg Path atop of the cheapest partially
6798
- * grouped path, assuming there is one. Once again, we'll only do this
6799
- * if it looks as though the hash table won't exceed work_mem.
6775
+ * grouped path, assuming there is one
6800
6776
*/
6801
6777
if (partially_grouped_rel && partially_grouped_rel -> pathlist )
6802
6778
{
6803
6779
Path * path = partially_grouped_rel -> cheapest_total_path ;
6804
6780
6805
- hashaggtablesize = estimate_hashagg_tablesize (path ,
6806
- agg_final_costs ,
6807
- dNumGroups );
6808
-
6809
- if (!hashagg_avoid_disk_plan ||
6810
- hashaggtablesize < work_mem * 1024L )
6811
- add_path (grouped_rel , (Path * )
6812
- create_agg_path (root ,
6813
- grouped_rel ,
6814
- path ,
6815
- grouped_rel -> reltarget ,
6816
- AGG_HASHED ,
6817
- AGGSPLIT_FINAL_DESERIAL ,
6818
- parse -> groupClause ,
6819
- havingQual ,
6820
- agg_final_costs ,
6821
- dNumGroups ));
6781
+ add_path (grouped_rel , (Path * )
6782
+ create_agg_path (root ,
6783
+ grouped_rel ,
6784
+ path ,
6785
+ grouped_rel -> reltarget ,
6786
+ AGG_HASHED ,
6787
+ AGGSPLIT_FINAL_DESERIAL ,
6788
+ parse -> groupClause ,
6789
+ havingQual ,
6790
+ agg_final_costs ,
6791
+ dNumGroups ));
6822
6792
}
6823
6793
}
6824
6794
@@ -7171,65 +7141,43 @@ create_partial_grouping_paths(PlannerInfo *root,
7171
7141
}
7172
7142
}
7173
7143
7144
+ /*
7145
+ * Add a partially-grouped HashAgg Path where possible
7146
+ */
7174
7147
if (can_hash && cheapest_total_path != NULL )
7175
7148
{
7176
- double hashaggtablesize ;
7177
-
7178
7149
/* Checked above */
7179
7150
Assert (parse -> hasAggs || parse -> groupClause );
7180
7151
7181
- hashaggtablesize =
7182
- estimate_hashagg_tablesize (cheapest_total_path ,
7183
- agg_partial_costs ,
7184
- dNumPartialGroups );
7185
-
7186
- /*
7187
- * Tentatively produce a partial HashAgg Path, depending on if it
7188
- * looks as if the hash table will fit in work_mem.
7189
- */
7190
- if ((!hashagg_avoid_disk_plan || hashaggtablesize < work_mem * 1024L ) &&
7191
- cheapest_total_path != NULL )
7192
- {
7193
- add_path (partially_grouped_rel , (Path * )
7194
- create_agg_path (root ,
7195
- partially_grouped_rel ,
7196
- cheapest_total_path ,
7197
- partially_grouped_rel -> reltarget ,
7198
- AGG_HASHED ,
7199
- AGGSPLIT_INITIAL_SERIAL ,
7200
- parse -> groupClause ,
7201
- NIL ,
7202
- agg_partial_costs ,
7203
- dNumPartialGroups ));
7204
- }
7152
+ add_path (partially_grouped_rel , (Path * )
7153
+ create_agg_path (root ,
7154
+ partially_grouped_rel ,
7155
+ cheapest_total_path ,
7156
+ partially_grouped_rel -> reltarget ,
7157
+ AGG_HASHED ,
7158
+ AGGSPLIT_INITIAL_SERIAL ,
7159
+ parse -> groupClause ,
7160
+ NIL ,
7161
+ agg_partial_costs ,
7162
+ dNumPartialGroups ));
7205
7163
}
7206
7164
7165
+ /*
7166
+ * Now add a partially-grouped HashAgg partial Path where possible
7167
+ */
7207
7168
if (can_hash && cheapest_partial_path != NULL )
7208
7169
{
7209
- double hashaggtablesize ;
7210
-
7211
- hashaggtablesize =
7212
- estimate_hashagg_tablesize (cheapest_partial_path ,
7213
- agg_partial_costs ,
7214
- dNumPartialPartialGroups );
7215
-
7216
- /* Do the same for partial paths. */
7217
- if ((!hashagg_avoid_disk_plan ||
7218
- hashaggtablesize < work_mem * 1024L ) &&
7219
- cheapest_partial_path != NULL )
7220
- {
7221
- add_partial_path (partially_grouped_rel , (Path * )
7222
- create_agg_path (root ,
7223
- partially_grouped_rel ,
7224
- cheapest_partial_path ,
7225
- partially_grouped_rel -> reltarget ,
7226
- AGG_HASHED ,
7227
- AGGSPLIT_INITIAL_SERIAL ,
7228
- parse -> groupClause ,
7229
- NIL ,
7230
- agg_partial_costs ,
7231
- dNumPartialPartialGroups ));
7232
- }
7170
+ add_partial_path (partially_grouped_rel , (Path * )
7171
+ create_agg_path (root ,
7172
+ partially_grouped_rel ,
7173
+ cheapest_partial_path ,
7174
+ partially_grouped_rel -> reltarget ,
7175
+ AGG_HASHED ,
7176
+ AGGSPLIT_INITIAL_SERIAL ,
7177
+ parse -> groupClause ,
7178
+ NIL ,
7179
+ agg_partial_costs ,
7180
+ dNumPartialPartialGroups ));
7233
7181
}
7234
7182
7235
7183
/*
0 commit comments