2018-04-07 22:00:39 +02:00
|
|
|
/*
|
|
|
|
* 1.test CREATE INDEX
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
*
|
|
|
|
* Deliberately avoid dropping objects in this section, to get some pg_dump
|
|
|
|
* coverage.
|
2018-04-07 22:00:39 +02:00
|
|
|
*/
|
|
|
|
-- Regular index with included columns
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
CREATE TABLE tbl_include_reg (c1 int, c2 int, c3 int, c4 box);
|
|
|
|
INSERT INTO tbl_include_reg SELECT x, 2*x, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
2018-07-18 20:43:03 +02:00
|
|
|
CREATE INDEX tbl_include_reg_idx ON tbl_include_reg (c1, c2) INCLUDE (c3, c4);
|
|
|
|
-- duplicate column is pretty pointless, but we allow it anyway
|
|
|
|
CREATE INDEX ON tbl_include_reg (c1, c2) INCLUDE (c1, c3);
|
2018-04-07 22:00:39 +02:00
|
|
|
SELECT pg_get_indexdef(i.indexrelid)
|
|
|
|
FROM pg_index i JOIN pg_class c ON i.indexrelid = c.oid
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
WHERE i.indrelid = 'tbl_include_reg'::regclass ORDER BY c.relname;
|
2018-07-18 20:43:03 +02:00
|
|
|
pg_get_indexdef
|
|
|
|
---------------------------------------------------------------------------------------------------------------
|
|
|
|
CREATE INDEX tbl_include_reg_c1_c2_c11_c3_idx ON public.tbl_include_reg USING btree (c1, c2) INCLUDE (c1, c3)
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
CREATE INDEX tbl_include_reg_idx ON public.tbl_include_reg USING btree (c1, c2) INCLUDE (c3, c4)
|
2018-07-18 20:43:03 +02:00
|
|
|
(2 rows)
|
2018-04-07 22:00:39 +02:00
|
|
|
|
2018-07-19 19:48:05 +02:00
|
|
|
\d tbl_include_reg_idx
|
2018-07-19 20:53:41 +02:00
|
|
|
Index "public.tbl_include_reg_idx"
|
|
|
|
Column | Type | Key? | Definition
|
|
|
|
--------+---------+------+------------
|
|
|
|
c1 | integer | yes | c1
|
|
|
|
c2 | integer | yes | c2
|
|
|
|
c3 | integer | no | c3
|
|
|
|
c4 | box | no | c4
|
2018-07-19 19:48:05 +02:00
|
|
|
btree, for table "public.tbl_include_reg"
|
|
|
|
|
2018-04-07 22:00:39 +02:00
|
|
|
-- Unique index and unique constraint
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
CREATE TABLE tbl_include_unique1 (c1 int, c2 int, c3 int, c4 box);
|
|
|
|
INSERT INTO tbl_include_unique1 SELECT x, 2*x, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
CREATE UNIQUE INDEX tbl_include_unique1_idx_unique ON tbl_include_unique1 using btree (c1, c2) INCLUDE (c3, c4);
|
|
|
|
ALTER TABLE tbl_include_unique1 add UNIQUE USING INDEX tbl_include_unique1_idx_unique;
|
|
|
|
ALTER TABLE tbl_include_unique1 add UNIQUE (c1, c2) INCLUDE (c3, c4);
|
2018-04-07 22:00:39 +02:00
|
|
|
SELECT pg_get_indexdef(i.indexrelid)
|
|
|
|
FROM pg_index i JOIN pg_class c ON i.indexrelid = c.oid
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
WHERE i.indrelid = 'tbl_include_unique1'::regclass ORDER BY c.relname;
|
|
|
|
pg_get_indexdef
|
|
|
|
-----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
CREATE UNIQUE INDEX tbl_include_unique1_c1_c2_c3_c4_key ON public.tbl_include_unique1 USING btree (c1, c2) INCLUDE (c3, c4)
|
|
|
|
CREATE UNIQUE INDEX tbl_include_unique1_idx_unique ON public.tbl_include_unique1 USING btree (c1, c2) INCLUDE (c3, c4)
|
2018-04-07 22:00:39 +02:00
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
-- Unique index and unique constraint. Both must fail.
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
CREATE TABLE tbl_include_unique2 (c1 int, c2 int, c3 int, c4 box);
|
|
|
|
INSERT INTO tbl_include_unique2 SELECT 1, 2, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
CREATE UNIQUE INDEX tbl_include_unique2_idx_unique ON tbl_include_unique2 using btree (c1, c2) INCLUDE (c3, c4);
|
|
|
|
ERROR: could not create unique index "tbl_include_unique2_idx_unique"
|
2018-04-07 22:00:39 +02:00
|
|
|
DETAIL: Key (c1, c2)=(1, 2) is duplicated.
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
ALTER TABLE tbl_include_unique2 add UNIQUE (c1, c2) INCLUDE (c3, c4);
|
|
|
|
ERROR: could not create unique index "tbl_include_unique2_c1_c2_c3_c4_key"
|
2018-04-07 22:00:39 +02:00
|
|
|
DETAIL: Key (c1, c2)=(1, 2) is duplicated.
|
|
|
|
-- PK constraint
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
CREATE TABLE tbl_include_pk (c1 int, c2 int, c3 int, c4 box);
|
|
|
|
INSERT INTO tbl_include_pk SELECT 1, 2*x, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
ALTER TABLE tbl_include_pk add PRIMARY KEY (c1, c2) INCLUDE (c3, c4);
|
2018-04-07 22:00:39 +02:00
|
|
|
SELECT pg_get_indexdef(i.indexrelid)
|
|
|
|
FROM pg_index i JOIN pg_class c ON i.indexrelid = c.oid
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
WHERE i.indrelid = 'tbl_include_pk'::regclass ORDER BY c.relname;
|
|
|
|
pg_get_indexdef
|
|
|
|
--------------------------------------------------------------------------------------------------------
|
|
|
|
CREATE UNIQUE INDEX tbl_include_pk_pkey ON public.tbl_include_pk USING btree (c1, c2) INCLUDE (c3, c4)
|
2018-04-07 22:00:39 +02:00
|
|
|
(1 row)
|
|
|
|
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
CREATE TABLE tbl_include_box (c1 int, c2 int, c3 int, c4 box);
|
|
|
|
INSERT INTO tbl_include_box SELECT 1, 2*x, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
CREATE UNIQUE INDEX tbl_include_box_idx_unique ON tbl_include_box using btree (c1, c2) INCLUDE (c3, c4);
|
|
|
|
ALTER TABLE tbl_include_box add PRIMARY KEY USING INDEX tbl_include_box_idx_unique;
|
2018-04-07 22:00:39 +02:00
|
|
|
SELECT pg_get_indexdef(i.indexrelid)
|
|
|
|
FROM pg_index i JOIN pg_class c ON i.indexrelid = c.oid
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
WHERE i.indrelid = 'tbl_include_box'::regclass ORDER BY c.relname;
|
|
|
|
pg_get_indexdef
|
|
|
|
----------------------------------------------------------------------------------------------------------------
|
|
|
|
CREATE UNIQUE INDEX tbl_include_box_idx_unique ON public.tbl_include_box USING btree (c1, c2) INCLUDE (c3, c4)
|
2018-04-07 22:00:39 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- PK constraint. Must fail.
|
Adjust INCLUDE index truncation comments and code.
Add several assertions that ensure that we're dealing with a pivot tuple
without non-key attributes where that's expected. Also, remove the
assertion within _bt_isequal(), restoring the v10 function signature. A
similar check will be performed for the page highkey within
_bt_moveright() in most cases. Also avoid dropping all objects within
regression tests, to increase pg_dump test coverage for INCLUDE indexes.
Rather than using infrastructure that's generally intended to be used
with reference counted heap tuple descriptors during truncation, use the
same function that was introduced to store flat TupleDescs in shared
memory (we use a temp palloc'd buffer). This isn't strictly necessary,
but seems more future-proof than the old approach. It also lets us
avoid including rel.h within indextuple.c, which was arguably a
modularity violation. Also, we now call index_deform_tuple() with the
truncated TupleDesc, not the source TupleDesc, since that's more robust,
and saves a few cycles.
In passing, fix a memory leak by pfree'ing truncated pivot tuple memory
during CREATE INDEX. Also pfree during a page split, just to be
consistent.
Refactor _bt_check_natts() to be more readable.
Author: Peter Geoghegan with some editorization by me
Reviewed by: Alexander Korotkov, Teodor Sigaev
Discussion: https://www.postgresql.org/message-id/CAH2-Wz%3DkCWuXeMrBCopC-tFs3FbiVxQNjjgNKdG2sHxZ5k2y3w%40mail.gmail.com
2018-04-19 07:45:58 +02:00
|
|
|
CREATE TABLE tbl_include_box_pk (c1 int, c2 int, c3 int, c4 box);
|
|
|
|
INSERT INTO tbl_include_box_pk SELECT 1, 2, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
ALTER TABLE tbl_include_box_pk add PRIMARY KEY (c1, c2) INCLUDE (c3, c4);
|
|
|
|
ERROR: could not create unique index "tbl_include_box_pk_pkey"
|
2018-04-07 22:00:39 +02:00
|
|
|
DETAIL: Key (c1, c2)=(1, 2) is duplicated.
|
|
|
|
/*
|
|
|
|
* 2. Test CREATE TABLE with constraint
|
|
|
|
*/
|
|
|
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box,
|
|
|
|
CONSTRAINT covering UNIQUE(c1,c2) INCLUDE(c3,c4));
|
|
|
|
SELECT indexrelid::regclass, indnatts, indnkeyatts, indisunique, indisprimary, indkey, indclass FROM pg_index WHERE indrelid = 'tbl'::regclass::oid;
|
|
|
|
indexrelid | indnatts | indnkeyatts | indisunique | indisprimary | indkey | indclass
|
|
|
|
------------+----------+-------------+-------------+--------------+---------+-----------
|
|
|
|
covering | 4 | 2 | t | f | 1 2 3 4 | 1978 1978
|
|
|
|
(1 row)
|
|
|
|
|
2018-09-03 17:58:42 +02:00
|
|
|
SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'tbl'::regclass::oid;
|
|
|
|
pg_get_constraintdef | conname | conkey
|
|
|
|
----------------------------------+----------+--------
|
|
|
|
UNIQUE (c1, c2) INCLUDE (c3, c4) | covering | {1,2}
|
2018-04-07 22:00:39 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- ensure that constraint works
|
|
|
|
INSERT INTO tbl SELECT 1, 2, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
ERROR: duplicate key value violates unique constraint "covering"
|
|
|
|
DETAIL: Key (c1, c2)=(1, 2) already exists.
|
|
|
|
DROP TABLE tbl;
|
|
|
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box,
|
|
|
|
CONSTRAINT covering PRIMARY KEY(c1,c2) INCLUDE(c3,c4));
|
|
|
|
SELECT indexrelid::regclass, indnatts, indnkeyatts, indisunique, indisprimary, indkey, indclass FROM pg_index WHERE indrelid = 'tbl'::regclass::oid;
|
|
|
|
indexrelid | indnatts | indnkeyatts | indisunique | indisprimary | indkey | indclass
|
|
|
|
------------+----------+-------------+-------------+--------------+---------+-----------
|
|
|
|
covering | 4 | 2 | t | t | 1 2 3 4 | 1978 1978
|
|
|
|
(1 row)
|
|
|
|
|
2018-09-03 17:58:42 +02:00
|
|
|
SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'tbl'::regclass::oid;
|
|
|
|
pg_get_constraintdef | conname | conkey
|
|
|
|
---------------------------------------+----------+--------
|
|
|
|
PRIMARY KEY (c1, c2) INCLUDE (c3, c4) | covering | {1,2}
|
2018-04-07 22:00:39 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- ensure that constraint works
|
|
|
|
INSERT INTO tbl SELECT 1, 2, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
ERROR: duplicate key value violates unique constraint "covering"
|
|
|
|
DETAIL: Key (c1, c2)=(1, 2) already exists.
|
|
|
|
INSERT INTO tbl SELECT 1, NULL, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
ERROR: null value in column "c2" violates not-null constraint
|
|
|
|
DETAIL: Failing row contains (1, null, 3, (4,4),(4,4)).
|
2019-04-01 02:24:04 +02:00
|
|
|
INSERT INTO tbl SELECT x, 2*x, NULL, NULL FROM generate_series(1,300) AS x;
|
2019-02-11 04:51:32 +01:00
|
|
|
explain (costs off)
|
|
|
|
select * from tbl where (c1,c2,c3) < (2,5,1);
|
|
|
|
QUERY PLAN
|
|
|
|
------------------------------------------------
|
|
|
|
Bitmap Heap Scan on tbl
|
|
|
|
Filter: (ROW(c1, c2, c3) < ROW(2, 5, 1))
|
|
|
|
-> Bitmap Index Scan on covering
|
|
|
|
Index Cond: (ROW(c1, c2) <= ROW(2, 5))
|
|
|
|
(4 rows)
|
|
|
|
|
|
|
|
select * from tbl where (c1,c2,c3) < (2,5,1);
|
|
|
|
c1 | c2 | c3 | c4
|
|
|
|
----+----+----+----
|
|
|
|
1 | 2 | |
|
|
|
|
2 | 4 | |
|
|
|
|
(2 rows)
|
|
|
|
|
2019-04-01 02:24:04 +02:00
|
|
|
-- row comparison that compares high key at page boundary
|
|
|
|
SET enable_seqscan = off;
|
|
|
|
explain (costs off)
|
|
|
|
select * from tbl where (c1,c2,c3) < (262,1,1) limit 1;
|
|
|
|
QUERY PLAN
|
|
|
|
----------------------------------------------------
|
|
|
|
Limit
|
|
|
|
-> Index Only Scan using covering on tbl
|
|
|
|
Index Cond: (ROW(c1, c2) <= ROW(262, 1))
|
|
|
|
Filter: (ROW(c1, c2, c3) < ROW(262, 1, 1))
|
|
|
|
(4 rows)
|
|
|
|
|
|
|
|
select * from tbl where (c1,c2,c3) < (262,1,1) limit 1;
|
|
|
|
c1 | c2 | c3 | c4
|
|
|
|
----+----+----+----
|
|
|
|
1 | 2 | |
|
|
|
|
(1 row)
|
|
|
|
|
2018-04-07 22:00:39 +02:00
|
|
|
DROP TABLE tbl;
|
2019-04-01 02:24:04 +02:00
|
|
|
RESET enable_seqscan;
|
2018-04-07 22:00:39 +02:00
|
|
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box,
|
|
|
|
UNIQUE(c1,c2) INCLUDE(c3,c4));
|
|
|
|
SELECT indexrelid::regclass, indnatts, indnkeyatts, indisunique, indisprimary, indkey, indclass FROM pg_index WHERE indrelid = 'tbl'::regclass::oid;
|
|
|
|
indexrelid | indnatts | indnkeyatts | indisunique | indisprimary | indkey | indclass
|
|
|
|
---------------------+----------+-------------+-------------+--------------+---------+-----------
|
|
|
|
tbl_c1_c2_c3_c4_key | 4 | 2 | t | f | 1 2 3 4 | 1978 1978
|
|
|
|
(1 row)
|
|
|
|
|
2018-09-03 17:58:42 +02:00
|
|
|
SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'tbl'::regclass::oid;
|
|
|
|
pg_get_constraintdef | conname | conkey
|
|
|
|
----------------------------------+---------------------+--------
|
|
|
|
UNIQUE (c1, c2) INCLUDE (c3, c4) | tbl_c1_c2_c3_c4_key | {1,2}
|
2018-04-07 22:00:39 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- ensure that constraint works
|
|
|
|
INSERT INTO tbl SELECT 1, 2, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
ERROR: duplicate key value violates unique constraint "tbl_c1_c2_c3_c4_key"
|
|
|
|
DETAIL: Key (c1, c2)=(1, 2) already exists.
|
|
|
|
DROP TABLE tbl;
|
|
|
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box,
|
|
|
|
PRIMARY KEY(c1,c2) INCLUDE(c3,c4));
|
|
|
|
SELECT indexrelid::regclass, indnatts, indnkeyatts, indisunique, indisprimary, indkey, indclass FROM pg_index WHERE indrelid = 'tbl'::regclass::oid;
|
|
|
|
indexrelid | indnatts | indnkeyatts | indisunique | indisprimary | indkey | indclass
|
|
|
|
------------+----------+-------------+-------------+--------------+---------+-----------
|
|
|
|
tbl_pkey | 4 | 2 | t | t | 1 2 3 4 | 1978 1978
|
|
|
|
(1 row)
|
|
|
|
|
2018-09-03 17:58:42 +02:00
|
|
|
SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'tbl'::regclass::oid;
|
|
|
|
pg_get_constraintdef | conname | conkey
|
|
|
|
---------------------------------------+----------+--------
|
|
|
|
PRIMARY KEY (c1, c2) INCLUDE (c3, c4) | tbl_pkey | {1,2}
|
2018-04-07 22:00:39 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- ensure that constraint works
|
|
|
|
INSERT INTO tbl SELECT 1, 2, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
ERROR: duplicate key value violates unique constraint "tbl_pkey"
|
|
|
|
DETAIL: Key (c1, c2)=(1, 2) already exists.
|
|
|
|
INSERT INTO tbl SELECT 1, NULL, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
ERROR: null value in column "c2" violates not-null constraint
|
|
|
|
DETAIL: Failing row contains (1, null, 3, (4,4),(4,4)).
|
|
|
|
INSERT INTO tbl SELECT x, 2*x, NULL, NULL FROM generate_series(1,10) AS x;
|
|
|
|
DROP TABLE tbl;
|
|
|
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box,
|
|
|
|
EXCLUDE USING btree (c1 WITH =) INCLUDE(c3,c4));
|
|
|
|
SELECT indexrelid::regclass, indnatts, indnkeyatts, indisunique, indisprimary, indkey, indclass FROM pg_index WHERE indrelid = 'tbl'::regclass::oid;
|
|
|
|
indexrelid | indnatts | indnkeyatts | indisunique | indisprimary | indkey | indclass
|
|
|
|
-------------------+----------+-------------+-------------+--------------+--------+----------
|
|
|
|
tbl_c1_c3_c4_excl | 3 | 1 | f | f | 1 3 4 | 1978
|
|
|
|
(1 row)
|
|
|
|
|
2018-09-03 17:58:42 +02:00
|
|
|
SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'tbl'::regclass::oid;
|
|
|
|
pg_get_constraintdef | conname | conkey
|
|
|
|
--------------------------------------------------+-------------------+--------
|
|
|
|
EXCLUDE USING btree (c1 WITH =) INCLUDE (c3, c4) | tbl_c1_c3_c4_excl | {1}
|
2018-04-07 22:00:39 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- ensure that constraint works
|
|
|
|
INSERT INTO tbl SELECT 1, 2, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
ERROR: conflicting key value violates exclusion constraint "tbl_c1_c3_c4_excl"
|
|
|
|
DETAIL: Key (c1)=(1) conflicts with existing key (c1)=(1).
|
|
|
|
INSERT INTO tbl SELECT x, 2*x, NULL, NULL FROM generate_series(1,10) AS x;
|
|
|
|
DROP TABLE tbl;
|
|
|
|
/*
|
|
|
|
* 3.0 Test ALTER TABLE DROP COLUMN.
|
|
|
|
* Any column deletion leads to index deletion.
|
|
|
|
*/
|
|
|
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 int);
|
|
|
|
CREATE UNIQUE INDEX tbl_idx ON tbl using btree(c1, c2, c3, c4);
|
|
|
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|
|
|
indexdef
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
CREATE UNIQUE INDEX tbl_idx ON public.tbl USING btree (c1, c2, c3, c4)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
ALTER TABLE tbl DROP COLUMN c3;
|
|
|
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|
|
|
indexdef
|
|
|
|
----------
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
DROP TABLE tbl;
|
|
|
|
/*
|
|
|
|
* 3.1 Test ALTER TABLE DROP COLUMN.
|
|
|
|
* Included column deletion leads to the index deletion,
|
|
|
|
* AS well AS key columns deletion. It's explained in documentation.
|
|
|
|
*/
|
|
|
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box);
|
|
|
|
CREATE UNIQUE INDEX tbl_idx ON tbl using btree(c1, c2) INCLUDE(c3,c4);
|
|
|
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|
|
|
indexdef
|
|
|
|
---------------------------------------------------------------------------------
|
|
|
|
CREATE UNIQUE INDEX tbl_idx ON public.tbl USING btree (c1, c2) INCLUDE (c3, c4)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
ALTER TABLE tbl DROP COLUMN c3;
|
|
|
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|
|
|
indexdef
|
|
|
|
----------
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
DROP TABLE tbl;
|
|
|
|
/*
|
|
|
|
* 3.2 Test ALTER TABLE DROP COLUMN.
|
|
|
|
* Included column deletion leads to the index deletion.
|
|
|
|
* AS well AS key columns deletion. It's explained in documentation.
|
|
|
|
*/
|
|
|
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box, UNIQUE(c1, c2) INCLUDE(c3,c4));
|
|
|
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|
|
|
indexdef
|
|
|
|
---------------------------------------------------------------------------------------------
|
|
|
|
CREATE UNIQUE INDEX tbl_c1_c2_c3_c4_key ON public.tbl USING btree (c1, c2) INCLUDE (c3, c4)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
ALTER TABLE tbl DROP COLUMN c3;
|
|
|
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|
|
|
indexdef
|
|
|
|
----------
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
ALTER TABLE tbl DROP COLUMN c1;
|
|
|
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|
|
|
indexdef
|
|
|
|
----------
|
|
|
|
(0 rows)
|
|
|
|
|
2018-07-17 02:00:24 +02:00
|
|
|
DROP TABLE tbl;
|
|
|
|
/*
|
|
|
|
* 3.3 Test ALTER TABLE SET STATISTICS
|
|
|
|
*/
|
|
|
|
CREATE TABLE tbl (c1 int, c2 int);
|
|
|
|
CREATE INDEX tbl_idx ON tbl (c1, (c1+0)) INCLUDE (c2);
|
|
|
|
ALTER INDEX tbl_idx ALTER COLUMN 1 SET STATISTICS 1000;
|
|
|
|
ERROR: cannot alter statistics on non-expression column "c1" of index "tbl_idx"
|
|
|
|
HINT: Alter statistics on table column instead.
|
|
|
|
ALTER INDEX tbl_idx ALTER COLUMN 2 SET STATISTICS 1000;
|
|
|
|
ALTER INDEX tbl_idx ALTER COLUMN 3 SET STATISTICS 1000;
|
|
|
|
ERROR: cannot alter statistics on included column "c2" of index "tbl_idx"
|
|
|
|
ALTER INDEX tbl_idx ALTER COLUMN 4 SET STATISTICS 1000;
|
|
|
|
ERROR: column number 4 of relation "tbl_idx" does not exist
|
2018-04-07 22:00:39 +02:00
|
|
|
DROP TABLE tbl;
|
|
|
|
/*
|
|
|
|
* 4. CREATE INDEX CONCURRENTLY
|
|
|
|
*/
|
|
|
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box, UNIQUE(c1, c2) INCLUDE(c3,c4));
|
|
|
|
INSERT INTO tbl SELECT x, 2*x, 3*x, box('4,4,4,4') FROM generate_series(1,1000) AS x;
|
|
|
|
CREATE UNIQUE INDEX CONCURRENTLY on tbl (c1, c2) INCLUDE (c3, c4);
|
|
|
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|
|
|
indexdef
|
|
|
|
---------------------------------------------------------------------------------------------
|
|
|
|
CREATE UNIQUE INDEX tbl_c1_c2_c3_c4_idx ON public.tbl USING btree (c1, c2) INCLUDE (c3, c4)
|
|
|
|
CREATE UNIQUE INDEX tbl_c1_c2_c3_c4_key ON public.tbl USING btree (c1, c2) INCLUDE (c3, c4)
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
DROP TABLE tbl;
|
|
|
|
/*
|
|
|
|
* 5. REINDEX
|
|
|
|
*/
|
|
|
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box, UNIQUE(c1, c2) INCLUDE(c3,c4));
|
|
|
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|
|
|
indexdef
|
|
|
|
---------------------------------------------------------------------------------------------
|
|
|
|
CREATE UNIQUE INDEX tbl_c1_c2_c3_c4_key ON public.tbl USING btree (c1, c2) INCLUDE (c3, c4)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
ALTER TABLE tbl DROP COLUMN c3;
|
|
|
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|
|
|
indexdef
|
|
|
|
----------
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
REINDEX INDEX tbl_c1_c2_c3_c4_key;
|
|
|
|
ERROR: relation "tbl_c1_c2_c3_c4_key" does not exist
|
|
|
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|
|
|
indexdef
|
|
|
|
----------
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
ALTER TABLE tbl DROP COLUMN c1;
|
|
|
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|
|
|
indexdef
|
|
|
|
----------
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
DROP TABLE tbl;
|
|
|
|
/*
|
2019-03-10 09:36:47 +01:00
|
|
|
* 7. Check various AMs. All but btree and gist must fail.
|
2018-04-07 22:00:39 +02:00
|
|
|
*/
|
|
|
|
CREATE TABLE tbl (c1 int,c2 int, c3 box, c4 box);
|
|
|
|
CREATE INDEX on tbl USING brin(c1, c2) INCLUDE (c3, c4);
|
|
|
|
ERROR: access method "brin" does not support included columns
|
2019-03-10 09:36:47 +01:00
|
|
|
CREATE INDEX on tbl USING gist(c3) INCLUDE (c1, c4);
|
2018-04-07 22:00:39 +02:00
|
|
|
CREATE INDEX on tbl USING spgist(c3) INCLUDE (c4);
|
|
|
|
ERROR: access method "spgist" does not support included columns
|
|
|
|
CREATE INDEX on tbl USING gin(c1, c2) INCLUDE (c3, c4);
|
|
|
|
ERROR: access method "gin" does not support included columns
|
|
|
|
CREATE INDEX on tbl USING hash(c1, c2) INCLUDE (c3, c4);
|
|
|
|
ERROR: access method "hash" does not support included columns
|
2019-03-10 09:36:47 +01:00
|
|
|
CREATE INDEX on tbl USING rtree(c3) INCLUDE (c1, c4);
|
2018-04-07 22:00:39 +02:00
|
|
|
NOTICE: substituting access method "gist" for obsolete method "rtree"
|
|
|
|
CREATE INDEX on tbl USING btree(c1, c2) INCLUDE (c3, c4);
|
|
|
|
DROP TABLE tbl;
|
|
|
|
/*
|
|
|
|
* 8. Update, delete values in indexed table.
|
|
|
|
*/
|
|
|
|
CREATE TABLE tbl (c1 int, c2 int, c3 int, c4 box);
|
|
|
|
INSERT INTO tbl SELECT x, 2*x, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
CREATE UNIQUE INDEX tbl_idx_unique ON tbl using btree(c1, c2) INCLUDE (c3,c4);
|
|
|
|
UPDATE tbl SET c1 = 100 WHERE c1 = 2;
|
|
|
|
UPDATE tbl SET c1 = 1 WHERE c1 = 3;
|
|
|
|
-- should fail
|
|
|
|
UPDATE tbl SET c2 = 2 WHERE c1 = 1;
|
|
|
|
ERROR: duplicate key value violates unique constraint "tbl_idx_unique"
|
|
|
|
DETAIL: Key (c1, c2)=(1, 2) already exists.
|
|
|
|
UPDATE tbl SET c3 = 1;
|
|
|
|
DELETE FROM tbl WHERE c1 = 5 OR c3 = 12;
|
|
|
|
DROP TABLE tbl;
|
|
|
|
/*
|
|
|
|
* 9. Alter column type.
|
|
|
|
*/
|
|
|
|
CREATE TABLE tbl (c1 int,c2 int, c3 int, c4 box, UNIQUE(c1, c2) INCLUDE(c3,c4));
|
|
|
|
INSERT INTO tbl SELECT x, 2*x, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
|
|
|
ALTER TABLE tbl ALTER c1 TYPE bigint;
|
|
|
|
ALTER TABLE tbl ALTER c3 TYPE bigint;
|
|
|
|
\d tbl
|
|
|
|
Table "public.tbl"
|
|
|
|
Column | Type | Collation | Nullable | Default
|
|
|
|
--------+---------+-----------+----------+---------
|
|
|
|
c1 | bigint | | |
|
|
|
|
c2 | integer | | |
|
|
|
|
c3 | bigint | | |
|
|
|
|
c4 | box | | |
|
|
|
|
Indexes:
|
|
|
|
"tbl_c1_c2_c3_c4_key" UNIQUE CONSTRAINT, btree (c1, c2) INCLUDE (c3, c4)
|
|
|
|
|
|
|
|
DROP TABLE tbl;
|