mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Finish repairing 6.5's problems with r-tree indexes: create appropriate
selectivity functions and make the r-tree operators use them. The estimation functions themselves are just stubs, unfortunately, but perhaps someday someone will make them compute realistic estimates. Change pg_am so that the optimizer can reliably tell the difference between ordered and unordered indexes --- before it would think that an r-tree index can be scanned in '<<' order, which is not right AFAIK. Repair broken negator links for network_sup and related ops. Initdb forced. This might be my last initdb force for 7.0 ... hope so anyway ...
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.47 2000/02/15 20:49:20 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.48 2000/02/17 03:39:40 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -96,8 +96,8 @@ find_secondary_indexes(Query *root, Index relid)
|
||||
IndexOptInfo *info = makeNode(IndexOptInfo);
|
||||
int i;
|
||||
Relation indexRelation;
|
||||
uint16 amstrategy;
|
||||
Oid relam;
|
||||
uint16 amorderstrategy;
|
||||
|
||||
/*
|
||||
* Need to make these arrays large enough to be sure there is a
|
||||
@@ -129,37 +129,38 @@ find_secondary_indexes(Query *root, Index relid)
|
||||
|
||||
/* Extract info from the relation descriptor for the index */
|
||||
indexRelation = index_open(index->indexrelid);
|
||||
#ifdef notdef
|
||||
/* XXX should iterate through strategies -- but how? use #1 for now */
|
||||
amstrategy = indexRelation->rd_am->amstrategies;
|
||||
#endif /* notdef */
|
||||
amstrategy = 1;
|
||||
relam = indexRelation->rd_rel->relam;
|
||||
info->relam = relam;
|
||||
info->pages = indexRelation->rd_rel->relpages;
|
||||
info->tuples = indexRelation->rd_rel->reltuples;
|
||||
info->amcostestimate = index_cost_estimator(indexRelation);
|
||||
amorderstrategy = indexRelation->rd_am->amorderstrategy;
|
||||
index_close(indexRelation);
|
||||
|
||||
/*
|
||||
* Fetch the ordering operators associated with the index.
|
||||
*
|
||||
* XXX what if it's a hash or other unordered index?
|
||||
* Fetch the ordering operators associated with the index,
|
||||
* if any.
|
||||
*/
|
||||
MemSet(info->ordering, 0, sizeof(Oid) * (INDEX_MAX_KEYS+1));
|
||||
for (i = 0; i < INDEX_MAX_KEYS && index->indclass[i]; i++)
|
||||
if (amorderstrategy != 0)
|
||||
{
|
||||
HeapTuple amopTuple;
|
||||
for (i = 0; i < INDEX_MAX_KEYS && index->indclass[i]; i++)
|
||||
{
|
||||
HeapTuple amopTuple;
|
||||
Form_pg_amop amop;
|
||||
|
||||
amopTuple = SearchSysCacheTuple(AMOPSTRATEGY,
|
||||
amopTuple =
|
||||
SearchSysCacheTuple(AMOPSTRATEGY,
|
||||
ObjectIdGetDatum(relam),
|
||||
ObjectIdGetDatum(index->indclass[i]),
|
||||
UInt16GetDatum(amstrategy),
|
||||
UInt16GetDatum(amorderstrategy),
|
||||
0);
|
||||
if (!HeapTupleIsValid(amopTuple))
|
||||
elog(ERROR, "find_secondary_indexes: no amop %u %u %d",
|
||||
relam, index->indclass[i], amstrategy);
|
||||
info->ordering[i] = ((Form_pg_amop) GETSTRUCT(amopTuple))->amopopr;
|
||||
if (!HeapTupleIsValid(amopTuple))
|
||||
elog(ERROR, "find_secondary_indexes: no amop %u %u %d",
|
||||
relam, index->indclass[i], (int) amorderstrategy);
|
||||
amop = (Form_pg_amop) GETSTRUCT(amopTuple);
|
||||
info->ordering[i] = amop->amopopr;
|
||||
}
|
||||
}
|
||||
|
||||
indexes = lcons(info, indexes);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* geo-selfuncs.c
|
||||
* geo_selfuncs.c
|
||||
* Selectivity routines registered in the operator catalog in the
|
||||
* "oprrest" and "oprjoin" attributes.
|
||||
*
|
||||
@@ -9,9 +9,10 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_selfuncs.c,v 1.12 2000/01/26 05:57:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_selfuncs.c,v 1.13 2000/02/17 03:39:42 tgl Exp $
|
||||
*
|
||||
* XXX These are totally bogus.
|
||||
* XXX These are totally bogus. Perhaps someone will make them do
|
||||
* something reasonable, someday.
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -19,17 +20,41 @@
|
||||
|
||||
#include "utils/builtins.h"
|
||||
|
||||
|
||||
/*
|
||||
* Selectivity functions for rtrees. These are bogus -- unless we know
|
||||
* the actual key distribution in the index, we can't make a good prediction
|
||||
* of the selectivity of these operators.
|
||||
*
|
||||
* Note: the values used here may look unreasonably small. Perhaps they
|
||||
* are. For now, we want to make sure that the optimizer will make use
|
||||
* of an r-tree index if one is available, so the selectivity had better
|
||||
* be fairly small.
|
||||
*
|
||||
* In general, rtrees need to search multiple subtrees in order to guarantee
|
||||
* that all occurrences of the same key have been found. Because of this,
|
||||
* the estimated cost for scanning the index ought to be higher than the
|
||||
* output selectivity would indicate. rtcostestimate(), over in selfuncs.c,
|
||||
* ought to be adjusted accordingly --- but until we can generate somewhat
|
||||
* realistic numbers here, it hardly matters...
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Selectivity for operators that depend on area, such as "overlap".
|
||||
*/
|
||||
|
||||
float64
|
||||
areasel(Oid opid,
|
||||
Oid relid,
|
||||
AttrNumber attno,
|
||||
char *value,
|
||||
Datum value,
|
||||
int32 flag)
|
||||
{
|
||||
float64 result;
|
||||
|
||||
result = (float64) palloc(sizeof(float64data));
|
||||
*result = 1.0 / 4.0;
|
||||
*result = 0.05;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -43,81 +68,66 @@ areajoinsel(Oid opid,
|
||||
float64 result;
|
||||
|
||||
result = (float64) palloc(sizeof(float64data));
|
||||
*result = 1.0 / 4.0;
|
||||
*result = 0.05;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Selectivity functions for rtrees. These are bogus -- unless we know
|
||||
* the actual key distribution in the index, we can't make a good prediction
|
||||
* of the selectivity of these operators.
|
||||
* positionsel
|
||||
*
|
||||
* In general, rtrees need to search multiple subtrees in order to guarantee
|
||||
* that all occurrences of the same key have been found. Because of this,
|
||||
* the heuristic selectivity functions we return are higher than they would
|
||||
* otherwise be.
|
||||
* How likely is a box to be strictly left of (right of, above, below)
|
||||
* a given box?
|
||||
*/
|
||||
|
||||
/*
|
||||
* left_sel -- How likely is a box to be strictly left of (right of, above,
|
||||
* below) a given box?
|
||||
*/
|
||||
|
||||
#ifdef NOT_USED
|
||||
float64
|
||||
leftsel(Oid opid,
|
||||
Oid relid,
|
||||
AttrNumber attno,
|
||||
char *value,
|
||||
int32 flag)
|
||||
positionsel(Oid opid,
|
||||
Oid relid,
|
||||
AttrNumber attno,
|
||||
Datum value,
|
||||
int32 flag)
|
||||
{
|
||||
float64 result;
|
||||
|
||||
result = (float64) palloc(sizeof(float64data));
|
||||
*result = 1.0 / 6.0;
|
||||
*result = 0.1;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef NOT_USED
|
||||
float64
|
||||
leftjoinsel(Oid opid,
|
||||
Oid relid1,
|
||||
AttrNumber attno1,
|
||||
Oid relid2,
|
||||
AttrNumber attno2)
|
||||
positionjoinsel(Oid opid,
|
||||
Oid relid1,
|
||||
AttrNumber attno1,
|
||||
Oid relid2,
|
||||
AttrNumber attno2)
|
||||
{
|
||||
float64 result;
|
||||
|
||||
result = (float64) palloc(sizeof(float64data));
|
||||
*result = 1.0 / 6.0;
|
||||
*result = 0.1;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* contsel -- How likely is a box to contain (be contained by) a given box?
|
||||
*
|
||||
* This is a tighter constraint than "overlap", so produce a smaller
|
||||
* estimate than areasel does.
|
||||
*/
|
||||
#ifdef NOT_USED
|
||||
|
||||
float64
|
||||
contsel(Oid opid,
|
||||
Oid relid,
|
||||
AttrNumber attno,
|
||||
char *value,
|
||||
Datum value,
|
||||
int32 flag)
|
||||
{
|
||||
float64 result;
|
||||
|
||||
result = (float64) palloc(sizeof(float64data));
|
||||
*result = 1.0 / 10.0;
|
||||
*result = 0.01;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef NOT_USED
|
||||
float64
|
||||
contjoinsel(Oid opid,
|
||||
Oid relid1,
|
||||
@@ -128,8 +138,6 @@ contjoinsel(Oid opid,
|
||||
float64 result;
|
||||
|
||||
result = (float64) palloc(sizeof(float64data));
|
||||
*result = 1.0 / 10.0;
|
||||
*result = 0.01;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user