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

Commit3695a55

Browse files
committed
Replace simple constant pg_am.amcanreturn with an AM support function.
The need for this was debated when we put in the index-only-scan feature,but at the time we had no near-term expectation of having AMs that couldsupport such scans for only some indexes; so we kept it simple. However,the SP-GiST AM forces the issue, so let's fix it.This patch only installs the new API; no behavior actually changes.
1 parent19d2231 commit3695a55

File tree

15 files changed

+103
-46
lines changed

15 files changed

+103
-46
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,6 @@
481481
<entry>Does the access method support multicolumn indexes?</entry>
482482
</row>
483483

484-
<row>
485-
<entry><structfield>amcanreturn</structfield></entry>
486-
<entry><type>bool</type></entry>
487-
<entry></entry>
488-
<entry>Can the access method return the contents of index entries?</entry>
489-
</row>
490-
491484
<row>
492485
<entry><structfield>amoptionalkey</structfield></entry>
493486
<entry><type>bool</type></entry>
@@ -622,6 +615,14 @@
622615
<entry>Post-<command>VACUUM</command> cleanup function</entry>
623616
</row>
624617

618+
<row>
619+
<entry><structfield>amcanreturn</structfield></entry>
620+
<entry><type>regproc</type></entry>
621+
<entry><literal><link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.oid</literal></entry>
622+
<entry>Function to check whether index supports index-only scans,
623+
or zero if none</entry>
624+
</row>
625+
625626
<row>
626627
<entry><structfield>amcostestimate</structfield></entry>
627628
<entry><type>regproc</type></entry>

‎doc/src/sgml/indexam.sgml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@
134134
<structfield>amsearchnulls</structfield>, indicating that it supports
135135
<literal>IS NULL</> and <literal>IS NOT NULL</> clauses as search
136136
conditions.
137-
An index method can also set <structfield>amcanreturn</structfield>,
138-
indicating that it can support <firstterm>index-only scans</> by returning
139-
the indexed column values for an index entry in the form of an IndexTuple.
140-
(An example of an index AM that cannot do this is hash, which stores only
141-
the hash values not the original data.)
142137
</para>
143138

144139
</sect1>
@@ -278,6 +273,19 @@ amvacuumcleanup (IndexVacuumInfo *info,
278273

279274
<para>
280275
<programlisting>
276+
bool
277+
amcanreturn (Relation indexRelation);
278+
</programlisting>
279+
Check whether the index can support <firstterm>index-only scans</> by
280+
returning the indexed column values for an index entry in the form of an
281+
IndexTuple. Return TRUE if so, else FALSE. If the index AM can never
282+
support index-only scans (an example is hash, which stores only
283+
the hash values not the original data), it is sufficient to set its
284+
<structfield>amcanreturn</> field to zero in <structname>pg_am</>.
285+
</para>
286+
287+
<para>
288+
<programlisting>
281289
void
282290
amcostestimate (PlannerInfo *root,
283291
IndexOptInfo *index,
@@ -391,9 +399,9 @@ amgettuple (IndexScanDesc scan,
391399
</para>
392400

393401
<para>
394-
If theaccess method supports index-only scans (i.e.,
395-
<structfield>amcanreturn</structfield> is TRUEin its <structname>pg_am</>
396-
row),then on successit must also check
402+
If theindex supports index-only scans (i.e.,
403+
<function>amcanreturn</function> returns TRUEfor it),
404+
then on successthe AM must also check
397405
<literal>scan-&gt;xs_want_itup</>, and if that is true it must return
398406
the original indexed data for the index entry, in the form of an
399407
<structname>IndexTuple</> pointer stored at <literal>scan-&gt;xs_itup</>,

‎src/backend/access/index/indexam.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*index_getbitmap - get all tuples from a scan
2727
*index_bulk_delete- bulk deletion of index tuples
2828
*index_vacuum_cleanup- post-deletion cleanup of an index
29+
*index_can_return- does index support index-only scans?
2930
*index_getprocid - get a support procedure OID
3031
*index_getprocinfo - get a support procedure's lookup info
3132
*
@@ -711,6 +712,27 @@ index_vacuum_cleanup(IndexVacuumInfo *info,
711712
returnresult;
712713
}
713714

715+
/* ----------------
716+
*index_can_return - does index support index-only scans?
717+
* ----------------
718+
*/
719+
bool
720+
index_can_return(RelationindexRelation)
721+
{
722+
FmgrInfo*procedure;
723+
724+
RELATION_CHECKS;
725+
726+
/* amcanreturn is optional; assume FALSE if not provided by AM */
727+
if (!RegProcedureIsValid(indexRelation->rd_am->amcanreturn))
728+
return false;
729+
730+
GET_REL_PROCEDURE(amcanreturn);
731+
732+
returnDatumGetBool(FunctionCall1(procedure,
733+
PointerGetDatum(indexRelation)));
734+
}
735+
714736
/* ----------------
715737
*index_getprocid
716738
*

‎src/backend/access/nbtree/nbtree.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,3 +1091,14 @@ btvacuumpage(BTVacState *vstate, BlockNumber blkno, BlockNumber orig_blkno)
10911091
gotorestart;
10921092
}
10931093
}
1094+
1095+
/*
1096+
*btcanreturn() -- Check whether btree indexes support index-only scans.
1097+
*
1098+
* btrees always do, so this is trivial.
1099+
*/
1100+
Datum
1101+
btcanreturn(PG_FUNCTION_ARGS)
1102+
{
1103+
PG_RETURN_BOOL(true);
1104+
}

‎src/backend/access/spgist/spgscan.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,10 @@ spggettuple(PG_FUNCTION_ARGS)
559559

560560
PG_RETURN_BOOL(false);
561561
}
562+
563+
Datum
564+
spgcanreturn(PG_FUNCTION_ARGS)
565+
{
566+
/* Not implemented yet */
567+
PG_RETURN_BOOL(false);
568+
}

‎src/backend/optimizer/path/indxpath.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,10 +1075,10 @@ check_index_only(RelOptInfo *rel, IndexOptInfo *index)
10751075
ListCell*lc;
10761076
inti;
10771077

1078-
/* Index-only scans must be enabled, andAM must be capable ofit */
1078+
/* Index-only scans must be enabled, andindex must be capable ofthem */
10791079
if (!enable_indexonlyscan)
10801080
return false;
1081-
if (!index->amcanreturn)
1081+
if (!index->canreturn)
10821082
return false;
10831083

10841084
/*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
212212

213213
info->relam=indexRelation->rd_rel->relam;
214214
info->amcostestimate=indexRelation->rd_am->amcostestimate;
215+
info->canreturn=index_can_return(indexRelation);
215216
info->amcanorderbyop=indexRelation->rd_am->amcanorderbyop;
216-
info->amcanreturn=indexRelation->rd_am->amcanreturn;
217217
info->amoptionalkey=indexRelation->rd_am->amoptionalkey;
218218
info->amsearcharray=indexRelation->rd_am->amsearcharray;
219219
info->amsearchnulls=indexRelation->rd_am->amsearchnulls;

‎src/include/access/genam.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ extern IndexBulkDeleteResult *index_bulk_delete(IndexVacuumInfo *info,
156156
void*callback_state);
157157
externIndexBulkDeleteResult*index_vacuum_cleanup(IndexVacuumInfo*info,
158158
IndexBulkDeleteResult*stats);
159+
externboolindex_can_return(RelationindexRelation);
159160
externRegProcedureindex_getprocid(Relationirel,AttrNumberattnum,
160161
uint16procnum);
161162
externFmgrInfo*index_getprocinfo(Relationirel,AttrNumberattnum,

‎src/include/access/nbtree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ extern Datum btmarkpos(PG_FUNCTION_ARGS);
607607
externDatumbtrestrpos(PG_FUNCTION_ARGS);
608608
externDatumbtbulkdelete(PG_FUNCTION_ARGS);
609609
externDatumbtvacuumcleanup(PG_FUNCTION_ARGS);
610+
externDatumbtcanreturn(PG_FUNCTION_ARGS);
610611
externDatumbtoptions(PG_FUNCTION_ARGS);
611612

612613
/*

‎src/include/access/spgist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ extern Datum spgmarkpos(PG_FUNCTION_ARGS);
182182
externDatumspgrestrpos(PG_FUNCTION_ARGS);
183183
externDatumspggetbitmap(PG_FUNCTION_ARGS);
184184
externDatumspggettuple(PG_FUNCTION_ARGS);
185+
externDatumspgcanreturn(PG_FUNCTION_ARGS);
185186

186187
/* spgutils.c */
187188
externDatumspgoptions(PG_FUNCTION_ARGS);

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201112172
56+
#defineCATALOG_VERSION_NO201112181
5757

5858
#endif

‎src/include/catalog/pg_am.h

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ CATALOG(pg_am,2601)
4545
boolamcanbackward;/* does AM support backward scan? */
4646
boolamcanunique;/* does AM support UNIQUE indexes? */
4747
boolamcanmulticol;/* does AM support multi-column indexes? */
48-
boolamcanreturn;/* can AM return IndexTuples? */
4948
boolamoptionalkey;/* can query omit key for the first column? */
5049
boolamsearcharray;/* can AM handle ScalarArrayOpExpr quals? */
5150
boolamsearchnulls;/* can AM search for NULL/NOT NULL entries? */
@@ -65,6 +64,7 @@ CATALOG(pg_am,2601)
6564
regprocambuildempty;/* "build empty index" function */
6665
regprocambulkdelete;/* bulk-delete function */
6766
regprocamvacuumcleanup;/* post-VACUUM cleanup function */
67+
regprocamcanreturn;/* can indexscan return IndexTuples? */
6868
regprocamcostestimate;/* estimate cost of an indexscan */
6969
regprocamoptions;/* parse AM-specific parameters */
7070
}FormData_pg_am;
@@ -89,26 +89,26 @@ typedef FormData_pg_am *Form_pg_am;
8989
#defineAnum_pg_am_amcanbackward6
9090
#defineAnum_pg_am_amcanunique7
9191
#defineAnum_pg_am_amcanmulticol8
92-
#defineAnum_pg_am_amcanreturn9
93-
#defineAnum_pg_am_amoptionalkey10
94-
#defineAnum_pg_am_amsearcharray11
95-
#defineAnum_pg_am_amsearchnulls12
96-
#defineAnum_pg_am_amstorage13
97-
#defineAnum_pg_am_amclusterable14
98-
#defineAnum_pg_am_ampredlocks15
99-
#defineAnum_pg_am_amkeytype16
100-
#defineAnum_pg_am_aminsert17
101-
#defineAnum_pg_am_ambeginscan18
102-
#defineAnum_pg_am_amgettuple19
103-
#defineAnum_pg_am_amgetbitmap20
104-
#defineAnum_pg_am_amrescan21
105-
#defineAnum_pg_am_amendscan22
106-
#defineAnum_pg_am_ammarkpos23
107-
#defineAnum_pg_am_amrestrpos24
108-
#defineAnum_pg_am_ambuild25
109-
#defineAnum_pg_am_ambuildempty26
110-
#defineAnum_pg_am_ambulkdelete27
111-
#defineAnum_pg_am_amvacuumcleanup28
92+
#defineAnum_pg_am_amoptionalkey9
93+
#defineAnum_pg_am_amsearcharray10
94+
#defineAnum_pg_am_amsearchnulls11
95+
#defineAnum_pg_am_amstorage12
96+
#defineAnum_pg_am_amclusterable13
97+
#defineAnum_pg_am_ampredlocks14
98+
#defineAnum_pg_am_amkeytype15
99+
#defineAnum_pg_am_aminsert16
100+
#defineAnum_pg_am_ambeginscan17
101+
#defineAnum_pg_am_amgettuple18
102+
#defineAnum_pg_am_amgetbitmap19
103+
#defineAnum_pg_am_amrescan20
104+
#defineAnum_pg_am_amendscan21
105+
#defineAnum_pg_am_ammarkpos22
106+
#defineAnum_pg_am_amrestrpos23
107+
#defineAnum_pg_am_ambuild24
108+
#defineAnum_pg_am_ambuildempty25
109+
#defineAnum_pg_am_ambulkdelete26
110+
#defineAnum_pg_am_amvacuumcleanup27
111+
#defineAnum_pg_am_amcanreturn28
112112
#defineAnum_pg_am_amcostestimate29
113113
#defineAnum_pg_am_amoptions30
114114

@@ -117,19 +117,19 @@ typedef FormData_pg_am *Form_pg_am;
117117
* ----------------
118118
*/
119119

120-
DATA(insertOID=403 (btree52tftttttttftt0btinsertbtbeginscanbtgettuplebtgetbitmapbtrescanbtendscanbtmarkposbtrestrposbtbuildbtbuildemptybtbulkdeletebtvacuumcleanupbtcostestimatebtoptions ));
120+
DATA(insertOID=403 (btree52tfttttttftt0btinsertbtbeginscanbtgettuplebtgetbitmapbtrescanbtendscanbtmarkposbtrestrposbtbuildbtbuildemptybtbulkdeletebtvacuumcleanupbtcanreturnbtcostestimatebtoptions ));
121121
DESCR("b-tree index access method");
122122
#defineBTREE_AM_OID 403
123-
DATA(insertOID=405 (hash11fftfffffffff23hashinserthashbeginscanhashgettuplehashgetbitmaphashrescanhashendscanhashmarkposhashrestrposhashbuildhashbuildemptyhashbulkdeletehashvacuumcleanuphashcostestimatehashoptions ));
123+
DATA(insertOID=405 (hash11fftffffffff23hashinserthashbeginscanhashgettuplehashgetbitmaphashrescanhashendscanhashmarkposhashrestrposhashbuildhashbuildemptyhashbulkdeletehashvacuumcleanup-hashcostestimatehashoptions ));
124124
DESCR("hash index access method");
125125
#defineHASH_AM_OID 405
126-
DATA(insertOID=783 (gist08ftfftftftttf0gistinsertgistbeginscangistgettuplegistgetbitmapgistrescangistendscangistmarkposgistrestrposgistbuildgistbuildemptygistbulkdeletegistvacuumcleanupgistcostestimategistoptions ));
126+
DATA(insertOID=783 (gist08ftffttftttf0gistinsertgistbeginscangistgettuplegistgetbitmapgistrescangistendscangistmarkposgistrestrposgistbuildgistbuildemptygistbulkdeletegistvacuumcleanup-gistcostestimategistoptions ));
127127
DESCR("GiST index access method");
128128
#defineGIST_AM_OID 783
129-
DATA(insertOID=2742 (gin05fffftftfftff0gininsertginbeginscan-gingetbitmapginrescanginendscanginmarkposginrestrposginbuildginbuildemptyginbulkdeleteginvacuumcleanupgincostestimateginoptions ));
129+
DATA(insertOID=2742 (gin05ffffttfftff0gininsertginbeginscan-gingetbitmapginrescanginendscanginmarkposginrestrposginbuildginbuildemptyginbulkdeleteginvacuumcleanup-gincostestimateginoptions ));
130130
DESCR("GIN index access method");
131131
#defineGIN_AM_OID 2742
132-
DATA(insertOID=4000 (spgist05ffffffffffff0spginsertspgbeginscanspggettuplespggetbitmapspgrescanspgendscanspgmarkposspgrestrposspgbuildspgbuildemptyspgbulkdeletespgvacuumcleanupspgcostestimatespgoptions ));
132+
DATA(insertOID=4000 (spgist05fffffffffff0spginsertspgbeginscanspggettuplespggetbitmapspgrescanspgendscanspgmarkposspgrestrposspgbuildspgbuildemptyspgbulkdeletespgvacuumcleanupspgcanreturnspgcostestimatespgoptions ));
133133
DESCR("SP-GiST index access method");
134134
#defineSPGIST_AM_OID 4000
135135

‎src/include/catalog/pg_proc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ DATA(insert OID = 332 ( btbulkdelete PGNSP PGUID 12 1 0 0 0 f f f t f v 4 0
546546
DESCR("btree(internal)");
547547
DATA(insertOID=972 (btvacuumcleanupPGNSPPGUID121000ffftfv202281"2281 2281"_null__null__null__null_btvacuumcleanup_null__null__null_ ));
548548
DESCR("btree(internal)");
549+
DATA(insertOID=276 (btcanreturnPGNSPPGUID121000ffftfs1016"2281"_null__null__null__null_btcanreturn_null__null__null_ ));
550+
DESCR("btree(internal)");
549551
DATA(insertOID=1268 (btcostestimatePGNSPPGUID121000ffftfv902278"2281 2281 2281 2281 2281 2281 2281 2281 2281"_null__null__null__null_btcostestimate_null__null__null_ ));
550552
DESCR("btree(internal)");
551553
DATA(insertOID=2785 (btoptionsPGNSPPGUID121000ffftfs2017"1009 16"_null__null__null__null_btoptions_null__null__null_ ));
@@ -4506,6 +4508,8 @@ DATA(insert OID = 4011 ( spgbulkdelete PGNSP PGUID 12 1 0 0 0 f f f t f v 4
45064508
DESCR("spgist(internal)");
45074509
DATA(insertOID=4012 (spgvacuumcleanupPGNSPPGUID121000ffftfv202281"2281 2281"_null__null__null__null_spgvacuumcleanup_null__null__null_ ));
45084510
DESCR("spgist(internal)");
4511+
DATA(insertOID=4032 (spgcanreturnPGNSPPGUID121000ffftfs1016"2281"_null__null__null__null_spgcanreturn_null__null__null_ ));
4512+
DESCR("spgist(internal)");
45094513
DATA(insertOID=4013 (spgcostestimatePGNSPPGUID121000ffftfv902278"2281 2281 2281 2281 2281 2281 2281 2281 2281"_null__null__null__null_spgcostestimate_null__null__null_ ));
45104514
DESCR("spgist(internal)");
45114515
DATA(insertOID=4014 (spgoptionsPGNSPPGUID121000ffftfs2017"1009 16"_null__null__null__null_spgoptions_null__null__null_ ));

‎src/include/nodes/relation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ typedef struct IndexOptInfo
490490
boolunique;/* true if a unique index */
491491
boolimmediate;/* is uniqueness enforced immediately? */
492492
boolhypothetical;/* true if index doesn't really exist */
493+
boolcanreturn;/* can index return IndexTuples? */
493494
boolamcanorderbyop;/* does AM support order by operator result? */
494-
boolamcanreturn;/* can AM return IndexTuples? */
495495
boolamoptionalkey;/* can query omit key for the first column? */
496496
boolamsearcharray;/* can AM handle ScalarArrayOpExpr quals? */
497497
boolamsearchnulls;/* can AM search for NULL/NOT NULL entries? */

‎src/include/utils/rel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ typedef struct RelationAmInfo
6464
FmgrInfoambuildempty;
6565
FmgrInfoambulkdelete;
6666
FmgrInfoamvacuumcleanup;
67+
FmgrInfoamcanreturn;
6768
FmgrInfoamcostestimate;
6869
FmgrInfoamoptions;
6970
}RelationAmInfo;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp