Skip to content

Commit ae0c8d0

Browse files
committed
Remove "fuzzy comparison" logic in qsort comparison function for
choose_bitmap_and(). It was way too fuzzy --- per comment, it was meant to be 1% relative difference, but was actually coded as 0.01 absolute difference, thus causing selectivities of say 0.001 and 0.000000000001 to be treated as equal. I believe this thinko explains Maxim Boguk's recent complaint. While we could change it to a relative test coded like compare_fuzzy_path_costs(), there's a bigger problem here, which is that any fuzziness at all renders the comparison function non-transitive, which could confuse qsort() to the point of delivering completely wrong results. So forget the whole thing and just do an exact comparison.
1 parent ca9d503 commit ae0c8d0

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/backend/optimizer/path/indxpath.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.207 2006/06/06 17:59:57 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.208 2006/06/07 17:08:07 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -674,20 +674,18 @@ bitmap_path_comparator(const void *a, const void *b)
674674
Cost bcost;
675675
Selectivity aselec;
676676
Selectivity bselec;
677-
Selectivity diff;
678677

679678
cost_bitmap_tree_node(pa, &acost, &aselec);
680679
cost_bitmap_tree_node(pb, &bcost, &bselec);
681680

682681
/*
683-
* Since selectivities are often pretty crude, don't put blind faith
684-
* in them; if the selectivities are within 1% of being the same, treat
685-
* them as equal and sort by cost instead.
682+
* If selectivities are the same, sort by cost. (Note: there used to be
683+
* logic here to do "fuzzy comparison", but that's a bad idea because it
684+
* fails to be transitive, which will confuse qsort terribly.)
686685
*/
687-
diff = aselec - bselec;
688-
if (diff < -0.01)
686+
if (aselec < bselec)
689687
return -1;
690-
if (diff > 0.01)
688+
if (aselec > bselec)
691689
return 1;
692690

693691
if (acost < bcost)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy