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

Commit0a70b21

Browse files
committed
updates according to including_columns_commited version
1 parent3f17781 commit0a70b21

File tree

11 files changed

+524
-57
lines changed

11 files changed

+524
-57
lines changed

‎contrib/dblink/dblink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static remoteConn *getConnectionByName(const char *name);
101101
staticHTAB*createConnHash(void);
102102
staticvoidcreateNewConnection(constchar*name,remoteConn*rconn);
103103
staticvoiddeleteConnection(constchar*name);
104-
staticchar**get_pkey_attnames(Relationrel,int16*indnkeyatts);
104+
staticchar**get_pkey_attnames(Relationrel,int16*indnkeyatts);
105105
staticchar**get_text_array_contents(ArrayType*array,int*numitems);
106106
staticchar*get_sql_insert(Relationrel,int*pkattnums,intpknumatts,char**src_pkattvals,char**tgt_pkattvals);
107107
staticchar*get_sql_delete(Relationrel,int*pkattnums,intpknumatts,char**tgt_pkattvals);

‎doc/src/sgml/ref/create_index.sgml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ doc/src/sgml/ref/create_index.sgml
2323
<synopsis>
2424
CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] <replaceable class="parameter">name</replaceable> ] ON <replaceable class="parameter">table_name</replaceable> [ USING <replaceable class="parameter">method</replaceable> ]
2525
( { <replaceable class="parameter">column_name</replaceable> | ( <replaceable class="parameter">expression</replaceable> ) } [ COLLATE <replaceable class="parameter">collation</replaceable> ] [ <replaceable class="parameter">opclass</replaceable> ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] )
26-
[ INCLUDING ({<replaceable class="parameter">column_name</replaceable>| ( <replaceable class="parameter">expression</replaceable> ) } [ COLLATE <replaceable class="parameter">collation</replaceable> ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] )
26+
[ INCLUDING ( <replaceable class="parameter">column_name</replaceable>[, ...] ) ]
2727
[ WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] ) ]
2828
[ TABLESPACE <replaceable class="parameter">tablespace_name</replaceable> ]
2929
[ WHERE <replaceable class="parameter">predicate</replaceable> ]
@@ -145,22 +145,25 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] <replaceable class=
145145
<para>
146146
An optional <literal>INCLUDING</> clause allows a list of columns to be
147147
specified which will be included in the index, in the non-key portion of
148-
the index. Columns which are part of this clause cannot also exist in the
149-
key columns portion of the index, and vice versa. The
150-
<literal>INCLUDING</> columns exist solely to allow more queries to benefit
151-
from <firstterm>index-only scans</> by including certain columns in the
152-
index, the value of which would otherwise have to be obtained by reading
153-
the table's heap. Having these columns in the <literal>INCLUDING</> clause
154-
in some cases allows <productname>PostgreSQL</> to skip the heap read
155-
completely. This also allows <literal>UNIQUE</> indexes to be defined on
156-
one set of columns, which can include another set of column in the
157-
<literal>INCLUDING</> clause, on which the uniqueness is not enforced upon.
158-
It's the same with other constraints (PRIMARY KEY and EXCLUDE). This can
159-
also can be used for non-unique indexes as any columns which are not required
160-
for the searching or ordering of records can be included in the
161-
<literal>INCLUDING</> clause, which can slightly reduce the size of the index,
162-
due to storing included attributes only in leaf index pages.
163-
Currently, only the B-tree access method supports this feature.
148+
the index. Columns which are part of this clause cannot also exist in
149+
the key columns portion of the index, and vice versa. The
150+
<literal>INCLUDING</> columns exist solely to allow more queries to
151+
benefit from <firstterm>index-only scans</> by including certain
152+
columns in the index, the value of which would otherwise have to be
153+
obtained by reading the table's heap. Having these columns in the
154+
<literal>INCLUDING</> clause in some cases allows
155+
<productname>PostgreSQL</> to skip the heap read completely. This
156+
also allows <literal>UNIQUE</> indexes to be defined on one set of
157+
columns, which can include another set of column in the
158+
<literal>INCLUDING</> clause, on which the uniqueness is not enforced
159+
upon. It's the same with other constraints (PRIMARY KEY and EXCLUDE).
160+
This can also can be used for non-unique indexes as any columns which
161+
are not required for the searching or ordering of records can be
162+
included in the <literal>INCLUDING</> clause, which can slightly reduce
163+
the size of the index, due to storing included attributes only in leaf
164+
index pages. Currently, only the B-tree access method supports this
165+
feature. Expressions as included columns are not supported since
166+
they cannot be used in index-only scan.
164167
</para>
165168
</listitem>
166169
</varlistentry>

‎doc/src/sgml/ref/create_table.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
505505
Optional clause <literal>INCLUDING</literal> allows to add into the index
506506
a portion of columns on which the uniqueness is not enforced upon.
507507
Note, that althogh constraint is not enforced upon included columns, it still
508-
depends on them. Consequently, some operations on these columns (e.g. <literal>DROP COLUMN<literal>)
508+
depends on them. Consequently, some operations on these columns (e.g. <literal>DROP COLUMN</literal>)
509509
can cause cascade constraint and index deletion.
510510
See paragraph about <literal>INCLUDING</literal> in
511511
<xref linkend="SQL-CREATEINDEX"> for more information.
@@ -545,7 +545,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
545545
Optional clause <literal>INCLUDING</literal> allows to add into the index
546546
a portion of columns on which the constraint is not enforced upon.
547547
Note, that althogh constraint is not enforced upon included columns, it still
548-
depends on them. Consequently, some operations on these columns (e.g. <literal>DROP COLUMN<literal>)
548+
depends on them. Consequently, some operations on these columns (e.g. <literal>DROP COLUMN</literal>)
549549
can cause cascade constraint and index deletion.
550550
See paragraph about <literal>INCLUDING</literal> in
551551
<xref linkend="SQL-CREATEINDEX"> for more information.

‎src/backend/access/common/indextuple.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,25 +448,29 @@ CopyIndexTuple(IndexTuple source)
448448
* Reform index tuple. Truncate nonkey (INCLUDING) attributes.
449449
*/
450450
IndexTuple
451-
index_reform_tuple(Relationidxrel,IndexTupleolditup,intnatts,intnkeyatts)
451+
index_truncate_tuple(Relationidxrel,IndexTupleolditup)
452452
{
453453
TupleDescitupdesc=RelationGetDescr(idxrel);
454454
Datumvalues[INDEX_MAX_KEYS];
455455
boolisnull[INDEX_MAX_KEYS];
456456
IndexTuplenewitup;
457+
intindnatts=IndexRelationGetNumberOfAttributes(idxrel);
458+
intindnkeyatts=IndexRelationGetNumberOfKeyAttributes(idxrel);
457459

458-
Assert(natts <=INDEX_MAX_KEYS);
459-
Assert(nkeyatts>0);
460-
Assert(nkeyatts <=natts);
460+
Assert(indnatts <=INDEX_MAX_KEYS);
461+
Assert(indnkeyatts>0);
462+
Assert(indnkeyatts <=indnatts);
461463

462464
index_deform_tuple(olditup,itupdesc,values,isnull);
463465

464466
/* form new tuple that will contain only key attributes */
465-
itupdesc->natts=nkeyatts;
467+
itupdesc->natts=indnkeyatts;
466468
newitup=index_form_tuple(itupdesc,values,isnull);
467469
newitup->t_tid=olditup->t_tid;
468470

469-
itupdesc->natts=natts;
471+
itupdesc->natts=indnatts;
472+
473+
Assert(IndexTupleSize(newitup) <=IndexTupleSize(olditup));
470474

471475
returnnewitup;
472476
}

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -748,14 +748,6 @@ _bt_insertonpg(Relation rel,
748748
elog(ERROR,"cannot insert to incompletely split page %u",
749749
BufferGetBlockNumber(buf));
750750

751-
/* Truncate nonkey attributes when inserting on nonleaf pages. */
752-
if (rel->rd_index->indnatts!=rel->rd_index->indnkeyatts
753-
&& !P_ISLEAF(lpageop))
754-
{
755-
itup=index_reform_tuple(rel,itup,
756-
rel->rd_index->indnatts,rel->rd_index->indnkeyatts);
757-
}
758-
759751
itemsz=IndexTupleDSize(*itup);
760752
itemsz=MAXALIGN(itemsz);/* be safe, PageAddItem will do this but we
761753
* need to be consistent */
@@ -1094,7 +1086,7 @@ _bt_split(Relation rel, Buffer buf, Buffer cbuf, OffsetNumber firstright,
10941086
*/
10951087
if (indnatts!=indnkeyatts&&P_ISLEAF(lopaque))
10961088
{
1097-
lefthikey=index_reform_tuple(rel,item,indnatts,indnkeyatts);
1089+
lefthikey=index_truncate_tuple(rel,item);
10981090
itemsz=IndexTupleSize(lefthikey);
10991091
itemsz=MAXALIGN(itemsz);
11001092
}
@@ -1991,10 +1983,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
19911983
right_item_sz=ItemIdGetLength(itemid);
19921984
item= (IndexTuple)PageGetItem(lpage,itemid);
19931985

1994-
if (rel->rd_index->indnatts!=rel->rd_index->indnkeyatts)
1995-
right_item=index_reform_tuple(rel,item,rel->rd_index->indnatts,rel->rd_index->indnkeyatts);
1996-
else
1997-
right_item=CopyIndexTuple(item);
1986+
right_item=CopyIndexTuple(item);
19981987
ItemPointerSet(&(right_item->t_tid),rbkno,P_HIKEY);
19991988

20001989
/* NO EREPORT(ERROR) from here till newroot op is logged */

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -552,22 +552,15 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
552552
* assume that hikey is already truncated, and so they should not
553553
* worry about it, when copying the high key into the parent page
554554
* as a downlink.
555-
* NOTE It is not crutial for reliability in present,
556-
* but maybe it will be that in the future.
557-
* NOTE this code will be changed by the "btree compression" patch,
558-
* which is in progress now.
559555
*/
560-
keytup=index_reform_tuple(wstate->index,oitup,
561-
indnatts,indnkeyatts);
556+
keytup=index_truncate_tuple(wstate->index,oitup);
562557

563558
/* delete "wrong" high key, insert keytup as P_HIKEY. */
564-
START_CRIT_SECTION();
565559
PageIndexTupleDelete(opage,P_HIKEY);
566560

567561
if (!_bt_pgaddtup(opage,IndexTupleSize(keytup),keytup,P_HIKEY))
568562
elog(ERROR,"failed to rewrite compressed item in index \"%s\"",
569563
RelationGetRelationName(wstate->index));
570-
END_CRIT_SECTION();
571564
}
572565

573566
/*
@@ -593,8 +586,7 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
593586
* truncated by the time we handle them.
594587
*/
595588
if (indnkeyatts!=indnatts&&P_ISLEAF(opageop))
596-
state->btps_minkey=index_reform_tuple(wstate->index,oitup,
597-
indnatts,indnkeyatts);
589+
state->btps_minkey=index_truncate_tuple(wstate->index,oitup);
598590
else
599591
state->btps_minkey=CopyIndexTuple(oitup);
600592

@@ -637,8 +629,7 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
637629
* into the parent page as a downlink
638630
*/
639631
if (indnkeyatts<indnatts&&P_ISLEAF(pageop))
640-
state->btps_minkey=index_reform_tuple(wstate->index,itup,
641-
indnatts,indnkeyatts);
632+
state->btps_minkey=index_truncate_tuple(wstate->index,itup);
642633
else
643634
state->btps_minkey=CopyIndexTuple(itup);}
644635

@@ -650,9 +641,7 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
650641

651642
if (!P_ISLEAF(pageop))
652643
{
653-
itup=index_reform_tuple(wstate->index,
654-
itup,wstate->index->rd_index->indnatts,
655-
wstate->index->rd_index->indnkeyatts);
644+
itup=index_truncate_tuple(wstate->index,itup);
656645
itupsz=IndexTupleDSize(*itup);
657646
itupsz=MAXALIGN(itupsz);
658647
}

‎src/include/access/itup.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ extern Datum nocache_index_getattr(IndexTuple tup, int attnum,
149149
externvoidindex_deform_tuple(IndexTupletup,TupleDesctupleDescriptor,
150150
Datum*values,bool*isnull);
151151
externIndexTupleCopyIndexTuple(IndexTuplesource);
152-
externIndexTupleindex_reform_tuple(Relationidxrel,IndexTupleolditup,
153-
intindnatts,intindnkeyatts);
152+
externIndexTupleindex_truncate_tuple(Relationidxrel,IndexTupleolditup);
154153

155154
#endif/* ITUP_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp