Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fcf4b14

Browse files
committed
Simplify pg_am representation of ordering-capable access methods:
provide just a boolean 'amcanorder', instead of fields that specify the sort operator strategy numbers. We have decided to require ordering-capable AMs to use btree-compatible strategy numbers, so the old fields are overkill (and indeed misleading about what's allowed).
1 parent c82cc60 commit fcf4b14

File tree

8 files changed

+58
-80
lines changed

8 files changed

+58
-80
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.141 2007/01/09 02:14:09 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.142 2007/01/20 23:13:01 tgl Exp $ -->
22
<!--
33
Documentation of the system catalogs, directed toward PostgreSQL developers
44
-->
@@ -365,21 +365,10 @@
365365
</row>
366366

367367
<row>
368-
<entry><structfield>amorderstrategy</structfield></entry>
369-
<entry><type>int2</type></entry>
370-
<entry></entry>
371-
<entry>Zero if the index offers no sort order, otherwise the strategy
372-
number of the strategy operator that describes the default
373-
(<literal>ASC</>) sort order</entry>
374-
</row>
375-
376-
<row>
377-
<entry><structfield>amdescorder</structfield></entry>
378-
<entry><type>int2</type></entry>
368+
<entry><structfield>amcanorder</structfield></entry>
369+
<entry><type>bool</type></entry>
379370
<entry></entry>
380-
<entry>Zero if the index offers no sort order, otherwise the strategy
381-
number of the strategy operator that describes the <literal>DESC</>
382-
sort order</entry>
371+
<entry>Does the access method support ordered scans?</entry>
383372
</row>
384373

385374
<row>

doc/src/sgml/indexam.sgml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/indexam.sgml,v 2.19 2006/12/23 00:43:08 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/indexam.sgml,v 2.20 2007/01/20 23:13:01 tgl Exp $ -->
22

33
<chapter id="indexam">
44
<title>Index Access Method Interface Definition</title>
@@ -442,6 +442,15 @@ amrestrpos (IndexScanDesc scan);
442442
the scan keys to a <quote>normalized</> form.
443443
</para>
444444

445+
<para>
446+
Some access methods return index entries in a well-defined order, others
447+
do not. If entries are returned in sorted order, the access method should
448+
set <structname>pg_am</>.<structfield>amcanorder</> true to indicate that
449+
it supports ordered scans.
450+
All such access methods must use btree-compatible strategy numbers for
451+
their equality and ordering operators.
452+
</para>
453+
445454
<para>
446455
The <function>amgettuple</> function has a <literal>direction</> argument,
447456
which can be either <literal>ForwardScanDirection</> (the normal case)
@@ -451,8 +460,7 @@ amrestrpos (IndexScanDesc scan);
451460
the normal front-to-back direction, so <function>amgettuple</> must return
452461
the last matching tuple in the index, rather than the first one as it
453462
normally would. (This will only occur for access
454-
methods that advertise they support ordered scans by setting
455-
<structname>pg_am</>.<structfield>amorderstrategy</> nonzero.) After the
463+
methods that advertise they support ordered scans.) After the
456464
first call, <function>amgettuple</> must be prepared to advance the scan in
457465
either direction from the most recently returned entry.
458466
</para>

doc/src/sgml/xindex.sgml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/xindex.sgml,v 1.54 2007/01/09 02:14:10 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/xindex.sgml,v 1.55 2007/01/20 23:13:01 tgl Exp $ -->
22

33
<sect1 id="xindex">
44
<title>Interfacing Extensions To Indexes</title>
@@ -287,20 +287,6 @@
287287
return type <type>boolean</type>, since they must appear at the top
288288
level of a <literal>WHERE</> clause to be used with an index.
289289
</para>
290-
291-
<para>
292-
By the way, the <structfield>amorderstrategy</structfield> and
293-
<structfield>amdescorder</structfield> columns in <classname>pg_am</> tell
294-
whether the index method supports ordered scans. Zeroes mean it doesn't;
295-
if it does, <structfield>amorderstrategy</structfield> is the strategy
296-
number that corresponds to the default ordering operator, and
297-
<structfield>amdescorder</structfield> is the strategy number for the
298-
ordering operator of an index column that has the <literal>DESC</> option.
299-
For example, B-tree has <structfield>amorderstrategy</structfield> = 1,
300-
which is its <quote>less than</quote> strategy number, and
301-
<structfield>amdescorder</structfield> = 5, which is its
302-
<quote>greater than</quote> strategy number.
303-
</para>
304290
</sect2>
305291

306292
<sect2 id="xindex-support">

