pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Detach constraints when partitions are detached
5+ messages / 4 participants
[nested] [flat]

Commits from this thread:
  2019-01-24 71eba83999 19184fcc09  Simplify coding to detach constraints when detaching partition
* pgsql: Detach constraints when partitions are detached
@ 2019-01-24 03:02 Alvaro Herrera <alvherre@alvh.no-ip.org>
  2019-01-24 04:58 ` Re: pgsql: Detach constraints when partitions are detached Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Alvaro Herrera @ 2019-01-24 03:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Detach constraints when partitions are detached

I (Álvaro) forgot to do this in eb7ed3f30634, leading to undroppable
constraints after partitions are detached.  Repair.

Reported-by: Amit Langote
Author: Amit Langote
Discussion: https://postgr.es/m/c1c9b688-b886-84f7-4048-1e4ebe9b1d06@lab.ntt.co.jp

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ae366aa57762ad0e6a1a0885a7644e79541afe39

Modified Files
--------------
src/backend/commands/tablecmds.c       | 18 ++++++++++++++++++
src/test/regress/expected/indexing.out | 15 +++++++++++++++
src/test/regress/sql/indexing.sql      | 14 ++++++++++++++
3 files changed, 47 insertions(+)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pgsql: Detach constraints when partitions are detached
  2019-01-24 03:02 pgsql: Detach constraints when partitions are detached Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2019-01-24 04:58 ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-01-24 05:22   ` Re: pgsql: Detach constraints when partitions are detached Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2019-01-24 04:58 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: pgsql-committers@lists.postgresql.org

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> Detach constraints when partitions are detached

Hm ... it looks like this fails under -DRELCACHE_FORCE_RELEASE:

https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=prion&dt=2019-01-24%2003%3A58%3A02

Core was generated by `postgres: ec2-user regression [local] ALTER TABLE                             '.
Program terminated with signal 11, Segmentation fault.
#0  0x00000000005f9413 in ATExecDetachPartition (rel=rel@entry=0x7f20d6fab080, name=<optimized out>) at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/commands/tablecmds.c:15116
15116			if (!idx->rd_index->indisprimary && !idx->rd_index->indisunique)
#0  0x00000000005f9413 in ATExecDetachPartition (rel=rel@entry=0x7f20d6fab080, name=<optimized out>) at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/commands/tablecmds.c:15116
#1  0x0000000000605a95 in ATExecCmd (wqueue=wqueue@entry=0x7ffe1afaea28, tab=tab@entry=0x1591a10, rel=rel@entry=0x7f20d6fab080, cmd=0x155ee08, lockmode=lockmode@entry=8) at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/commands/tablecmds.c:4314
#2  0x0000000000607faf in ATRewriteCatalogs (lockmode=8, wqueue=0x7ffe1afaea28) at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/commands/tablecmds.c:4028
#3  ATController (parsetree=parsetree@entry=0x1542fc8, rel=<optimized out>, cmds=<optimized out>, recurse=<optimized out>, lockmode=lockmode@entry=8) at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/commands/tablecmds.c:3694
#4  0x00000000006086cf in AlterTable (relid=relid@entry=32016, lockmode=lockmode@entry=8, stmt=stmt@entry=0x1542fc8) at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/commands/tablecmds.c:3368
#5  0x0000000000792042 in ProcessUtilitySlow (pstate=pstate@entry=0x152ede8, pstmt=pstmt@entry=0x1470b18, queryString=queryString@entry=0x146fb78 "alter table idxpart detach partition idxpart1;", context=context@entry=PROCESS_UTILITY_TOPLEVEL, params=params@entry=0x0, queryEnv=queryEnv@entry=0x0, completionTag=completionTag@entry=0x7ffe1afaefe0 "", dest=0x1470c10) at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/tcop/utility.c:1120
#6  0x00000000007904d6 in standard_ProcessUtility (pstmt=0x1470b18, queryString=0x146fb78 "alter table idxpart detach partition idxpart1;", context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0x1470c10, completionTag=0x7ffe1afaefe0 "") at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/tcop/utility.c:923
#7  0x000000000078dae5 in PortalRunUtility (portal=0x14d5dd8, pstmt=0x1470b18, isTopLevel=<optimized out>, setHoldSnapshot=<optimized out>, dest=<optimized out>, completionTag=0x7ffe1afaefe0 "") at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/tcop/pquery.c:1175
#8  0x000000000078e5f9 in PortalRunMulti (portal=portal@entry=0x14d5dd8, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=false, dest=dest@entry=0x1470c10, altdest=altdest@entry=0x1470c10, completionTag=completionTag@entry=0x7ffe1afaefe0 "") at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/tcop/pquery.c:1328
#9  0x000000000078f292 in PortalRun (portal=portal@entry=0x14d5dd8, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, run_once=run_once@entry=true, dest=dest@entry=0x1470c10, altdest=altdest@entry=0x1470c10, completionTag=completionTag@entry=0x7ffe1afaefe0 "") at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/tcop/pquery.c:796
#10 0x000000000078b02d in exec_simple_query (query_string=0x146fb78 "alter table idxpart detach partition idxpart1;") at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/tcop/postgres.c:1215
#11 0x000000000078c362 in PostgresMain (argc=<optimized out>, argv=argv@entry=0x149a548, dbname=0x149a2d8 "regression", username=<optimized out>) at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/tcop/postgres.c:4256
#12 0x00000000004805f8 in BackendRun (port=<optimized out>, port=<optimized out>) at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/postmaster/postmaster.c:4378
#13 BackendStartup (port=0x1490320) at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/postmaster/postmaster.c:4069
#14 ServerLoop () at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/postmaster/postmaster.c:1699
#15 0x0000000000713f60 in PostmasterMain (argc=argc@entry=8, argv=argv@entry=0x146b6d0) at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/postmaster/postmaster.c:1372
#16 0x0000000000481a63 in main (argc=8, argv=0x146b6d0) at /home/ec2-user/bf/root/HEAD/pgsql.build/../pgsql/src/backend/main/main.c:228


			regards, tom lane




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pgsql: Detach constraints when partitions are detached
  2019-01-24 03:02 pgsql: Detach constraints when partitions are detached Alvaro Herrera <alvherre@alvh.no-ip.org>
  2019-01-24 04:58 ` Re: pgsql: Detach constraints when partitions are detached Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-01-24 05:22   ` Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
  2019-01-24 14:28     ` Re: pgsql: Detach constraints when partitions are detached Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Amit Langote @ 2019-01-24 05:22 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: pgsql-committers@lists.postgresql.org

On 2019/01/24 13:58, Tom Lane wrote:
> Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
>> Detach constraints when partitions are detached
> 
> Hm ... it looks like this fails under -DRELCACHE_FORCE_RELEASE:

Oops, sorry.  This is why:

         index_close(idx, NoLock);
...
+        if (!idx->rd_index->indisprimary && !idx->rd_index->indisunique)
+            continue;

Attached a fix.

Thanks,
Amit

Attachments:

ae366aa577-fixup.patch (text/plain, 1.1K) download diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 738c178107..98366a2d5b 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -15095,6 +15095,7 @@ ATExecDetachPartition(Relation rel, RangeVar *name) { Oid idxid = lfirst_oid(cell); Relation idx; + bool detachConstraint = false; Oid constrOid; if (!has_superclass(idxid)) @@ -15106,14 +15107,18 @@ ATExecDetachPartition(Relation rel, RangeVar *name) idx = index_open(idxid, AccessExclusiveLock); IndexSetParentIndex(idx, InvalidOid); update_relispartition(classRel, idxid, false); - index_close(idx, NoLock); /* * Detach any constraints associated with the index too. Only UNIQUE * and PRIMARY KEY index constraints can be inherited, so no need * to check for others. */ - if (!idx->rd_index->indisprimary && !idx->rd_index->indisunique) + if (idx->rd_index->indisprimary || idx->rd_index->indisunique) + detachConstraint = true; + + index_close(idx, NoLock); + + if (!detachConstraint) continue; constrOid = get_relation_idx_constraint_oid(RelationGetRelid(partRel),
^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: pgsql: Detach constraints when partitions are detached
  2019-01-24 03:02 pgsql: Detach constraints when partitions are detached Alvaro Herrera <alvherre@alvh.no-ip.org>
  2019-01-24 04:58 ` Re: pgsql: Detach constraints when partitions are detached Tom Lane <tgl@sss.pgh.pa.us>
  2019-01-24 05:22   ` Re: pgsql: Detach constraints when partitions are detached Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
@ 2019-01-24 14:28     ` Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Alvaro Herrera @ 2019-01-24 14:28 UTC (permalink / raw)
  To: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-committers@lists.postgresql.org, Pg Hackers <pgsql-hackers@lists.postgresql.org>

CC'ing -hackers.

On 2019-Jan-24, Amit Langote wrote:

> On 2019/01/24 13:58, Tom Lane wrote:
> > Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> >> Detach constraints when partitions are detached
> > 
> > Hm ... it looks like this fails under -DRELCACHE_FORCE_RELEASE:
> 
> Oops, sorry.  This is why:
> 
>          index_close(idx, NoLock);
> ...
> +        if (!idx->rd_index->indisprimary && !idx->rd_index->indisunique)
> +            continue;
> 
> Attached a fix.

Mumble.  I changed course here and went for simpler coding instead.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Detach constraints when partitions are detached
@ 2019-01-24 03:02 Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Alvaro Herrera @ 2019-01-24 03:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Detach constraints when partitions are detached

I (Álvaro) forgot to do this in eb7ed3f30634, leading to undroppable
constraints after partitions are detached.  Repair.

Reported-by: Amit Langote
Author: Amit Langote
Discussion: https://postgr.es/m/c1c9b688-b886-84f7-4048-1e4ebe9b1d06@lab.ntt.co.jp

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/00376eaa2ec28db92efe349a895164b0e31b314c

Modified Files
--------------
src/backend/commands/tablecmds.c       | 18 ++++++++++++++++++
src/test/regress/expected/indexing.out | 15 +++++++++++++++
src/test/regress/sql/indexing.sql      | 14 ++++++++++++++
3 files changed, 47 insertions(+)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2019-01-24 14:28 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-01-24 03:02 pgsql: Detach constraints when partitions are detached Alvaro Herrera <alvherre@alvh.no-ip.org>
2019-01-24 04:58 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-01-24 05:22   ` Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
2019-01-24 14:28     ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-01-24 03:02 pgsql: Detach constraints when partitions are detached Alvaro Herrera <alvherre@alvh.no-ip.org>

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