Problem with CREATE TABLE ... (LIKE ... INCLUDING INDEXES)

From: Thom Brown <thom(at)linux(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Problem with CREATE TABLE ... (LIKE ... INCLUDING INDEXES)
Date: 2015-06-14 02:38:44
Message-ID: CAA-aLv5pC6G3HrvPhMDNCtwB4CMBo5FAREdN7n4TTcoYPDbnUg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

I've noticed that LIKE tablename INCLUDING INDEXES skips any indexes
that were duplicated.

e.g.

CREATE TABLE people (id int, alias text);
CREATE INDEX idx_people_id_1 ON people (id);
CREATE INDEX idx_people_id_2 ON people (id) WHERE id % 2 = 0;
CREATE INDEX idx_people_alias_1 ON people (alias);
CREATE INDEX idx_people_alias_2 ON people (alias);
CREATE INDEX idx_people_alias_3_tblspc ON people (alias) TABLESPACE ts;
CREATE INDEX idx_people_alias_4 ON people (alias) WITH (FILLFACTOR = 24);

\d+ people

Table "public.people"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+----------+--------------+-------------
id | integer | | plain | |
alias | text | | extended | |
Indexes:
"idx_people_alias_1" btree (alias)
"idx_people_alias_2" btree (alias)
"idx_people_alias_3_tblspc" btree (alias), tablespace "ts"
"idx_people_alias_4" btree (alias) WITH (fillfactor=24)
"idx_people_id_1" btree (id)
"idx_people_id_2" btree (id) WHERE (id % 2) = 0

CREATE SCHEMA test;
CREATE TABLE test.people (LIKE people INCLUDING INDEXES);

\d+ test.people

Table "test.people"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+----------+--------------+-------------
id | integer | | plain | |
alias | text | | extended | |
Indexes:
"people_alias_idx" btree (alias)
"people_id_idx" btree (id)
"people_id_idx1" btree (id) WHERE (id % 2) = 0

As you can see, 3 indexes are missing, which happen to be ones that
would duplicate the column definition of another index. Is this
intentional? If so, shouldn't it be documented behaviour?

--
Thom

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2015-06-14 02:44:25 Re: 9.5 release notes
Previous Message Jan de Visser 2015-06-14 02:32:50 Re: 9.5 release notes