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

Commit37c443e

Browse files
committed
Fix compare_fuzzy_path_costs() to behave a bit more sanely. The original
coding would ignore startup cost differences of less than 1% of theestimated total cost; which was OK for normal planning but highly not OKif a very small LIMIT was applied afterwards, so that startup cost becomesthe name of the game. Instead, compare startup and total costs fuzzilybut independently. This changes the plan selected for two queries in theregression tests; adjust expected-output files for resulting changes inrow order. Per reports from Dawid Kuroczko and Sam Mason.
1 parent3758aff commit37c443e

File tree

6 files changed

+1506
-1525
lines changed

6 files changed

+1506
-1525
lines changed

‎src/backend/optimizer/util/pathnode.c

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.123 2005/07/15 17:09:25 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.124 2005/07/22 19:12:01 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -98,60 +98,41 @@ compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
9898
staticint
9999
compare_fuzzy_path_costs(Path*path1,Path*path2,CostSelectorcriterion)
100100
{
101-
Costfuzz;
102-
103101
/*
104-
* The fuzz factor is set at one percent of the smaller total_cost,
105-
* but not less than 0.01 cost units (just in case total cost is
106-
* zero).
102+
* We use a fuzz factor of 1% of the smaller cost.
107103
*
108104
* XXX does this percentage need to be user-configurable?
109105
*/
110-
fuzz=Min(path1->total_cost,path2->total_cost)*0.01;
111-
fuzz=Max(fuzz,0.01);
112-
113106
if (criterion==STARTUP_COST)
114107
{
115-
if (Abs(path1->startup_cost-path2->startup_cost)>fuzz)
116-
{
117-
if (path1->startup_cost<path2->startup_cost)
118-
return-1;
119-
else
120-
return+1;
121-
}
108+
if (path1->startup_cost>path2->startup_cost*1.01)
109+
return+1;
110+
if (path2->startup_cost>path1->startup_cost*1.01)
111+
return-1;
122112

123113
/*
124114
* If paths have the same startup cost (not at all unlikely),
125115
* order them by total cost.
126116
*/
127-
if (Abs(path1->total_cost-path2->total_cost)>fuzz)
128-
{
129-
if (path1->total_cost<path2->total_cost)
130-
return-1;
131-
else
132-
return+1;
133-
}
117+
if (path1->total_cost>path2->total_cost*1.01)
118+
return+1;
119+
if (path2->total_cost>path1->total_cost*1.01)
120+
return-1;
134121
}
135122
else
136123
{
137-
if (Abs(path1->total_cost-path2->total_cost)>fuzz)
138-
{
139-
if (path1->total_cost<path2->total_cost)
140-
return-1;
141-
else
142-
return+1;
143-
}
124+
if (path1->total_cost>path2->total_cost*1.01)
125+
return+1;
126+
if (path2->total_cost>path1->total_cost*1.01)
127+
return-1;
144128

145129
/*
146130
* If paths have the same total cost, order them by startup cost.
147131
*/
148-
if (Abs(path1->startup_cost-path2->startup_cost)>fuzz)
149-
{
150-
if (path1->startup_cost<path2->startup_cost)
151-
return-1;
152-
else
153-
return+1;
154-
}
132+
if (path1->startup_cost>path2->startup_cost*1.01)
133+
return+1;
134+
if (path2->startup_cost>path1->startup_cost*1.01)
135+
return-1;
155136
}
156137
return0;
157138
}

‎src/test/regress/expected/geometry.out

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,24 +258,24 @@ SELECT '' AS twenty, b.f1 / p.f1 AS rotation
258258
twenty | rotation
259259
--------+----------------------------------------------------------------------
260260
| (0,-0),(-0.2,-0.2)
261-
| (0.08,-0),(0,-0.56)
262-
| (0.0651176557644,0),(0,-0.0483449262493)
263-
| (-0,0.0828402366864),(-0.201183431953,0)
264-
| (0.2,0),(0,0)
265261
| (-0.1,-0.1),(-0.3,-0.3)
266-
| (0.12,-0.28),(0.04,-0.84)
267-
| (0.0976764836466,-0.0241724631247),(0.0325588278822,-0.072517389374)
268-
| (-0.100591715976,0.12426035503),(-0.301775147929,0.0414201183432)
269-
| (0.3,0),(0.1,0)
270262
| (-0.25,-0.25),(-0.25,-0.35)
271-
| (0.26,-0.7),(0.1,-0.82)
272-
| (0.109762715209,-0.0562379754329),(0.0813970697055,-0.0604311578117)
273-
| (-0.251479289941,0.103550295858),(-0.322485207101,0.0739644970414)
274-
| (0.3,0.05),(0.25,0)
275263
| (-0.3,-0.3),(-0.3,-0.3)
264+
| (0.08,-0),(0,-0.56)
265+
| (0.12,-0.28),(0.04,-0.84)
266+
| (0.26,-0.7),(0.1,-0.82)
276267
| (0.12,-0.84),(0.12,-0.84)
268+
| (0.0651176557644,0),(0,-0.0483449262493)
269+
| (0.0976764836466,-0.0241724631247),(0.0325588278822,-0.072517389374)
270+
| (0.109762715209,-0.0562379754329),(0.0813970697055,-0.0604311578117)
277271
| (0.0976764836466,-0.072517389374),(0.0976764836466,-0.072517389374)
272+
| (-0,0.0828402366864),(-0.201183431953,0)
273+
| (-0.100591715976,0.12426035503),(-0.301775147929,0.0414201183432)
274+
| (-0.251479289941,0.103550295858),(-0.322485207101,0.0739644970414)
278275
| (-0.301775147929,0.12426035503),(-0.301775147929,0.12426035503)
276+
| (0.2,0),(0,0)
277+
| (0.3,0),(0.1,0)
278+
| (0.3,0.05),(0.25,0)
279279
| (0.3,0),(0.3,0)
280280
(20 rows)
281281

‎src/test/regress/expected/geometry_1.out

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,24 +258,24 @@ SELECT '' AS twenty, b.f1 / p.f1 AS rotation
258258
twenty | rotation
259259
--------+----------------------------------------------------------------------
260260
| (0,0),(-0.2,-0.2)
261-
| (0.08,0),(0,-0.56)
262-
| (0.0651176557644,0),(0,-0.0483449262493)
263-
| (0,0.0828402366864),(-0.201183431953,0)
264-
| (0.2,0),(0,0)
265261
| (-0.1,-0.1),(-0.3,-0.3)
266-
| (0.12,-0.28),(0.04,-0.84)
267-
| (0.0976764836466,-0.0241724631247),(0.0325588278822,-0.072517389374)
268-
| (-0.100591715976,0.12426035503),(-0.301775147929,0.0414201183432)
269-
| (0.3,0),(0.1,0)
270262
| (-0.25,-0.25),(-0.25,-0.35)
271-
| (0.26,-0.7),(0.1,-0.82)
272-
| (0.109762715209,-0.0562379754329),(0.0813970697055,-0.0604311578117)
273-
| (-0.251479289941,0.103550295858),(-0.322485207101,0.0739644970414)
274-
| (0.3,0.05),(0.25,0)
275263
| (-0.3,-0.3),(-0.3,-0.3)
264+
| (0.08,0),(0,-0.56)
265+
| (0.12,-0.28),(0.04,-0.84)
266+
| (0.26,-0.7),(0.1,-0.82)
276267
| (0.12,-0.84),(0.12,-0.84)
268+
| (0.0651176557644,0),(0,-0.0483449262493)
269+
| (0.0976764836466,-0.0241724631247),(0.0325588278822,-0.072517389374)
270+
| (0.109762715209,-0.0562379754329),(0.0813970697055,-0.0604311578117)
277271
| (0.0976764836466,-0.072517389374),(0.0976764836466,-0.072517389374)
272+
| (0,0.0828402366864),(-0.201183431953,0)
273+
| (-0.100591715976,0.12426035503),(-0.301775147929,0.0414201183432)
274+
| (-0.251479289941,0.103550295858),(-0.322485207101,0.0739644970414)
278275
| (-0.301775147929,0.12426035503),(-0.301775147929,0.12426035503)
276+
| (0.2,0),(0,0)
277+
| (0.3,0),(0.1,0)
278+
| (0.3,0.05),(0.25,0)
279279
| (0.3,0),(0.3,0)
280280
(20 rows)
281281

‎src/test/regress/expected/geometry_2.out

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,24 +258,24 @@ SELECT '' AS twenty, b.f1 / p.f1 AS rotation
258258
twenty | rotation
259259
--------+----------------------------------------------------------------------
260260
| (0,-0),(-0.2,-0.2)
261-
| (0.08,-0),(0,-0.56)
262-
| (0.0651176557644,0),(0,-0.0483449262493)
263-
| (-0,0.0828402366864),(-0.201183431953,0)
264-
| (0.2,0),(0,0)
265261
| (-0.1,-0.1),(-0.3,-0.3)
266-
| (0.12,-0.28),(0.04,-0.84)
267-
| (0.0976764836466,-0.0241724631247),(0.0325588278822,-0.072517389374)
268-
| (-0.100591715976,0.12426035503),(-0.301775147929,0.0414201183432)
269-
| (0.3,0),(0.1,0)
270262
| (-0.25,-0.25),(-0.25,-0.35)
271-
| (0.26,-0.7),(0.1,-0.82)
272-
| (0.109762715209,-0.0562379754329),(0.0813970697055,-0.0604311578117)
273-
| (-0.251479289941,0.103550295858),(-0.322485207101,0.0739644970414)
274-
| (0.3,0.05),(0.25,0)
275263
| (-0.3,-0.3),(-0.3,-0.3)
264+
| (0.08,-0),(0,-0.56)
265+
| (0.12,-0.28),(0.04,-0.84)
266+
| (0.26,-0.7),(0.1,-0.82)
276267
| (0.12,-0.84),(0.12,-0.84)
268+
| (0.0651176557644,0),(0,-0.0483449262493)
269+
| (0.0976764836466,-0.0241724631247),(0.0325588278822,-0.072517389374)
270+
| (0.109762715209,-0.0562379754329),(0.0813970697055,-0.0604311578117)
277271
| (0.0976764836466,-0.072517389374),(0.0976764836466,-0.072517389374)
272+
| (-0,0.0828402366864),(-0.201183431953,0)
273+
| (-0.100591715976,0.12426035503),(-0.301775147929,0.0414201183432)
274+
| (-0.251479289941,0.103550295858),(-0.322485207101,0.0739644970414)
278275
| (-0.301775147929,0.12426035503),(-0.301775147929,0.12426035503)
276+
| (0.2,0),(0,0)
277+
| (0.3,0),(0.1,0)
278+
| (0.3,0.05),(0.25,0)
279279
| (0.3,0),(0.3,0)
280280
(20 rows)
281281

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp