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

Appearance settings

Commit 00fecc2

Browse filesBrowse files
committed
Relax some asserts in merge join costing code
In the planner, it was possible, given an extreme enough case containing a large number of joins for the number of estimated rows to become infinite. This could cause problems in initial_cost_mergejoin() where we perform some calculations based on those row estimates. A problem case, presented by Onder Kalaci showed an Assert failure from an Assert checking outerstartsel <= outerendsel. In his test case this was effectively NaN <= Inf, which is false. The NaN outerstartsel came from multiplying the infinite outer_path_rows by 0.0. In master, this problem was fixed by a90c950, however, that fix was too invasive for the backbranches. Here we just relax the Asserts to allow them to pass. The worst that appears to happen from this is that we show NaN cost values and infinite row estimates in EXPLAIN. add_path() would have had a hard time doing anything useful with such costs, but that does not really matter as if the row estimates were even close to accurate, such plan would not complete this side of the heat death of the universe. Reported-by: Onder Kalaci Backpatch: 9.5 to 13 Discussion: https://postgr.es/m/DM6PR21MB1211FF360183BCA901B27F04D80B0@DM6PR21MB1211.namprd21.prod.outlook.com
1 parent 994a02f commit 00fecc2
Copy full SHA for 00fecc2

File tree

Expand file treeCollapse file tree

1 file changed

+6
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/backend/optimizer/path/costsize.c
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,8 +2276,9 @@ initial_cost_mergejoin(PlannerInfo *root, JoinCostWorkspace *workspace,
22762276
outer_rows = clamp_row_est(outer_path_rows * outerendsel);
22772277
inner_rows = clamp_row_est(inner_path_rows * innerendsel);
22782278

2279-
Assert(outer_skip_rows <= outer_rows);
2280-
Assert(inner_skip_rows <= inner_rows);
2279+
/* skip rows can become NaN when path rows has become infinite */
2280+
Assert(outer_skip_rows <= outer_rows || isnan(outer_skip_rows));
2281+
Assert(inner_skip_rows <= inner_rows || isnan(inner_skip_rows));
22812282

22822283
/*
22832284
* Readjust scan selectivities to account for above rounding. This is
@@ -2289,8 +2290,9 @@ initial_cost_mergejoin(PlannerInfo *root, JoinCostWorkspace *workspace,
22892290
outerendsel = outer_rows / outer_path_rows;
22902291
innerendsel = inner_rows / inner_path_rows;
22912292

2292-
Assert(outerstartsel <= outerendsel);
2293-
Assert(innerstartsel <= innerendsel);
2293+
/* start sel can become NaN when path rows has become infinite */
2294+
Assert(outerstartsel <= outerendsel || isnan(outerstartsel));
2295+
Assert(innerstartsel <= innerendsel || isnan(innerstartsel));
22942296

22952297
/* cost of source data */
22962298

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.