don't mark indexes invalid unnecessarily

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: don't mark indexes invalid unnecessarily
Date: 2018-12-03 22:50:19
Message-ID: 20181203225019.2vvdef2ybnkxt364@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox
Thread:
Lists: pgsql-hackers

While working on FKs pointing to partitioned tables, I noticed that in
PG11 we fail to produce a working dump in the case of a partitioned
table that doesn't have partitions.

The attached patch fixes that. In doing so, it breaks a test ... and
analyzing that, it turns out that the test was broken, it wasn't testing
what it was supposed to be testing. I patched it so that it continues
to work (and now it tests the correct thing). To be precise, the test
was doing this:

create table parted_conflict (a int, b text) partition by range (a);
create table parted_conflict_1 partition of parted_conflict for values from (0) to (1000) partition by range (a);
create unique index on only parted_conflict_1 (a);
create unique index on only parted_conflict (a);
alter index parted_conflict_a_idx attach partition parted_conflict_1_a_idx;
create table parted_conflict_1_1 partition of parted_conflict_1 for values from (0) to (500);

with the expectation that the partition would not have a proper index on
which to run an INSERT INTO parted_conflict_1 ON CONFLICT (a), expecting
that partition parted_conflict_1_1 would not have the index. But in
reality parted_conflict_1_1 does have the index (and it only fails
because the index in its parent is marked invalid). So the patch moves
the CREATE TABLE parted_conflict_1_1 to before the indexes creation, so
that the partition really does not have the index, and then it gets the
expected error.

If you were to run the pg_upgrade test with my fks-to-partitioned-tables
patch, it will fail because of a PK on an partitionless partitioned
table being marked invalid after restore; but if you run it after
applying this patch, it should work (it works for me).

--
Álvaro Herrera 39°50'S 73°21'W

Attachment Content-Type Size
needless-invalid.patch text/x-diff 3.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nikita Glukhov 2018-12-03 23:25:04 Re: jsonpath
Previous Message Thomas Munro 2018-12-03 21:55:23 Re: [PATCH v19] GSSAPI encryption support