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

Commit7c89246

Browse files
committed
Fix fuzzy thinking about amcanmulticol versus amcaninclude.
These flags should be independent: in particular an index AM shouldbe able to say that it supports include columns without necessarilysupporting multiple key columns. The included-columns patch gotthis wrong, possibly aided by the fact that it didn't bother toupdate the documentation.While here, clarify some text about amcanreturn, which was a littlevague about what should happen when amcanreturn reports that onlysome of the index columns are returnable.Noted while reviewing the SP-GiST included-columns patch, whichquite incorrectly (and unsafely) changed SP-GiST to claimamcanmulticol = true as a workaround for this bug.Backpatch to v11 where included columns were introduced.
1 parent0e0e71a commit7c89246

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
@@ -196,7 +196,7 @@ typedef struct IndexAmRoutine
196196
implications. The requirements of <structfield>amcanunique</structfield>
197197
are discussed in <xref linkend="index-unique-checks"/>.
198198
The <structfield>amcanmulticol</structfield> flag asserts that the
199-
access method supportsmulticolumn indexes, while
199+
access method supportsmulti-key-column indexes, while
200200
<structfield>amoptionalkey</structfield> asserts that it allows scans
201201
where no indexable restriction clause is given for the first index column.
202202
When <structfield>amcanmulticol</structfield> is false,
@@ -232,6 +232,19 @@ typedef struct IndexAmRoutine
232232
conditions.
233233
</para>
234234

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

237250
<sect1 id="index-functions">
@@ -383,10 +396,13 @@ amcanreturn (Relation indexRelation, int attno);
383396
</programlisting>
384397
Check whether the index can support <link
385398
linkend="indexes-index-only-scans"><firstterm>index-only scans</firstterm></link> on
386-
the given column, by returning the indexed column values for an index entry
387-
in the form of an <structname>IndexTuple</structname>. The attribute number
388-
is 1-based, i.e., the first column's attno is 1. Returns true if supported,
389-
else false. If the access method does not support index-only scans at all,
399+
the given column, by returning the column's original indexed value.
400+
The attribute number is 1-based, i.e., the first column's attno is 1.
401+
Returns true if supported, else false.
402+
This function should always return true for included columns
403+
(if those are supported), since there's little point in an included
404+
column that can't be retrieved.
405+
If the access method does not support index-only scans at all,
390406
the <structfield>amcanreturn</structfield> field in its <structname>IndexAmRoutine</structname>
391407
struct can be set to NULL.
392408
</para>
@@ -476,7 +492,7 @@ amproperty (Oid index_oid, int attno,
476492
core code does not know how to do that and will return NULL. It may
477493
also be advantageous to implement <literal>AMPROP_RETURNABLE</literal> testing,
478494
if that can be done more cheaply than by opening the index and calling
479-
<structfield>amcanreturn</structfield>, which is the core code's default behavior.
495+
<function>amcanreturn</function>, which is the core code's default behavior.
480496
The default behavior should be satisfactory for all other standard
481497
properties.
482498
</para>
@@ -580,10 +596,13 @@ amgettuple (IndexScanDesc scan,
580596

581597
<para>
582598
If the index supports <link linkend="indexes-index-only-scans">index-only
583-
scans</link> (i.e., <function>amcanreturn</function> returns true for it),
599+
scans</link> (i.e., <function>amcanreturn</function> returns true for any
600+
of its columns),
584601
then on success the AM must also check <literal>scan-&gt;xs_want_itup</literal>,
585602
and if that is true it must return the originally indexed data for the
586-
index entry. The data can be returned in the form of an
603+
index entry. Columns for which <function>amcanreturn</function> returns
604+
false can be returned as nulls.
605+
The data can be returned in the form of an
587606
<structname>IndexTuple</structname> pointer stored at <literal>scan-&gt;xs_itup</literal>,
588607
with tuple descriptor <literal>scan-&gt;xs_itupdesc</literal>; or in the form of
589608
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
@@ -584,7 +584,7 @@ DefineIndex(Oid relationId,
584584
stmt->indexIncludingParams);
585585
numberOfAttributes=list_length(allIndexParams);
586586

587-
if (numberOfAttributes <=0)
587+
if (numberOfKeyAttributes <=0)
588588
ereport(ERROR,
589589
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
590590
errmsg("must specify at least one column")));
@@ -807,7 +807,7 @@ DefineIndex(Oid relationId,
807807
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
808808
errmsg("access method \"%s\" does not support included columns",
809809
accessMethodName)));
810-
if (numberOfAttributes>1&& !amRoutine->amcanmulticol)
810+
if (numberOfKeyAttributes>1&& !amRoutine->amcanmulticol)
811811
ereport(ERROR,
812812
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
813813
errmsg("access method \"%s\" does not support multicolumn indexes",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp