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

Commit8bf66de

Browse files
committed
Fix confusion about havingQual vs hasHavingQual in planner.
Preprocessing of the HAVING clause will reduce havingQual to NILif the clause is constant-TRUE. This is one case where thatconvention is rather unfortunate, because "HAVING TRUE" is not at allthe same as not having any HAVING clause at all. (Per the SQL spec,it still forces the query to be grouped.) The planner deals with thisby having a boolean hasHavingQual that records whether havingQual wasoriginally nonempty; places that just want to check whether HAVINGwas specified are supposed to consult that.I found three places that got that wrong. Fortunately, these couldonly affect cost estimates not correctness. It'd be hard evento demonstrate the errors; for example, the one in allpaths.c wouldonly matter in a query that has HAVING TRUE but no GROUP BY and noaggregates, which would require a completely variable-free SELECTlist, making the case probably of only academic interest. Hence,while these are worth fixing before someone copies the incorrectcoding somewhere more critical, they don't seem worth back-patching.I didn't bother trying to devise regression tests, either.Discussion:https://postgr.es/m/2503888.1666042643@sss.pgh.pa.us
1 parent997cd15 commit8bf66de

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

‎contrib/postgres_fdw/postgres_fdw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,7 +3357,7 @@ estimate_path_cost_size(PlannerInfo *root,
33573357
* Get the retrieved_rows and rows estimates. If there are HAVING
33583358
* quals, account for their selectivity.
33593359
*/
3360-
if (root->parse->havingQual)
3360+
if (root->hasHavingQual)
33613361
{
33623362
/* Factor in the selectivity of the remotely-checked quals */
33633363
retrieved_rows=
@@ -3405,7 +3405,7 @@ estimate_path_cost_size(PlannerInfo *root,
34053405
run_cost+=cpu_tuple_cost*numGroups;
34063406

34073407
/* Account for the eval cost of HAVING quals, if any */
3408-
if (root->parse->havingQual)
3408+
if (root->hasHavingQual)
34093409
{
34103410
QualCostremote_cost;
34113411

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2575,7 +2575,7 @@ set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
25752575
if (parse->hasAggs||
25762576
parse->groupClause||
25772577
parse->groupingSets||
2578-
parse->havingQual||
2578+
root->hasHavingQual||
25792579
parse->distinctClause||
25802580
parse->sortClause||
25812581
has_multiple_baserels(root))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp