Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit93b4f0f

Browse files
committed
Set pg_am.amstrategies to zero for index AMs that don't have fixed
operator strategy numbers, ie, GiST and GIN. This is almost cosmeticenough to not need a catversion bump, but since the opr_sanity regressiontest has to change in sync with the catalog entry, I figured I'd betterdo one.
1 parent6b4fe04 commit93b4f0f

File tree

7 files changed

+41
-27
lines changed

7 files changed

+41
-27
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.137 2006/11/12 06:25:37 neilc Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.138 2006/12/18 18:56:28 tgl Exp $ -->
22
<!--
33
Documentation of the system catalogs, directed toward PostgreSQL developers
44
-->
@@ -347,7 +347,9 @@
347347
<entry><structfield>amstrategies</structfield></entry>
348348
<entry><type>int2</type></entry>
349349
<entry></entry>
350-
<entry>Number of operator strategies for this access method</entry>
350+
<entry>Number of operator strategies for this access method,
351+
or zero if access method does not have a fixed set of operator
352+
strategies</entry>
351353
</row>
352354

353355
<row>

‎src/backend/commands/opclasscmds.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.49 2006/10/04 00:29:51 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.50 2006/12/18 18:56:28 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
1616
#include"postgres.h"
1717

18+
#include<limits.h>
19+
1820
#include"access/genam.h"
1921
#include"access/heapam.h"
2022
#include"catalog/dependency.h"
@@ -73,8 +75,8 @@ DefineOpClass(CreateOpClassStmt *stmt)
7375
storageoid,/* storage datatype oid, if any */
7476
namespaceoid,/* namespace to create opclass in */
7577
opclassoid;/* oid of opclass we create */
76-
intnumOperators,/* amstrategies value */
77-
numProcs;/* amsupport value */
78+
intmaxOpNumber,/* amstrategies value */
79+
maxProcNumber;/* amsupport value */
7880
boolamstorage;/* amstorage flag */
7981
List*operators;/* OpClassMember list for operators */
8082
List*procedures;/* OpClassMember list for support procs */
@@ -112,8 +114,11 @@ DefineOpClass(CreateOpClassStmt *stmt)
112114

113115
amoid=HeapTupleGetOid(tup);
114116
pg_am= (Form_pg_am)GETSTRUCT(tup);
115-
numOperators=pg_am->amstrategies;
116-
numProcs=pg_am->amsupport;
117+
maxOpNumber=pg_am->amstrategies;
118+
/* if amstrategies is zero, just enforce that op numbers fit in int16 */
119+
if (maxOpNumber <=0)
120+
maxOpNumber=SHRT_MAX;
121+
maxProcNumber=pg_am->amsupport;
117122
amstorage=pg_am->amstorage;
118123

119124
/* XXX Should we make any privilege check against the AM? */
@@ -176,12 +181,12 @@ DefineOpClass(CreateOpClassStmt *stmt)
176181
switch (item->itemtype)
177182
{
178183
caseOPCLASS_ITEM_OPERATOR:
179-
if (item->number <=0||item->number>numOperators)
184+
if (item->number <=0||item->number>maxOpNumber)
180185
ereport(ERROR,
181186
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
182187
errmsg("invalid operator number %d,"
183188
" must be between 1 and %d",
184-
item->number,numOperators)));
189+
item->number,maxOpNumber)));
185190
if (item->args!=NIL)
186191
{
187192
TypeName*typeName1= (TypeName*)linitial(item->args);
@@ -220,12 +225,12 @@ DefineOpClass(CreateOpClassStmt *stmt)
220225
addClassMember(&operators,member, false);
221226
break;
222227
caseOPCLASS_ITEM_FUNCTION:
223-
if (item->number <=0||item->number>numProcs)
228+
if (item->number <=0||item->number>maxProcNumber)
224229
ereport(ERROR,
225230
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
226231
errmsg("invalid procedure number %d,"
227232
" must be between 1 and %d",
228-
item->number,numProcs)));
233+
item->number,maxProcNumber)));
229234
funcOid=LookupFuncNameTypeNames(item->name,item->args,
230235
false);
231236
#ifdefNOT_USED

‎src/backend/optimizer/util/plancat.c

