Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gMCdc-0001Mr-Rt for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Nov 2018 13:52:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gMCda-00057v-Nz for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Nov 2018 13:52:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gMCda-00057o-C9 for pgsql-hackers@lists.postgresql.org; Mon, 12 Nov 2018 13:52:22 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gMCdX-0002PN-72 for pgsql-hackers@lists.postgresql.org; Mon, 12 Nov 2018 13:52:20 +0000 Received: by mail-wr1-x442.google.com with SMTP id u5-v6so4163834wrn.9 for ; Mon, 12 Nov 2018 05:52:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=strobel.info; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=t1k8sd/ztvAJj61akziEpLOpDKglVNYGNzMSmy2tsFs=; b=i9SwPRib8w50o2ExyWzmyH5CKYemHHD0atFmKUgYR4uXwaSBHlPfq2/uB7g+k3LlVZ 37tKBcsbIAsUOR/iZitTRtyTZzHE8+e6WlacZe7VUoTvSdH7Oj6yIaXKOuIPSQd9/2Kr jzJpkA1hbr7PXS1OJbiFo2hpWVc1eyNKay6BE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=t1k8sd/ztvAJj61akziEpLOpDKglVNYGNzMSmy2tsFs=; b=eLG3P/tRBYTJndqkJHf3qLS1xUVFCRQhAeNbmvaCsEJaHVNfh0mFxUO+xR/ynUBYdp X/2/+sPWO4LD1wQVdlB6Vvb0VE68j/qg33eLVHsNuwHrD/J9MEwQtsjAV91UIf6xhtDx Kd+E4QLPew9i/ytH6EWDn7UhAciV2k9Ueqjy6PITScUMha4RoLD4advFh2IDe03GDCrB bGZNRaK+82rPnUBvtJasmSrpquPoXFGMeL1ZBcNBqjI1kqvX2NvUIG0oZmKP7MMYgZs7 bc9WEyGF6GO8v2ILLmIlYct0iKzWUyOV/Bs3FrmATfY0gf61iheqscuERdddpRwJO7A5 V6yg== X-Gm-Message-State: AGRZ1gLEmR4WJi3gev+5rdGj0bpzaPzBaMTOczzSTbdunaujMMKezrRE pOnri7/sPoy7PULMXtNIqCJQ/pailzcMfA== X-Google-Smtp-Source: AJdET5fnoAfeZTaG48AHJxEXICsLfQPDmIBioqVBRGQhwjMWpdCXY9Tint+q3WnBgjCul9e4QLvBEg== X-Received: by 2002:adf:b109:: with SMTP id l9-v6mr1028574wra.290.1542030737047; Mon, 12 Nov 2018 05:52:17 -0800 (PST) Received: from Juergens-MacBook.local (77.119.131.201.wireless.dyn.drei.com. [77.119.131.201]) by smtp.gmail.com with ESMTPSA id l186-v6sm23943437wma.13.2018.11.12.05.52.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 05:52:16 -0800 (PST) Subject: Re: BUG #15212: Default values in partition tables don't work as expected and allow NOT NULL violation To: Tom Lane , Alvaro Herrera Cc: Amit Langote , Amit Langote , Ashutosh Bapat , PostgreSQL Hackers References: <20181109170712.pfn55lab5j7oae4v@alvherre.pgsql> <29152.1541802819@sss.pgh.pa.us> From: =?UTF-8?Q?J=c3=bcrgen_Strobel?= Message-ID: Date: Mon, 12 Nov 2018 14:52:11 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <29152.1541802819@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2018-11-09 23:33, Tom Lane wrote: > Alvaro Herrera writes: >> On 2018-Nov-09, Jürgen Strobel wrote: >>> Regarding your example, what I expected is that *both* inserts would >>> consistently result in a tuple of (1, 42) since p should route the >>> insert to p1 and use p1's defaults. The current inconsistent behavior is >>> the heart of the bug. > >> I think that would be sensible behavior, as long as the partition >> doesn't override values for the partitioning column -- i.e. if the >> default values don't re-route the tuple to another partition, I think we >> should use the partition's default rather than the parent. This says we >> should expand defaults after routing. > > I'd argue not, actually. I think there is plausible precedent in > updatable views, where what we use is the defaults associated with the > view, not the underlying table. Correspondingly, what ought to govern > in a partitioned insert is the defaults associated with the table actually > named in the insert command, never mind what its partitions might say. > That is useful for many situations, and it avoids all the logical > inconsistencies you get into if you find that the defaults associated > with some partition would force re-routing elsewhere. > > In any case, you can't make this happen without basically blowing up > default processing altogether. Defaults are currently expanded by the > planner, and pretty early too. To make it work like the OP wishes, > we'd have to insert them sometime late in the executor. > >> In any case it seems really hard to see this is as a bug that we would >> fix in back-branches. > > Backwards compatibility considerations would prevent that in any case. I don't really think the view comparison holds water. Views are layered above tables without affecting them by design, but partitions are intrinsic parts of sharded tables and only make sense as a whole. With all due respect I suspect your view of implementation issues biases your judgement here. For me the partition's default handling was completely unexpected, especially with the documentation silent about default-applying behavior, and inconsistent with how check constraints work with partitions. Maybe there's another way to implement this. Like mark early and apply defaults later, and handle meta data like constraints. Sorry if this sounds stupid. Btw I fully agree about not back-patching changes to this, but a documentation update would be nice. Best regards, Jürgen