Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gGyHD-0001FB-Ly for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Oct 2018 03:31:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gGyH9-0004Yr-T7 for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Oct 2018 03:31:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gGyH7-0004Yk-Pz for pgsql-bugs@lists.postgresql.org; Mon, 29 Oct 2018 03:31:35 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gGyGz-0005YS-8o for pgsql-bugs@lists.postgresql.org; Mon, 29 Oct 2018 03:31:32 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 6144DE9F; Sun, 28 Oct 2018 23:31:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sun, 28 Oct 2018 23:31:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=m6YmUEomJpJwG1q+VxCaeRUrQ3F ARulSbpqSp7d1sU0=; b=dATsdJr1UP/o/oV7QWIPS1wezbgxI2MVZg5ZRupkVwi U3TM9WcpN4fGxhsXkdSGR90jNLDtnRUMt0b6zsRXrO3ILKQdfqcl7Pvm2HNzRQAr oWO4aMGOCzF30NXcw1O3SyFWTmI2Q+BC4+mQNfliWuuFzhUWZeeV/g/xXkq1fDut CRvBM8fF2dNrIHWJIuMM1/+amJmk1GUbUb7M9pBO+EXwcp6LK0KDXU+k27c0GKsN cq2oNGvj3+CtQsIQ669po7dCuwQlgsihnzXy1zUh1a5UDNWLqI5graXvjr3IwvAU zfI9k6lUqDNgpCNU0lVwQr7rwi2SWfNIu1KEqh1de8g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=m6YmUE omJpJwG1q+VxCaeRUrQ3FARulSbpqSp7d1sU0=; b=lKXvKRIR8GQVl2roK7aaGP 0W4vGmZWB5+RRbKumqDptCICGK2wVamKMlq/GZbPw3I7GG8MXylIeR7PXTr70B21 UoFAQ/472VvtoekPkuwIbAIrip5v3ASzCjOunySWIJg1dJCe03lScGuKhnmD6p9v TAE8yQikEG8MEmdW8E9iUYr2XUsSA5B2rceiig/bjuiu+UfLBv9cMtTHd4ofdQcK LYZH2xonVuyHq7WDQcfof/OZpxczJpEkUiTn809Qx9bNQfZPhLGXtZn4ZkxTzzLA al5bXgxs4Qcas5NDnr9crlUwLzszjyiA7NB3JBPXBRlhTWMiALkXZLGul56x/xlA == X-ME-Sender: X-ME-Proxy: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id 40D5CE43AC; Sun, 28 Oct 2018 23:31:20 -0400 (EDT) Date: Mon, 29 Oct 2018 12:31:17 +0900 From: Michael Paquier To: Amit Langote Cc: Tom Lane , skaurus@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition Message-ID: <20181029033117.GE14242@paquier.xyz> References: <15437-3fe01ee66bd1bae1@postgresql.org> <8213.1539917571@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ey/N+yb7u/X9mFhi" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --ey/N+yb7u/X9mFhi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 19, 2018 at 12:45:33PM +0900, Amit Langote wrote: > On 2018/10/19 11:52, Tom Lane wrote: >> Hmm ... I wonder if we shouldn't do CheckTableNotInUse for *both* cases, >> is_partition or no? >=20 > Yeah, that would be better robustness-wise, but I couldn't think of a case > where not doing CheckTableNotInUse for the !is_partition case would be > problematic. Adding an inheritance child doesn't change the relcache > content of the parent table, but for partitioning it does. Maybe I'm > missing something though. I am pretty sure that this patch would make some users unhappy. You break cases where one may want to add automatically inherited tables. Here is one example which works normally, but not with the patch (imagine that the name of the relation is based on some time-related data, like beginning filling a table for a new month or such): create table aa (a int); create function add_inh_func () returns trigger language plpgsql as $$ begin execute 'create table aa2 (a int) inherits (aa)'; return NULL; end $$; create trigger add_inh_trig before insert on aa for each statement execute procedure add_inh_func(); insert into aa values (1); drop table aa cascade; drop function add_inh_func (); In the case of a partition, the execution state relies on the data inserted, so the restriction sounds fine to me. If one tries to attach a partition after creating a table you actually get an error: ERROR: 55006: cannot ALTER TABLE "check_not_in_use" because it is being used by active queries in this session CONTEXT: SQL statement "alter table check_not_in_use attach partition check_not_in_use1 for values IN (1);" You can just trigger that scenario by executing the following queries: create table check_not_in_use (a int) partition by list (a); create function add_part_func () returns trigger language plpgsql as $$ begin execute 'create table check_not_in_use1 (a int)'; execute 'alter table check_not_in_use attach partition check_not_in_use1 for values IN (1);'; return null; end $$; create trigger add_part_trig before insert on check_not_in_use for each statement execute procedure add_part_func(); insert into check_not_in_use values (1); > Attached updated patch adds the check for both cases, although I'm not > sure what the error message text added by the patch should look like. Is > the following OK? >=20 > CheckTableNotInUse(relation, "CREATE TABLE INHERITS / PARTITION OF"); Other callers of CheckTableNotInUse() use command tags, which is inconsistent here, still I cannot think of anything better than CREATE TABLE "%s" PARTITION OF or: CREATE TABLE .. PARTITION OF -- Michael --ey/N+yb7u/X9mFhi Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlvWfwUACgkQnvQgOdby QH19tQ//UCSb5lD7OWAWNn708UzlNQo06gPf/sWBzOiQ066Q5o0G1wtCNIc5piky IRQV35bK3YTjc01VzPi/nHUX88eqoL5nOh+oERpVB5nwrHYtjdX4YTeLpYUQntZz yCREPBCVO/MMBDWImMk4IwOAoHgkNBKFp82XaLLjAle620ADHZOrsGg5m4041/5x D5X+/J8UrJM8bo940neXn1cm6HhaT8tVmZksGB8J/ux/zqRpT9PeJefwSaM68LKC sITjhBK/9CGCdl9TnOmuAtWFBX7BLub2A+/AimKUIVwD5JYPRMan+TfIIhi0V6dR VCdAagBgMcGJzpURpaRWOiV7O++UwbyT07LCQuKroBlKQsk7ZUQccVJ4yVD5ij5B IzFjJFJVfQnuAHhBYl2zybHtxFla72pui5698UUCWlHvDyE/gZhkk0ZXyMrGd2wG JcEcE3f81u3m0dRAlN8WGF50gkROOpg90/E6MUwvTgwpZIAh1lUm6KCjydcXLTtw 2gDc9VWecz0+QuKVpvZvUhYKB1Q1yUu079CnL82Vt6FYzmTSrpsKn30zDFN8zh2e 9WjgJn0tmkV7VwWdCAVjQG/E9TIqnM2H64xenJTHKbMUyTwAaDsk0DcDuZ5TFebA CKeJGgonb8aBbk7nWIHEJO5xks8uoZ4d2FpVTYOEhRDP9SXxaWY= =Xb9t -----END PGP SIGNATURE----- --ey/N+yb7u/X9mFhi--