Lines changed: 9 additions & 2 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.127 2006/10/04 00:29:55 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.128 2006/12/18 18:56:28 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -190,10 +190,17 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
190190
* Fetch the ordering operators associated with the index, if any.
191191
*/
192192
amorderstrategy=indexRelation->rd_am->amorderstrategy;
193-
if (amorderstrategy!=0)
193+
if (amorderstrategy>0)
194194
{
195195
intoprindex=amorderstrategy-1;
196196

197+
/*
198+
* Index AM must have a fixed set of strategies for it to
199+
* make sense to specify amorderstrategy, so we need not
200+
* allow the case amstrategies == 0.
201+
*/
202+
Assert(oprindex<indexRelation->rd_am->amstrategies);
203+
197204
for (i=0;i<ncolumns;i++)
198205
{
199206
info->ordering[i]=indexRelation->rd_operator[oprindex];

‎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-2006, 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.362 2006/12/10 22:13:26 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.363 2006/12/18 18:56:28 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200612101
56+
#defineCATALOG_VERSION_NO200612181
5757

5858
#endif

‎src/include/catalog/pg_am.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2006, 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.46 2006/07/31 20:09:05 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_am.h,v 1.47 2006/12/18 18:56:29 tgl Exp $
1212
*
1313
* NOTES
1414
*the genbki.sh script reads this file and generates .bki
@@ -40,7 +40,9 @@ CATALOG(pg_am,2601)
4040
{
4141
NameDataamname;/* access method name */
4242
int2amstrategies;/* total NUMBER of strategies (operators) by
43-
* which we can traverse/search this AM */
43+
* which we can traverse/search this AM.
44+
* Zero if AM does not have a fixed set of
45+
* strategy assignments. */
4446
int2amsupport;/* total NUMBER of support functions that this
4547
* AM uses */
4648
int2amorderstrategy;/* if this AM has a sort order, the strategy
@@ -114,10 +116,10 @@ DESCR("b-tree index access method");
114116
DATA(insertOID=405 (hash110ffffffhashinserthashbeginscanhashgettuplehashgetmultihashrescanhashendscanhashmarkposhashrestrposhashbuildhashbulkdeletehashvacuumcleanuphashcostestimatehashoptions ));
115117
DESCR("hash index access method");
116118
#defineHASH_AM_OID 405
117-
DATA(insertOID=783 (gist10070ftttttgistinsertgistbeginscangistgettuplegistgetmultigistrescangistendscangistmarkposgistrestrposgistbuildgistbulkdeletegistvacuumcleanupgistcostestimategistoptions ));
119+
DATA(insertOID=783 (gist070ftttttgistinsertgistbeginscangistgettuplegistgetmultigistrescangistendscangistmarkposgistrestrposgistbuildgistbulkdeletegistvacuumcleanupgistcostestimategistoptions ));
118120
DESCR("GiST index access method");
119121
#defineGIST_AM_OID 783
120-
DATA(insertOID=2742 (gin10040fffftfgininsertginbeginscangingettuplegingetmultiginrescanginendscanginmarkposginrestrposginbuildginbulkdeleteginvacuumcleanupgincostestimateginoptions ));
122+
DATA(insertOID=2742 (gin040fffftfgininsertginbeginscangingettuplegingetmultiginrescanginendscanginmarkposginrestrposginbuildginbulkdeleteginvacuumcleanupgincostestimateginoptions ));
121123
DESCR("GIN index access method");
122124
#defineGIN_AM_OID 2742
123125

‎src/test/regress/expected/opr_sanity.out

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,20 +773,19 @@ WHERE p1.amopclaid = 0 OR p1.amopstrategy <= 0 OR p1.amopopr = 0;
773773
SELECT p1.amopclaid, p1.amopopr, p2.oid, p2.amname
774774
FROM pg_amop AS p1, pg_am AS p2, pg_opclass AS p3
775775
WHERE p1.amopclaid = p3.oid AND p3.opcamid = p2.oid AND
776-
p1.amopstrategy > p2.amstrategies;
776+
p1.amopstrategy > p2.amstrategies AND p2.amstrategies <> 0;
777777
amopclaid | amopopr | oid | amname
778778
-----------+---------+-----+--------
779779
(0 rows)
780780

781781
-- Detect missing pg_amop entries: should have as many strategy operators
782782
-- as AM expects for each opclass for the AM. When nondefault subtypes are
783783
-- present, enforce condition separately for each subtype.
784-
-- We have to exclude GiST and GIN, unfortunately, since they haven't got
785-
-- any fixed requirements about strategy operators.
784+
-- We can't check this for AMs with variable strategy sets.
786785
SELECT p1.oid, p1.amname, p2.oid, p2.opcname, p3.amopsubtype
787786
FROM pg_am AS p1, pg_opclass AS p2, pg_amop AS p3
788787
WHERE p2.opcamid = p1.oid AND p3.amopclaid = p2.oid AND
789-
p1.amname != 'gist' AND p1.amname != 'gin' AND
788+
p1.amstrategies <> 0 AND
790789
p1.amstrategies != (SELECT count(*) FROM pg_amop AS p4
791790
WHERE p4.amopclaid = p2.oid AND
792791
p4.amopsubtype = p3.amopsubtype);

‎src/test/regress/sql/opr_sanity.sql

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,18 +642,17 @@ WHERE p1.amopclaid = 0 OR p1.amopstrategy <= 0 OR p1.amopopr = 0;
642642
SELECTp1.amopclaid,p1.amopopr,p2.oid,p2.amname
643643
FROM pg_amopAS p1, pg_amAS p2, pg_opclassAS p3
644644
WHEREp1.amopclaid=p3.oidANDp3.opcamid=p2.oidAND
645-
p1.amopstrategy>p2.amstrategies;
645+
p1.amopstrategy>p2.amstrategiesANDp2.amstrategies<>0;
646646

647647
-- Detect missing pg_amop entries: should have as many strategy operators
648648
-- as AM expects for each opclass for the AM. When nondefault subtypes are
649649
-- present, enforce condition separately for each subtype.
650-
-- We have to exclude GiST and GIN, unfortunately, since they haven't got
651-
-- any fixed requirements about strategy operators.
650+
-- We can't check this for AMs with variable strategy sets.
652651

653652
SELECTp1.oid,p1.amname,p2.oid,p2.opcname,p3.amopsubtype
654653
FROM pg_amAS p1, pg_opclassAS p2, pg_amopAS p3
655654
WHEREp2.opcamid=p1.oidANDp3.amopclaid=p2.oidAND
656-
p1.amname!='gist'ANDp1.amname!='gin'AND
655+
p1.amstrategies<>0AND
657656
p1.amstrategies!= (SELECTcount(*)FROM pg_amopAS p4
658657
WHEREp4.amopclaid=p2.oidAND
659658
p4.amopsubtype=p3.amopsubtype);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp