pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Indexes with INCLUDE columns and their support in B-tree
11+ messages / 5 participants
[nested] [flat]

Commits from this thread:
  2018-04-08 b3b7f7898f  Fix additional breakage in covering-index patch.
* pgsql: Indexes with INCLUDE columns and their support in B-tree
@ 2018-04-07 20:01  Teodor Sigaev <teodor@sigaev.ru>
  0 siblings, 2 replies; 11+ messages in thread

From: Teodor Sigaev @ 2018-04-07 20:01 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Indexes with INCLUDE columns and their support in B-tree

This patch introduces INCLUDE clause to index definition.  This clause
specifies a list of columns which will be included as a non-key part in
the index.  The INCLUDE columns exist solely to allow more queries to
benefit from index-only scans.  Also, such columns don't need to have
appropriate operator classes.  Expressions are not supported as INCLUDE
columns since they cannot be used in index-only scans.

Index access methods supporting INCLUDE are indicated by amcaninclude flag
in IndexAmRoutine.  For now, only B-tree indexes support INCLUDE clause.

In B-tree indexes INCLUDE columns are truncated from pivot index tuples
(tuples located in non-leaf pages and high keys).  Therefore, B-tree indexes
now might have variable number of attributes.  This patch also provides
generic facility to support that: pivot tuples contain number of their
attributes in t_tid.ip_posid.  Free 13th bit of t_info is used for indicating
that.  This facility will simplify further support of index suffix truncation.
The changes of above are backward-compatible, pg_upgrade doesn't need special
handling of B-tree indexes for that.

Bump catalog version

Author: Anastasia Lubennikova with contribition by Alexander Korotkov and me
Reviewed by: Peter Geoghegan, Tomas Vondra, Antonin Houska, Jeff Janes,
                         David Rowley, Alexander Korotkov
Discussion: https://www.postgresql.org/message-id/flat/56168952.4010101@postgrespro.ru

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8224de4f42ccf98e08db07b43d52fed72f962ebb

Modified Files
--------------
contrib/amcheck/expected/check_btree.out           |  46 +++
contrib/amcheck/sql/check_btree.sql                |  19 ++
contrib/amcheck/verify_nbtree.c                    |  98 +++++-
contrib/bloom/blutils.c                            |   1 +
contrib/dblink/dblink.c                            |  26 +-
contrib/dblink/expected/dblink.out                 |  55 ++++
contrib/dblink/sql/dblink.sql                      |  38 +++
contrib/tcn/tcn.c                                  |   6 +-
doc/src/sgml/btree.sgml                            |  17 +
doc/src/sgml/catalogs.sgml                         |  12 +-
doc/src/sgml/indexam.sgml                          |   5 +-
doc/src/sgml/indices.sgml                          |   7 +-
doc/src/sgml/ref/create_index.sgml                 |  62 +++-
doc/src/sgml/ref/create_table.sgml                 |  33 +-
src/backend/access/brin/brin.c                     |   1 +
src/backend/access/common/indextuple.c             |  31 ++
src/backend/access/gin/ginutil.c                   |   1 +
src/backend/access/gist/gist.c                     |   1 +
src/backend/access/hash/hash.c                     |   1 +
src/backend/access/heap/heapam.c                   |   4 +-
src/backend/access/index/genam.c                   |  19 +-
src/backend/access/nbtree/README                   |  17 +
src/backend/access/nbtree/nbtinsert.c              | 119 ++++---
src/backend/access/nbtree/nbtpage.c                |  23 +-
src/backend/access/nbtree/nbtree.c                 |   1 +
src/backend/access/nbtree/nbtsearch.c              |  63 +++-
src/backend/access/nbtree/nbtsort.c                |  52 +++-
src/backend/access/nbtree/nbtutils.c               |  54 +++-
src/backend/access/nbtree/nbtxlog.c                |  34 +-
src/backend/access/rmgrdesc/nbtdesc.c              |   8 +
src/backend/access/spgist/spgutils.c               |   1 +
src/backend/bootstrap/bootparse.y                  |   2 +
src/backend/bootstrap/bootstrap.c                  |   2 +-
src/backend/catalog/heap.c                         |   3 +-
src/backend/catalog/index.c                        |  86 +++--
src/backend/catalog/indexing.c                     |   1 +
src/backend/catalog/pg_constraint.c                |  27 +-
src/backend/catalog/toasting.c                     |   1 +
src/backend/commands/indexcmds.c                   |  63 +++-
src/backend/commands/matview.c                     |   6 +-
src/backend/commands/tablecmds.c                   |   9 +-
src/backend/commands/trigger.c                     |   1 +
src/backend/commands/typecmds.c                    |   1 +
src/backend/executor/execIndexing.c                |  14 +-
src/backend/executor/execReplication.c             |   6 +-
src/backend/executor/nodeIndexscan.c               |   8 +-
src/backend/nodes/copyfuncs.c                      |   2 +
src/backend/nodes/equalfuncs.c                     |   2 +
src/backend/nodes/outfuncs.c                       |   4 +
src/backend/optimizer/README                       |  10 +-
src/backend/optimizer/path/indxpath.c              |   2 +-
src/backend/optimizer/path/pathkeys.c              |  13 +-
src/backend/optimizer/util/plancat.c               |  33 +-
src/backend/parser/analyze.c                       |   6 +-
src/backend/parser/gram.y                          |  65 ++--
src/backend/parser/parse_relation.c                |   2 +-
src/backend/parser/parse_target.c                  |   3 +-
src/backend/parser/parse_utilcmd.c                 | 340 ++++++++++++++------
src/backend/utils/adt/ruleutils.c                  |  31 ++
src/backend/utils/adt/selfuncs.c                   |   4 +-
src/backend/utils/cache/relcache.c                 |  87 +++---
src/backend/utils/sort/tuplesort.c                 |   5 +-
src/bin/pg_dump/pg_dump.c                          |  40 ++-
src/bin/pg_dump/pg_dump.h                          |   6 +-
src/include/access/amapi.h                         |   2 +
src/include/access/hash.h                          |   2 +-
src/include/access/itup.h                          |   7 +-
src/include/access/nbtree.h                        |  91 ++++--
src/include/access/nbtxlog.h                       |  12 +-
src/include/catalog/catversion.h                   |   2 +-
src/include/catalog/pg_constraint.h                |  23 +-
src/include/catalog/pg_constraint_fn.h             |   1 +
src/include/catalog/pg_index.h                     |  38 +--
src/include/nodes/execnodes.h                      |   9 +-
src/include/nodes/parsenodes.h                     |   7 +-
src/include/nodes/relation.h                       |  13 +-
src/include/parser/kwlist.h                        |   1 +
src/include/utils/rel.h                            |  16 +-
.../specs/insert-conflict-do-nothing-2.spec        |   2 +-
.../specs/insert-conflict-do-update-2.spec         |   2 +-
.../isolation/specs/lock-committed-keyupdate.spec  |   2 +-
.../isolation/specs/lock-update-traversal.spec     |   5 +-
src/test/regress/expected/create_index.out         |  19 ++
src/test/regress/expected/index_including.out      | 346 +++++++++++++++++++++
src/test/regress/parallel_schedule                 |   2 +-
src/test/regress/serial_schedule                   |   1 +
src/test/regress/sql/create_index.sql              |  20 ++
src/test/regress/sql/index_including.sql           | 203 ++++++++++++
src/test/subscription/t/001_rep_changes.pl         |  19 +-
89 files changed, 2115 insertions(+), 470 deletions(-)



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: pgsql: Indexes with INCLUDE columns and their support in B-tree
@ 2018-04-07 20:44  Erik Rijkers <er@xs4all.nl>
  parent: Teodor Sigaev <teodor@sigaev.ru>
  1 sibling, 1 reply; 11+ messages in thread

From: Erik Rijkers @ 2018-04-07 20:44 UTC (permalink / raw)
  To: Teodor Sigaev <teodor@sigaev.ru>; +Cc: pgsql-committers@lists.postgresql.org

On 2018-04-07 22:01, Teodor Sigaev wrote:
> Indexes with INCLUDE columns and their support in B-tree
> 
> 
> Author: Anastasia Lubennikova with contribition by Alexander Korotkov 
> and me
> Reviewed by: Peter Geoghegan, Tomas Vondra, Antonin Houska, Jeff Janes,
>                          David Rowley, Alexander Korotkov


I've put quite some time in testing this patch, and although I don't 
really mind not being mentioned, I think it's better to err on the side 
of including too many names than too few.


Erik Rijkers







^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: pgsql: Indexes with INCLUDE columns and their support in B-tree
@ 2018-04-07 20:51  Teodor Sigaev <teodor@sigaev.ru>
  parent: Erik Rijkers <er@xs4all.nl>
  0 siblings, 2 replies; 11+ messages in thread

From: Teodor Sigaev @ 2018-04-07 20:51 UTC (permalink / raw)
  To: Erik Rijkers <er@xs4all.nl>; +Cc: pgsql-committers@lists.postgresql.org, Andrew Borodin <amborodin86@gmail.com>; Andrey Borodin <x4mmm@yandex-team.ru>

Ooops, sorry, if it possible, I'd like to change list of reviewers to 
add you, but I don't know how do it.

Nevertheless, thank you very much for your work

BTW, I miss Andrey Borodin in that list too...

Erik Rijkers wrote:
> On 2018-04-07 22:01, Teodor Sigaev wrote:
>> Indexes with INCLUDE columns and their support in B-tree
>>
>>
>> Author: Anastasia Lubennikova with contribition by Alexander Korotkov 
>> and me
>> Reviewed by: Peter Geoghegan, Tomas Vondra, Antonin Houska, Jeff Janes,
>>                          David Rowley, Alexander Korotkov
> 
> 
> I've put quite some time in testing this patch, and although I don't 
> really mind not being mentioned, I think it's better to err on the side 
> of including too many names than too few.
> 
> 
> Erik Rijkers
> 
> 
> 

-- 
Teodor Sigaev                      E-mail: teodor@sigaev.ru
                                       WWW: http://www.sigaev.ru/




^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: pgsql: Indexes with INCLUDE columns and their support in B-tree
@ 2018-04-07 21:21  Erik Rijkers <er@xs4all.nl>
  parent: Teodor Sigaev <teodor@sigaev.ru>
  1 sibling, 0 replies; 11+ messages in thread

From: Erik Rijkers @ 2018-04-07 21:21 UTC (permalink / raw)
  To: Teodor Sigaev <teodor@sigaev.ru>; +Cc: pgsql-committers@lists.postgresql.org, Andrew Borodin <amborodin86@gmail.com>; Andrey Borodin <x4mmm@yandex-team.ru>

On 2018-04-07 22:51, Teodor Sigaev wrote:
> Ooops, sorry, if it possible, I'd like to change list of reviewers to
> add you, but I don't know how do it.

No problem, really.

Thanks, great feature! I'm glad it got in.






^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: pgsql: Indexes with INCLUDE columns and their support in B-tree
@ 2018-04-08 03:06  Andrey Borodin <x4mmm@yandex-team.ru>
  parent: Teodor Sigaev <teodor@sigaev.ru>
  1 sibling, 0 replies; 11+ messages in thread

From: Andrey Borodin @ 2018-04-08 03:06 UTC (permalink / raw)
  To: Teodor Sigaev <teodor@sigaev.ru>; +Cc: Erik Rijkers <er@xs4all.nl>; pgsql-committers@lists.postgresql.org, Andrew Borodin <amborodin86@gmail.com>



> 8 апр. 2018 г., в 1:51, Teodor Sigaev <teodor@sigaev.ru> написал(а):
> 
> Ooops, sorry, if it possible, I'd like to change list of reviewers to add you, but I don't know how do it.
> 
> Nevertheless, thank you very much for your work
> 
> BTW, I miss Andrey Borodin in that list too...
No problem :) Thanks for pushing this!

Best regards, Andrey Borodin.





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: pgsql: Indexes with INCLUDE columns and their support in B-tree
@ 2018-04-08 14:41  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Teodor Sigaev <teodor@sigaev.ru>
  1 sibling, 1 reply; 11+ messages in thread

From: Tom Lane @ 2018-04-08 14:41 UTC (permalink / raw)
  To: Teodor Sigaev <teodor@sigaev.ru>; +Cc: pgsql-committers@lists.postgresql.org

Teodor Sigaev <teodor@sigaev.ru> writes:
> Indexes with INCLUDE columns and their support in B-tree

The valgrind-using animals seem to think this broke stuff.
There are at least two different problems here:

https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lousyjack&dt=2018-04-07%2020%3A03%3A02

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: pgsql: Indexes with INCLUDE columns and their support in B-tree
@ 2018-04-08 15:53  Alexander Korotkov <a.korotkov@postgrespro.ru>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 11+ messages in thread

