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

Commit 4ac8ee9

Browse files
committed
Fix fuzzy thinking about amcanmulticol versus amcaninclude.
These flags should be independent: in particular an index AM should be able to say that it supports include columns without necessarily supporting multiple key columns. The included-columns patch got this wrong, possibly aided by the fact that it didn't bother to update the documentation. While here, clarify some text about amcanreturn, which was a little vague about what should happen when amcanreturn reports that only some of the index columns are returnable. Noted while reviewing the SP-GiST included-columns patch, which quite incorrectly (and unsafely) changed SP-GiST to claim amcanmulticol = true as a workaround for this bug. Backpatch to v11 where included columns were introduced.
1 parent 2b77595 commit 4ac8ee9

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

doc/src/sgml/indexam.sgml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ typedef struct IndexAmRoutine
190190
implications. The requirements of <structfield>amcanunique</structfield>
191191
are discussed in <xref linkend="index-unique-checks"/>.
192192
The <structfield>amcanmulticol</structfield> flag asserts that the
193-
access method supports multicolumn indexes, while
193+
access method supports multi-key-column indexes, while
194194
<structfield>amoptionalkey</structfield> asserts that it allows scans
195195
where no indexable restriction clause is given for the first index column.
196196
When <structfield>amcanmulticol</structfield> is false,
@@ -226,6 +226,19 @@ typedef struct IndexAmRoutine
226226
conditions.
227227
</para>
228228

229+
<para>
230+
The <structfield>amcaninclude</structfield> flag indicates whether the
231+
access method supports <quote>included</quote> columns, that is it can
232+
store (without processing) additional columns beyond the key column(s).
233+
The requirements of the preceding paragraph apply only to the key
234+
columns. In particular, the combination
235+
of <structfield>amcanmulticol</structfield>=<literal>false</literal>
236+
and <structfield>amcaninclude</structfield>=<literal>true</literal> is
237+
sensible: it means that there can only be one key column, but there can
238+
also be included column(s). Also, included columns must be allowed to be
239+
null, independently of <structfield>amoptionalkey</structfield>.
240+
</para>
241+
229242
</sect1>
230243

231244
<sect1 id="index-functions">
@@ -377,10 +390,13 @@ amcanreturn (Relation indexRelation, int attno);
377390
</programlisting>
378391
Check whether the index can support <link
379392
linkend="indexes-index-only-scans"><firstterm>index-only scans</firstterm></link> on
380-
the given column, by returning the indexed column values for an index entry
381-
in the form of an <structname>IndexTuple</structname>. The attribute number
382-
is 1-based, i.e., the first column's attno is 1. Returns true if supported,
383-
else false. If the access method does not support index-only scans at all,
393+
the given column, by returning the column's original indexed value.
394+
The attribute number is 1-based, i.e., the first column's attno is 1.
395+
Returns true if supported, else false.
396+
This function should always return true for included columns
397+
(if those are supported), since there's little point in an included
398+
column that can't be retrieved.
399+
If the access method does not support index-only scans at all,
384400
the <structfield>amcanreturn</structfield> field in its <structname>IndexAmRoutine</structname>
385401
struct can be set to NULL.
386402
</para>
@@ -470,7 +486,7 @@ amproperty (Oid index_oid, int attno,
470486
core code does not know how to do that and will return NULL. It may
471487
also be advantageous to implement <literal>AMPROP_RETURNABLE</literal> testing,
472488
if that can be done more cheaply than by opening the index and calling
473-
<structfield>amcanreturn</structfield>, which is the core code's default behavior.
489+
<function>amcanreturn</function>, which is the core code's default behavior.
474490
The default behavior should be satisfactory for all other standard
475491
properties.
476492
</para>
@@ -574,10 +590,13 @@ amgettuple (IndexScanDesc scan,
574590

575591
<para>
576592
If the index supports <link linkend="indexes-index-only-scans">index-only
577-
scans</link> (i.e., <function>amcanreturn</function> returns true for it),
593+
scans</link> (i.e., <function>amcanreturn</function> returns true for any
594+
of its columns),
578595
then on success the AM must also check <literal>scan-&gt;xs_want_itup</literal>,
579596
and if that is true it must return the originally indexed data for the
580-
index entry. The data can be returned in the form of an
597+
index entry. Columns for which <function>amcanreturn</function> returns
598+
false can be returned as nulls.
599+
The data can be returned in the form of an
581600
<structname>IndexTuple</structname> pointer stored at <literal>scan-&gt;xs_itup</literal>,
582601
with tuple descriptor <literal>scan-&gt;xs_itupdesc</literal>; or in the form of
583602
a <structname>HeapTuple</structname> pointer stored at <literal>scan-&gt;xs_hitup</literal>,

src/backend/commands/indexcmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ DefineIndex(Oid relationId,
535535
list_copy(stmt->indexIncludingParams));
536536
numberOfAttributes = list_length(allIndexParams);
537537

538-
if (numberOfAttributes <= 0)
538+
if (numberOfKeyAttributes <= 0)
539539
ereport(ERROR,
540540
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
541541
errmsg("must specify at least one column")));
@@ -758,7 +758,7 @@ DefineIndex(Oid relationId,
758758
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
759759
errmsg("access method \"%s\" does not support included columns",
760760
accessMethodName)));
761-
if (numberOfAttributes > 1 && !amRoutine->amcanmulticol)
761+
if (numberOfKeyAttributes > 1 && !amRoutine->amcanmulticol)
762762
ereport(ERROR,
763763
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
764764
errmsg("access method \"%s\" does not support multicolumn indexes",

0 commit comments

Comments
 (0)