From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: tom@intevation.de
Subject: BUG #16272: Index expression can refer to wrong attributes if index is created via CREATE TABLE LIKE
Date: Fri, 21 Feb 2020 19:37:55 +0000
Message-ID: <16272-6e32da020e9a9381@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 16272
Logged by: Tom Gottfried
Email address: tom@intevation.de
PostgreSQL version: 11.7
Operating system: Ubuntu 18.04
Description:
Dear PostgreSQL developers,
consider the following to reproduce:
/* Works: */
CREATE TABLE test (
testp varchar,
testc varchar
);
CREATE INDEX test_idx ON test
((CAST((testp, testc) AS test)));
INSERT INTO test (testp) VALUES ('test');
CREATE TABLE test_ext (
newcol int,
LIKE test INCLUDING ALL
);
INSERT INTO test_ext SELECT 1, * FROM test;
/* Does not work: */
\set VERBOSITY verbose
CREATE TABLE test_parent (
testp varchar
);
CREATE TABLE test_child (
testc varchar
) INHERITS (test_parent);
CREATE INDEX test_child_idx ON test_child
((CAST((testp, testc) AS test_child)));
INSERT INTO test_child (testp) VALUES ('test');
CREATE TABLE test_parent_ext (
newcol int,
LIKE test_parent
);
CREATE TABLE test_child_ext (LIKE test_child INCLUDING INDEXES)
INHERITS (test_parent_ext);
/* =>
NOTICE: 00000: moving and merging column "testp" with inherited
definition
DETAIL: User-specified column moved to the position of the inherited
column.
LOCATION: MergeAttributes, tablecmds.c:2378
*/
INSERT INTO test_child_ext SELECT 1, * FROM test_child;
/* =>
ERROR: 42804: attribute 1 of type record has wrong type
DETAIL: Table has type integer, but query expects character varying.
LOCATION: CheckVarSlotCompatibility, execExprInterp.c:1898
*/
\d test_child_idx
\d test_child_ext_row_idx
/* =>
Index "public.test_child_idx"
Column | Type | Key? | Definition
--------+------------+------+---------------------------------
row | test_child | yes | (ROW(testp, testc)::test_child)
btree, for table "public.test_child"
Index "public.test_child_ext_row_idx"
Column | Type | Key? | Definition
--------+------------+------+----------------------------------
row | test_child | yes | (ROW(newcol, testp)::test_child)
btree, for table "public.test_child_ext"
*/
SELECT version();
/* =>
PostgreSQL 11.7 (Ubuntu 11.7-1.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled
by gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0, 64-bit
*/
The index expression in the index created via LIKE ... INCLUDING INDEXES
still refers to the first two attributes of the table, although an attribute
has been put in place before the columns the expression referred to in the
original index.
I expected the new index expression to refer to the same (now
merged/inherited) columns as the original index (here: testp, testc) as it
actually does in the first example without inheritance.
Thanks and best regards,
Tom
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, tom@intevation.de
Subject: Re: BUG #16272: Index expression can refer to wrong attributes if index is created via CREATE TABLE LIKE
In-Reply-To: <16272-6e32da020e9a9381@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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