From: Alexander Korotkov @ 2018-04-08 15:53 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Teodor Sigaev <teodor@sigaev.ru>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Sun, Apr 8, 2018 at 5:41 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Teodor Sigaev <teodor@sigaev.ru> writes:
> > Indexes with INCLUDE columns and their support in B-tree
>
> The valgrind-using animals seem to think this broke stuff.
> There are at least two different problems here:
>
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=
> lousyjack&dt=2018-04-07%2020%3A03%3A02


I think attached patch should fix one of those problems.
We should match clauses to only key columns of index.
I will further investigate the problem with CheckIndexCompatible().

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

covering-fix-match-clause-to-indexcol.patch (application/octet-stream, 530B) download diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index cc607dcdfa..ca9e067450 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -2245,7 +2245,7 @@ match_clause_to_index(IndexOptInfo *index, return; /* OK, check each index column for a match */ - for (indexcol = 0; indexcol < index->ncolumns; indexcol++) + for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++) { if (match_clause_to_indexcol(index, indexcol,
^ permalink raw reply [nested|flat] 11+ messages in thread

* Re: pgsql: Indexes with INCLUDE columns and their support in B-tree
@ 2018-04-08 16:58  Teodor Sigaev <teodor@sigaev.ru>
  parent: Alexander Korotkov <a.korotkov@postgrespro.ru>
  0 siblings, 1 reply; 11+ messages in thread

From: Teodor Sigaev @ 2018-04-08 16:58 UTC (permalink / raw)
  To: Alexander Korotkov <a.korotkov@postgrespro.ru>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers <pgsql-committers@lists.postgresql.org>

Thank you, pushed

Alexander Korotkov wrote:
> On Sun, Apr 8, 2018 at 5:41 PM, Tom Lane <tgl@sss.pgh.pa.us 
> <mailto:tgl@sss.pgh.pa.us>> wrote:
> 
>     Teodor Sigaev <teodor@sigaev.ru <mailto:teodor@sigaev.ru>> writes:
>     > Indexes with INCLUDE columns and their support in B-tree
> 
>     The valgrind-using animals seem to think this broke stuff.
>     There are at least two different problems here:
> 
>     https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lousyjack&dt=2018-04-07%2020%3A03%3A02
>     <https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lousyjack&dt=2018-04-07%2020%3A03%3A02;
> 
> 
> I think attached patch should fix one of those problems.
> We should match clauses to only key columns of index.
> I will further investigate the problem with CheckIndexCompatible().
> 
> ------
> Alexander Korotkov
> Postgres Professional:http://www.postgrespro.com 
> <http://www.postgrespro.com/;
> The Russian Postgres Company

-- 
Teodor Sigaev                      E-mail: teodor@sigaev.ru
                                       WWW: http://www.sigaev.ru/




^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: pgsql: Indexes with INCLUDE columns and their support in B-tree
@ 2018-04-08 20:26  Alexander Korotkov <a.korotkov@postgrespro.ru>
  parent: Teodor Sigaev <teodor@sigaev.ru>
  0 siblings, 1 reply; 11+ messages in thread

From: Alexander Korotkov @ 2018-04-08 20:26 UTC (permalink / raw)
  To: Teodor Sigaev <teodor@sigaev.ru>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Sun, Apr 8, 2018 at 7:58 PM, Teodor Sigaev <teodor@sigaev.ru> wrote:

> Thank you, pushed
>

Thank you!

There is also patch for valgrind error in CheckIndexCompatible().
It appears that this function didn't initialize ii_NumIndexAttrs and
ii_NumIndexKeyAttrs before calling ComputeIndexAttrs().  This
variables weren't used before, but now they're used to determine
whether index column is key.  Also, this patch makes ComputeIndexAttrs()
initialize classOidP elements with InvalidOid for non-key attributes.

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

covering-fix-compute-index-attrs.patch (application/octet-stream, 1.1K) download diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 3fb2344198..51dadb04cf 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -182,9 +182,13 @@ CheckIndexCompatible(Oid oldId, * the new index, so we can test whether it's compatible with the existing * one. Note that ComputeIndexAttrs might fail here, but that's OK: * DefineIndex would have called this function with the same arguments - * later on, and it would have failed then anyway. + * later on, and it would have failed then anyway. Our attributeList + * contains only key attributes, thus we're filling ii_NumIndexAttrs and + * ii_NumIndexKeyAttrs with same value. */ indexInfo = makeNode(IndexInfo); + indexInfo->ii_NumIndexAttrs = numberOfAttributes; + indexInfo->ii_NumIndexKeyAttrs = numberOfAttributes; indexInfo->ii_Expressions = NIL; indexInfo->ii_ExpressionsState = NIL; indexInfo->ii_PredicateState = NULL; @@ -1523,6 +1527,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo, if (attn >= nkeycols) { colOptionP[attn] = 0; + classOidP[attn] = InvalidOid; attn++; continue; }
^ permalink raw reply [nested|flat] 11+ messages in thread

* Re: pgsql: Indexes with INCLUDE columns and their support in B-tree
@ 2018-04-08 21:27  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Alexander Korotkov <a.korotkov@postgrespro.ru>
  0 siblings, 1 reply; 11+ messages in thread

From: Tom Lane @ 2018-04-08 21:27 UTC (permalink / raw)
  To: Alexander Korotkov <a.korotkov@postgrespro.ru>; +Cc: Teodor Sigaev <teodor@sigaev.ru>; pgsql-committers <pgsql-committers@lists.postgresql.org>

Alexander Korotkov <a.korotkov@postgrespro.ru> writes:
> There is also patch for valgrind error in CheckIndexCompatible().
> It appears that this function didn't initialize ii_NumIndexAttrs and
> ii_NumIndexKeyAttrs before calling ComputeIndexAttrs().  This
> variables weren't used before, but now they're used to determine
> whether index column is key.  Also, this patch makes ComputeIndexAttrs()
> initialize classOidP elements with InvalidOid for non-key attributes.

You didn't test this quite enough, because when I tried it I got a batch
of warnings about memory chunk inconsistencies.  The reason was that
DefineIndex only allocated a classObjectId array large enough for the
key columns, so that the change in ComputeIndexAttrs made it write past
the end of that array.  But I think it's a good idea to make those output
arrays all the same length, so I kept that change and changed DefineIndex.

Pushed; I've not checked to see if this makes valgrind happy, but
the buildfarm will tell us.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: pgsql: Indexes with INCLUDE columns and their support in B-tree
@ 2018-04-08 21:37  Alexander Korotkov <a.korotkov@postgrespro.ru>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 11+ messages in thread

From: Alexander Korotkov @ 2018-04-08 21:37 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Teodor Sigaev <teodor@sigaev.ru>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Mon, Apr 9, 2018 at 12:27 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Alexander Korotkov <a.korotkov@postgrespro.ru> writes:
> > There is also patch for valgrind error in CheckIndexCompatible().
> > It appears that this function didn't initialize ii_NumIndexAttrs and
> > ii_NumIndexKeyAttrs before calling ComputeIndexAttrs().  This
> > variables weren't used before, but now they're used to determine
> > whether index column is key.  Also, this patch makes ComputeIndexAttrs()
> > initialize classOidP elements with InvalidOid for non-key attributes.
>
> You didn't test this quite enough, because when I tried it I got a batch
> of warnings about memory chunk inconsistencies.  The reason was that
> DefineIndex only allocated a classObjectId array large enough for the
> key columns, so that the change in ComputeIndexAttrs made it write past
> the end of that array.


Sorry, my bad.

But I think it's a good idea to make those output
> arrays all the same length, so I kept that change and changed DefineIndex.
>
> Pushed; I've not checked to see if this makes valgrind happy, but
> the buildfarm will tell us.
>

Thank you!

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

^ permalink  raw  reply  [nested|flat] 11+ messages in thread


end of thread, other threads:[~2018-04-08 21:37 UTC | newest]

Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-04-07 20:01 pgsql: Indexes with INCLUDE columns and their support in B-tree Teodor Sigaev <teodor@sigaev.ru>
2018-04-07 20:44 ` Erik Rijkers <er@xs4all.nl>
2018-04-07 20:51   ` Teodor Sigaev <teodor@sigaev.ru>
2018-04-07 21:21     ` Erik Rijkers <er@xs4all.nl>
2018-04-08 03:06     ` Andrey Borodin <x4mmm@yandex-team.ru>
2018-04-08 14:41 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-04-08 15:53   ` Alexander Korotkov <a.korotkov@postgrespro.ru>
2018-04-08 16:58     ` Teodor Sigaev <teodor@sigaev.ru>
2018-04-08 20:26       ` Alexander Korotkov <a.korotkov@postgrespro.ru>
2018-04-08 21:27         ` Tom Lane <tgl@sss.pgh.pa.us>
2018-04-08 21:37           ` Alexander Korotkov <a.korotkov@postgrespro.ru>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox