Skip to content

Commit 598ea2c

Browse files
committed
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 ...
1 parent cf880a6 commit 598ea2c

File tree

12 files changed

+249
-181
lines changed

12 files changed

+249
-181
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.4 2000/02/06 05:09:31 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.5 2000/02/17 03:39:39 tgl Exp $
44
.TH "SYSTEM CATALOGS" INTRO 03/13/94 PostgreSQL PostgreSQL
55
.SH "Section 7 - System Catalogs"
66
.de LS
@@ -108,38 +108,37 @@ pg_aggregate
108108
.fi
109109
.nf M
110110
pg_am
111-
NameData amname /* access method name */
112-
oid amowner /* usesysid of creator */
113-
char amkind /* - deprecated */
114-
/* originally:
115-
h=hashed
116-
o=ordered
117-
s=special */
118-
int2 amstrategies /* total NUMBER of strategies by which
119-
we can traverse/search this AM */
120-
int2 amsupport /* total NUMBER of support functions
121-
that this AM uses */
122-
regproc amgettuple /* "next valid tuple" function */
123-
regproc aminsert /* "insert this tuple" function */
124-
regproc amdelete /* "delete this tuple" function */
125-
regproc amgetattr /* - deprecated */
126-
regproc amsetlock /* - deprecated */
127-
regproc amsettid /* - deprecated */
128-
regproc amfreetuple /* - deprecated */
129-
regproc ambeginscan /* "start new scan" function */
130-
regproc amrescan /* "restart this scan" function */
131-
regproc amendscan /* "end this scan" function */
132-
regproc ammarkpos /* "mark current scan position"
133-
function */
134-
regproc amrestrpos /* "restore marked scan position"
135-
function */
136-
regproc amopen /* - deprecated */
137-
regproc amclose /* - deprecated */
138-
regproc ambuild /* "build new index" function */
139-
regproc amcreate /* - deprecated */
140-
regproc amdestroy /* - deprecated */
141-
regproc amcostestimate /* estimate cost of an indexscan */
142-
111+
NameData amname /* access method name */
112+
oid amowner /* usesysid of creator */
113+
int2 amstrategies /* total NUMBER of strategies by which
114+
we can traverse/search this AM */
115+
int2 amsupport /* total NUMBER of support functions
116+
that this AM uses */
117+
int2 amorderstrategy /* if this AM has a sort order, the
118+
* strategy number of the sort operator.
119+
* Zero if AM is not ordered.
120+
*/
121+
regproc amgettuple /* "next valid tuple" function */
122+
regproc aminsert /* "insert this tuple" function */
123+
regproc amdelete /* "delete this tuple" function */
124+
regproc amgetattr /* - deprecated */
125+
regproc amsetlock /* - deprecated */
126+
regproc amsettid /* - deprecated */
127+
regproc amfreetuple /* - deprecated */
128+
regproc ambeginscan /* "start new scan" function */
129+
regproc amrescan /* "restart this scan" function */
130+
regproc amendscan /* "end this scan" function */
131+
regproc ammarkpos /* "mark current scan position"
132+
function */
133+
regproc amrestrpos /* "restore marked scan position"
134+
function */
135+
regproc amopen /* - deprecated */
136+
regproc amclose /* - deprecated */
137+
regproc ambuild /* "build new index" function */
138+
regproc amcreate /* - deprecated */
139+
regproc amdestroy /* - deprecated */
140+
regproc amcostestimate /* estimate cost of an indexscan */
141+
143142
.fi
144143
.nf M
145144
pg_amop

doc/src/sgml/xindex.sgml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.7 2000/01/24 07:16:49 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.8 2000/02/17 03:39:39 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -51,10 +51,6 @@ Postgres documentation
5151
<entry>amowner</entry>
5252
<entry>object id of the owner's instance in pg_user</entry>
5353
</row>
54-
<row>
55-
<entry>amkind</entry>
56-
<entry>not used at present, but set to 'o' as a place holder</entry>
57-
</row>
5854
<row>
5955
<entry>amstrategies</entry>
6056
<entry>number of strategies for this access method (see below)</entry>
@@ -63,6 +59,11 @@ Postgres documentation
6359
<entry>amsupport</entry>
6460
<entry>number of support routines for this access method (see below)</entry>
6561
</row>
62+
<row>
63+
<entry>amorderstrategy</entry>
64+
<entry>zero if the index offers no sort order, otherwise the strategy
65+
number of the strategy operator that describes the sort order</entry>
66+
</row>
6667
<row>
6768
<entry>amgettuple</entry>
6869
</row>
@@ -217,6 +218,15 @@ SELECT oid FROM pg_am WHERE amname = 'btree';
217218
method. The actual routines are listed elsewhere.
218219
</para>
219220

221+
<para>
222+
By the way, the <filename>amorderstrategy</filename> entry tells whether
223+
the access method supports ordered scan. Zero means it doesn't; if it
224+
does, <filename>amorderstrategy</filename> is the number of the strategy
225+
routine that corresponds to the ordering operator. For example, btree
226+
has <filename>amorderstrategy</filename> = 1 which is its
227+
"less than" strategy number.
228+
</para>
229+
220230
<para>
221231
The next class of interest is pg_opclass. This class exists only to
222232
associate a name and default type with an oid. In pg_amop, every

doc/src/sgml/xoper.sgml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@ SELECT (a + b) AS c FROM test_complex;
265265
yet.) If you do not do this, things will still work, but the optimizer's
266266
estimates won't be as good as they could be.
267267
</para>
268+
269+
<para>
270+
There are additional selectivity functions designed for geometric
271+
operators in src/backend/utils/adt/geo_selfuncs.c: areasel, positionsel,
272+
and contsel. At this writing these are just stubs, but you may want
273+
to use them (or even better, improve them) anyway.
274+
</para>
268275
</sect2>
269276

270277
<sect2>
@@ -294,6 +301,9 @@ SELECT (a + b) AS c FROM test_complex;
294301
neqjoinsel for &lt;&gt;
295302
scalarltjoinsel for &lt; or &lt;=
296303
scalargtjoinsel for &gt; or &gt;=
304+
areajoinsel for 2D area-based comparisons
305+
positionjoinsel for 2D position-based comparisons
306+
contjoinsel for 2D containment-based comparisons
297307
</ProgramListing>
298308
</para>
299309
</sect2>

src/backend/optimizer/util/plancat.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.47 2000/02/15 20:49:20 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.48 2000/02/17 03:39:40 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -96,8 +96,8 @@ find_secondary_indexes(Query *root, Index relid)
9696
IndexOptInfo *info = makeNode(IndexOptInfo);
9797
int i;
9898
Relation indexRelation;
99-
uint16 amstrategy;
10099
Oid relam;
100+
uint16 amorderstrategy;
101101

102102
/*
103103
* Need to make these arrays large enough to be sure there is a
@@ -129,37 +129,38 @@ find_secondary_indexes(Query *root, Index relid)
129129

130130
/* Extract info from the relation descriptor for the index */
131131
indexRelation = index_open(index->indexrelid);
132-
#ifdef notdef
133-
/* XXX should iterate through strategies -- but how? use #1 for now */
134-
amstrategy = indexRelation->rd_am->amstrategies;
135-
#endif /* notdef */
136-
amstrategy = 1;
137132
relam = indexRelation->rd_rel->relam;
138133
info->relam = relam;
139134
info->pages = indexRelation->rd_rel->relpages;
140135
info->tuples = indexRelation->rd_rel->reltuples;
141136
info->amcostestimate = index_cost_estimator(indexRelation);
137+
amorderstrategy = indexRelation->rd_am->amorderstrategy;
142138
index_close(indexRelation);
143139

144140
/*
145-
* Fetch the ordering operators associated with the index.
146-
*
147-
* XXX what if it's a hash or other unordered index?
141+
* Fetch the ordering operators associated with the index,
142+
* if any.
148143
*/
149144
MemSet(info->ordering, 0, sizeof(Oid) * (INDEX_MAX_KEYS+1));
150-
for (i = 0; i < INDEX_MAX_KEYS && index->indclass[i]; i++)
145+
if (amorderstrategy != 0)
151146
{
152-
HeapTuple amopTuple;
147+
for (i = 0; i < INDEX_MAX_KEYS && index->indclass[i]; i++)
148+
{
149+
HeapTuple amopTuple;
150+
Form_pg_amop amop;
153151

154-
amopTuple = SearchSysCacheTuple(AMOPSTRATEGY,
152+
amopTuple =
153+
SearchSysCacheTuple(AMOPSTRATEGY,
155154
ObjectIdGetDatum(relam),
156155
ObjectIdGetDatum(index->indclass[i]),
157-
UInt16GetDatum(amstrategy),
156+
UInt16GetDatum(amorderstrategy),
158157
0);
159-
if (!HeapTupleIsValid(amopTuple))
160-
elog(ERROR, "find_secondary_indexes: no amop %u %u %d",
161-
relam, index->indclass[i], amstrategy);
162-
info->ordering[i] = ((Form_pg_amop) GETSTRUCT(amopTuple))->amopopr;
158+
if (!HeapTupleIsValid(amopTuple))
159+
elog(ERROR, "find_secondary_indexes: no amop %u %u %d",
160+
relam, index->indclass[i], (int) amorderstrategy);
161+
amop = (Form_pg_amop) GETSTRUCT(amopTuple);
162+
info->ordering[i] = amop->amopopr;
163+
}
163164
}
164165

165166
indexes = lcons(info, indexes);

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