* Hack for non-functional btree npages estimation:
* npages = index_pages * selectivity_of_1st_attr_clause(s)
This commit is contained in:
parent
72d271177c
commit
67712200f1
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.5 1997/04/09 01:52:04 vadim Exp $
|
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.6 1997/04/24 16:07:14 vadim Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -499,6 +499,8 @@ IndexSelectivity(Oid indexrelid,
|
|||||||
float64data npages, select;
|
float64data npages, select;
|
||||||
float64 amopnpages, amopselect;
|
float64 amopnpages, amopselect;
|
||||||
Oid relam;
|
Oid relam;
|
||||||
|
bool nphack = false;
|
||||||
|
float64data fattr_select = 1.0;
|
||||||
|
|
||||||
indRel = SearchSysCacheTuple(RELOID,
|
indRel = SearchSysCacheTuple(RELOID,
|
||||||
ObjectIdGetDatum(indexrelid),
|
ObjectIdGetDatum(indexrelid),
|
||||||
@ -516,6 +518,15 @@ IndexSelectivity(Oid indexrelid,
|
|||||||
indexrelid);
|
indexrelid);
|
||||||
index = (IndexTupleForm)GETSTRUCT(indexTuple);
|
index = (IndexTupleForm)GETSTRUCT(indexTuple);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hack for non-functional btree npages estimation:
|
||||||
|
* npages = index_pages * selectivity_of_1st_attr_clause(s)
|
||||||
|
* - vadim 04/24/97
|
||||||
|
*/
|
||||||
|
if ( relam == BTREE_AM_OID &&
|
||||||
|
varAttributeNumbers[0] != InvalidAttrNumber )
|
||||||
|
nphack = true;
|
||||||
|
|
||||||
npages = 0.0;
|
npages = 0.0;
|
||||||
select = 1.0;
|
select = 1.0;
|
||||||
for (n = 0; n < nIndexKeys; ++n) {
|
for (n = 0; n < nIndexKeys; ++n) {
|
||||||
@ -556,7 +567,10 @@ IndexSelectivity(Oid indexrelid,
|
|||||||
elog(WARN, "IndexSelectivity: no amop %d %d",
|
elog(WARN, "IndexSelectivity: no amop %d %d",
|
||||||
indclass, operatorObjectIds[n]);
|
indclass, operatorObjectIds[n]);
|
||||||
amop = (Form_pg_amop)GETSTRUCT(amopTuple);
|
amop = (Form_pg_amop)GETSTRUCT(amopTuple);
|
||||||
amopnpages = (float64) fmgr(amop->amopnpages,
|
|
||||||
|
if ( !nphack )
|
||||||
|
{
|
||||||
|
amopnpages = (float64) fmgr(amop->amopnpages,
|
||||||
(char *) operatorObjectIds[n],
|
(char *) operatorObjectIds[n],
|
||||||
(char *) indrelid,
|
(char *) indrelid,
|
||||||
(char *) varAttributeNumbers[n],
|
(char *) varAttributeNumbers[n],
|
||||||
@ -573,7 +587,8 @@ IndexSelectivity(Oid indexrelid,
|
|||||||
if ((i = npages) < npages) /* ceil(npages)? */
|
if ((i = npages) < npages) /* ceil(npages)? */
|
||||||
npages += 1.0;
|
npages += 1.0;
|
||||||
#endif
|
#endif
|
||||||
npages += PointerIsValid(amopnpages) ? *amopnpages : 0.0;
|
npages += PointerIsValid(amopnpages) ? *amopnpages : 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
amopselect = (float64) fmgr(amop->amopselect,
|
amopselect = (float64) fmgr(amop->amopselect,
|
||||||
(char *) operatorObjectIds[n],
|
(char *) operatorObjectIds[n],
|
||||||
@ -583,15 +598,27 @@ IndexSelectivity(Oid indexrelid,
|
|||||||
(char *) constFlags[n],
|
(char *) constFlags[n],
|
||||||
(char *) nIndexKeys,
|
(char *) nIndexKeys,
|
||||||
(char *) indexrelid);
|
(char *) indexrelid);
|
||||||
|
|
||||||
|
if ( nphack && varAttributeNumbers[n] == index->indkey[0] )
|
||||||
|
fattr_select *= PointerIsValid(amopselect) ? *amopselect : 1.0;
|
||||||
|
|
||||||
select *= PointerIsValid(amopselect) ? *amopselect : 1.0;
|
select *= PointerIsValid(amopselect) ? *amopselect : 1.0;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Estimation of npages below is hack of course, but it's
|
* Estimation of npages below is hack of course, but it's
|
||||||
* better than it was before. - vadim 04/09/97
|
* better than it was before. - vadim 04/09/97
|
||||||
*/
|
*/
|
||||||
if ( nIndexKeys > 1 )
|
if ( nphack )
|
||||||
npages = npages / (1.0 + nIndexKeys);
|
{
|
||||||
*idxPages = ceil ((double)(npages/nIndexKeys));
|
npages = fattr_select * ((Form_pg_class)GETSTRUCT(indRel))->relpages;
|
||||||
|
*idxPages = ceil ((double)npages);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( nIndexKeys > 1 )
|
||||||
|
npages = npages / (1.0 + nIndexKeys);
|
||||||
|
*idxPages = ceil ((double)(npages/nIndexKeys));
|
||||||
|
}
|
||||||
*idxSelec = select;
|
*idxSelec = select;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user