From: Michael Paquier <michael@paquier.xyz>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: jan.mussler@zalando.de
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16594: DROP INDEX CONCURRENTLY fails on partitioned table with a non helpful error message.
Date: Tue, 1 Sep 2020 11:58:35 +0900
Message-ID: <20200901025835.GC3511@paquier.xyz> (raw)
In-Reply-To: <20200901012553.GA17180@alvherre.pgsql>
References: <20200829013433.GA1529@paquier.xyz>
<20200901012553.GA17180@alvherre.pgsql>
On Mon, Aug 31, 2020 at 09:25:53PM -0400, Alvaro Herrera wrote:
> Actually I think you're wrong; if I put it before the check, then if I
> do "drop index concurrently some_temp_partitioned_index" then it would
> fail; but if I put it after the check, then it does a normal
> non-concurrent index and it works. I'm not sure it's necessary to break
> a case that otherwise works ...
Hmm. Right. I agree that it would be better to not break that case.
And it means that there is a gap in the regression tests here, so I'd
like to add a test. Please see the attached to achieve that, which
includes your own code changes and the doc parts (I didn't see a point
in changing the new sentence for temporary relations as the follow-up
<para> mentions that).
> (But for that to work I need to test the flag in the bitmask rather than
> the option in the command, as in the attached).
Make sense.
--
Michael
Attachments:reindex-drop-part-michael.patch (text/x-diff, 4.5K) downloaddiff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.cindex d2b15a3387..3e57c7f9e1 100644--- a/src/backend/commands/tablecmds.c+++ b/src/backend/commands/tablecmds.c@@ -1373,6 +1373,17 @@ RemoveRelations(DropStmt *drop)
flags |= PERFORM_DELETION_CONCURRENTLY;
}
+ /*+ * Concurrent index drop cannot be used with partitioned indexes,+ * either.+ */+ if ((flags & PERFORM_DELETION_CONCURRENTLY) != 0 &&+ get_rel_relkind(relOid) == RELKIND_PARTITIONED_INDEX)+ ereport(ERROR,+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),+ errmsg("cannot drop partitioned index \"%s\" concurrently",+ rel->relname)));+
/* OK, we're ready to delete this one */
obj.classId = RelationRelationId;
obj.objectId = relOid;
diff --git a/src/test/regress/expected/indexing.out b/src/test/regress/expected/indexing.outindex f78865ef81..7e78a07af8 100644--- a/src/test/regress/expected/indexing.out+++ b/src/test/regress/expected/indexing.out@@ -174,6 +174,8 @@ create table idxpart1 partition of idxpart for values from (0) to (10);
drop index idxpart1_a_idx; -- no way
ERROR: cannot drop index idxpart1_a_idx because index idxpart_a_idx requires it
HINT: You can drop index idxpart_a_idx instead.
+drop index concurrently idxpart_a_idx; -- unsupported+ERROR: cannot drop partitioned index "idxpart_a_idx" concurrently
drop index idxpart_a_idx; -- both indexes go away
select relname, relkind from pg_class
where relname like 'idxpart%' order by relname;
@@ -194,6 +196,24 @@ select relname, relkind from pg_class
(2 rows)
drop table idxpart;
+-- DROP behavior with temporary partitioned indexes+create temp table idxpart_temp (a int) partition by range (a);+create index on idxpart_temp(a);+create temp table idxpart1_temp partition of idxpart_temp+ for values from (0) to (10);+drop index idxpart1_temp_a_idx; -- error+ERROR: cannot drop index idxpart1_temp_a_idx because index idxpart_temp_a_idx requires it+HINT: You can drop index idxpart_temp_a_idx instead.+-- non-concurrent drop is enforced here, so it is a valid case.+drop index concurrently idxpart_temp_a_idx;+select relname, relkind from pg_class+ where relname like 'idxpart_temp%' order by relname;+ relname | relkind +--------------+---------+ idxpart_temp | p+(1 row)++drop table idxpart_temp;
-- ALTER INDEX .. ATTACH, error cases
create table idxpart (a int, b int) partition by range (a, b);
create table idxpart1 partition of idxpart for values from (0, 0) to (10, 10);
diff --git a/src/test/regress/sql/indexing.sql b/src/test/regress/sql/indexing.sqlindex 35d159f41b..260233ae73 100644--- a/src/test/regress/sql/indexing.sql+++ b/src/test/regress/sql/indexing.sql@@ -92,6 +92,7 @@ create table idxpart (a int) partition by range (a);
create index on idxpart (a);
create table idxpart1 partition of idxpart for values from (0) to (10);
drop index idxpart1_a_idx; -- no way
+drop index concurrently idxpart_a_idx; -- unsupported
drop index idxpart_a_idx; -- both indexes go away
select relname, relkind from pg_class
where relname like 'idxpart%' order by relname;
@@ -100,6 +101,17 @@ drop table idxpart1; -- the index on partition goes away too
select relname, relkind from pg_class
where relname like 'idxpart%' order by relname;
drop table idxpart;
+-- DROP behavior with temporary partitioned indexes+create temp table idxpart_temp (a int) partition by range (a);+create index on idxpart_temp(a);+create temp table idxpart1_temp partition of idxpart_temp+ for values from (0) to (10);+drop index idxpart1_temp_a_idx; -- error+-- non-concurrent drop is enforced here, so it is a valid case.+drop index concurrently idxpart_temp_a_idx;+select relname, relkind from pg_class+ where relname like 'idxpart_temp%' order by relname;+drop table idxpart_temp;
-- ALTER INDEX .. ATTACH, error cases
create table idxpart (a int, b int) partition by range (a, b);
diff --git a/doc/src/sgml/ref/drop_index.sgml b/doc/src/sgml/ref/drop_index.sgmlindex 0aedd71bd6..85cf23bca2 100644--- a/doc/src/sgml/ref/drop_index.sgml+++ b/doc/src/sgml/ref/drop_index.sgml@@ -57,6 +57,8 @@ DROP INDEX [ CONCURRENTLY ] [ IF EXISTS ] <replaceable class="parameter">name</r
Also, regular <command>DROP INDEX</command> commands can be
performed within a transaction block, but
<command>DROP INDEX CONCURRENTLY</command> cannot.
+ Lastly, indexes on partitioned tables cannot be dropped using this+ option.
</para>
<para>
For temporary tables, <command>DROP INDEX</command> is always
signature.asc (application/pgp-signature, 832B) download
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: michael@paquier.xyz, alvherre@2ndquadrant.com, jan.mussler@zalando.de, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16594: DROP INDEX CONCURRENTLY fails on partitioned table with a non helpful error message.
In-Reply-To: <20200901025835.GC3511@paquier.xyz>
* 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