src/backend/commands/indexcmds.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.152 2007/01/09 02:14:11 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.153 2007/01/20 23:13:01 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -295,8 +295,7 @@ DefineIndex(RangeVar *heapRelation,
295295
errmsg("access method \"%s\" does not support multicolumn indexes",
296296
accessMethodName)));
297297

298-
amcanorder = (accessMethodForm->amorderstrategy > 0);
299-
298+
amcanorder = accessMethodForm->amcanorder;
300299
amoptions = accessMethodForm->amoptions;
301300

302301
ReleaseSysCache(tuple);

src/backend/optimizer/util/plancat.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.131 2007/01/09 02:14:13 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.132 2007/01/20 23:13:01 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -190,8 +190,10 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
190190

191191
/*
192192
* Fetch the ordering operators associated with the index, if any.
193+
* We expect that all ordering-capable indexes use btree's
194+
* strategy numbers for the ordering operators.
193195
*/
194-
if (indexRelation->rd_am->amorderstrategy > 0)
196+
if (indexRelation->rd_am->amcanorder)
195197
{
196198
int nstrat = indexRelation->rd_am->amstrategies;
197199

@@ -203,17 +205,17 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
203205

204206
if (opt & INDOPTION_DESC)
205207
{
206-
fwdstrat = indexRelation->rd_am->amdescorder;
207-
revstrat = indexRelation->rd_am->amorderstrategy;
208+
fwdstrat = BTGreaterStrategyNumber;
209+
revstrat = BTLessStrategyNumber;
208210
}
209211
else
210212
{
211-
fwdstrat = indexRelation->rd_am->amorderstrategy;
212-
revstrat = indexRelation->rd_am->amdescorder;
213+
fwdstrat = BTLessStrategyNumber;
214+
revstrat = BTGreaterStrategyNumber;
213215
}
214216
/*
215217
* Index AM must have a fixed set of strategies for it
216-
* to make sense to specify amorderstrategy, so we
218+
* to make sense to specify amcanorder, so we
217219
* need not allow the case amstrategies == 0.
218220
*/
219221
if (fwdstrat > 0)

src/backend/utils/adt/ruleutils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.244 2007/01/20 01:08:42 neilc Exp $
12+
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.245 2007/01/20 23:13:01 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -767,7 +767,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, int prettyFlags)
767767
&buf);
768768

769769
/* Add options if relevant */
770-
if (amrec->amorderstrategy > 0)
770+
if (amrec->amcanorder)
771771
{
772772
/* if it supports sort ordering, report DESC and NULLS opts */
773773
if (opt & INDOPTION_DESC)

src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.374 2007/01/20 21:47:10 neilc Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.375 2007/01/20 23:13:01 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200701202
56+
#define CATALOG_VERSION_NO 200701203
5757

5858
#endif

src/include/catalog/pg_am.h

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_am.h,v 1.49 2007/01/09 02:14:15 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_am.h,v 1.50 2007/01/20 23:13:01 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -45,12 +45,7 @@ CATALOG(pg_am,2601)
4545
* strategy assignments. */
4646
int2 amsupport; /* total number of support functions that this
4747
* AM uses */
48-
int2 amorderstrategy;/* if this AM has a sort order, the strategy
49-
* number of the default (ASC) sort operator.
50-
* Zero if AM is not ordered. */
51-
int2 amdescorder; /* if this AM has a sort order, the strategy
52-
* number of the DESC sort operator.
53-
* Zero if AM is not ordered. */
48+
bool amcanorder; /* does AM support ordered scan results? */
5449
bool amcanunique; /* does AM support UNIQUE indexes? */
5550
bool amcanmulticol; /* does AM support multi-column indexes? */
5651
bool amoptionalkey; /* can query omit key for the first column? */
@@ -83,47 +78,46 @@ typedef FormData_pg_am *Form_pg_am;
8378
* compiler constants for pg_am
8479
* ----------------
8580
*/
86-
#define Natts_pg_am 24
81+
#define Natts_pg_am 23
8782
#define Anum_pg_am_amname 1
8883
#define Anum_pg_am_amstrategies 2
8984
#define Anum_pg_am_amsupport 3
90-
#define Anum_pg_am_amorderstrategy 4
91-
#define Anum_pg_am_amdescorder 5
92-
#define Anum_pg_am_amcanunique 6
93-
#define Anum_pg_am_amcanmulticol 7
94-
#define Anum_pg_am_amoptionalkey 8
95-
#define Anum_pg_am_amindexnulls 9
96-
#define Anum_pg_am_amstorage 10
97-
#define Anum_pg_am_amclusterable 11
98-
#define Anum_pg_am_aminsert 12
99-
#define Anum_pg_am_ambeginscan 13
100-
#define Anum_pg_am_amgettuple 14
101-
#define Anum_pg_am_amgetmulti 15
102-
#define Anum_pg_am_amrescan 16
103-
#define Anum_pg_am_amendscan 17
104-
#define Anum_pg_am_ammarkpos 18
105-
#define Anum_pg_am_amrestrpos 19
106-
#define Anum_pg_am_ambuild 20
107-
#define Anum_pg_am_ambulkdelete 21
108-
#define Anum_pg_am_amvacuumcleanup 22
109-
#define Anum_pg_am_amcostestimate 23
110-
#define Anum_pg_am_amoptions 24
85+
#define Anum_pg_am_amcanorder 4
86+
#define Anum_pg_am_amcanunique 5
87+
#define Anum_pg_am_amcanmulticol 6
88+
#define Anum_pg_am_amoptionalkey 7
89+
#define Anum_pg_am_amindexnulls 8
90+
#define Anum_pg_am_amstorage 9
91+
#define Anum_pg_am_amclusterable 10
92+
#define Anum_pg_am_aminsert 11
93+
#define Anum_pg_am_ambeginscan 12
94+
#define Anum_pg_am_amgettuple 13
95+
#define Anum_pg_am_amgetmulti 14
96+
#define Anum_pg_am_amrescan 15
97+
#define Anum_pg_am_amendscan 16
98+
#define Anum_pg_am_ammarkpos 17
99+
#define Anum_pg_am_amrestrpos 18
100+
#define Anum_pg_am_ambuild 19
101+
#define Anum_pg_am_ambulkdelete 20
102+
#define Anum_pg_am_amvacuumcleanup 21
103+
#define Anum_pg_am_amcostestimate 22
104+
#define Anum_pg_am_amoptions 23
111105

112106
/* ----------------
113107
* initial contents of pg_am
114108
* ----------------
115109
*/
116110

117-
DATA(insert OID = 403 ( btree 5 1 1 5 t t t t f t btinsert btbeginscan btgettuple btgetmulti btrescan btendscan btmarkpos btrestrpos btbuild btbulkdelete btvacuumcleanup btcostestimate btoptions ));
111+
DATA(insert OID = 403 ( btree 5 1 t t t t t f t btinsert btbeginscan btgettuple btgetmulti btrescan btendscan btmarkpos btrestrpos btbuild btbulkdelete btvacuumcleanup btcostestimate btoptions ));
118112
DESCR("b-tree index access method");
119113
#define BTREE_AM_OID 403
120-
DATA(insert OID = 405 ( hash 1 1 0 0 f f f f f f hashinsert hashbeginscan hashgettuple hashgetmulti hashrescan hashendscan hashmarkpos hashrestrpos hashbuild hashbulkdelete hashvacuumcleanup hashcostestimate hashoptions ));
114+
DATA(insert OID = 405 ( hash 1 1 f f f f f f f hashinsert hashbeginscan hashgettuple hashgetmulti hashrescan hashendscan hashmarkpos hashrestrpos hashbuild hashbulkdelete hashvacuumcleanup hashcostestimate hashoptions ));
121115
DESCR("hash index access method");
122116
#define HASH_AM_OID 405
123-
DATA(insert OID = 783 ( gist 0 7 0 0 f t t t t t gistinsert gistbeginscan gistgettuple gistgetmulti gistrescan gistendscan gistmarkpos gistrestrpos gistbuild gistbulkdelete gistvacuumcleanup gistcostestimate gistoptions ));
117+
DATA(insert OID = 783 ( gist 0 7 f f t t t t t gistinsert gistbeginscan gistgettuple gistgetmulti gistrescan gistendscan gistmarkpos gistrestrpos gistbuild gistbulkdelete gistvacuumcleanup gistcostestimate gistoptions ));
124118
DESCR("GiST index access method");
125119
#define GIST_AM_OID 783
126-
DATA(insert OID = 2742 ( gin 0 4 0 0 f f f f t f gininsert ginbeginscan gingettuple gingetmulti ginrescan ginendscan ginmarkpos ginrestrpos ginbuild ginbulkdelete ginvacuumcleanup gincostestimate ginoptions ));
120+
DATA(insert OID = 2742 ( gin 0 4 f f f f f t f gininsert ginbeginscan gingettuple gingetmulti ginrescan ginendscan ginmarkpos ginrestrpos ginbuild ginbulkdelete ginvacuumcleanup gincostestimate ginoptions ));
127121
DESCR("GIN index access method");
128122
#define GIN_AM_OID 2742
129123

0 commit comments

Comments
 (0)