Skip to content

Commit fa2629b

Browse files
committed
Fix (hack) IndexSelectivity():
use sum(npages)/((nkeys == 1) ? 1 : nkeys + 1) as expected index page estimation for multi-key quals - instead of sum(npages). In old code npages for x > 10 and x < 20 is twice as for x > 10 - cool ?
1 parent b30aa6e commit fa2629b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/backend/optimizer/util/plancat.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.4 1997/03/12 21:06:14 scrappy Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.5 1997/04/09 01:52:04 vadim Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -564,9 +564,17 @@ IndexSelectivity(Oid indexrelid,
564564
(char *) constFlags[n],
565565
(char *) nIndexKeys,
566566
(char *) indexrelid);
567+
#if 0
568+
/*
569+
* So cool guys! Npages for x > 10 and x < 20 is twice as
570+
* npages for x > 10! - vadim 04/09/97
571+
*/
567572
npages += PointerIsValid(amopnpages) ? *amopnpages : 0.0;
568573
if ((i = npages) < npages) /* ceil(npages)? */
569574
npages += 1.0;
575+
#endif
576+
npages += PointerIsValid(amopnpages) ? *amopnpages : 0.0;
577+
570578
amopselect = (float64) fmgr(amop->amopselect,
571579
(char *) operatorObjectIds[n],
572580
(char *) indrelid,
@@ -577,7 +585,13 @@ IndexSelectivity(Oid indexrelid,
577585
(char *) indexrelid);
578586
select *= PointerIsValid(amopselect) ? *amopselect : 1.0;
579587
}
580-
*idxPages = npages;
588+
/*
589+
* Estimation of npages below is hack of course, but it's
590+
* better than it was before. - vadim 04/09/97
591+
*/
592+
if ( nIndexKeys > 1 )
593+
npages = npages / (1.0 + nIndexKeys);
594+
*idxPages = ceil ((double)(npages/nIndexKeys));
581595
*idxSelec = select;
582596
}
583597

0 commit comments

Comments
 (0)