Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xGbqV-00000002VgL-2D5X for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Oct 2026 12:43:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xGbqR-0000000E3Pc-3BNy for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Oct 2026 12:43:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xGbqQ-0000000E3PU-3K8g for pgsql-hackers@lists.postgresql.org; Tue, 13 Oct 2026 12:43:03 +0000 Received: from fout-b3-smtp.messagingengine.com ([202.12.124.146]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xGbqN-00000001s8B-2TIw for pgsql-hackers@lists.postgresql.org; Tue, 13 Oct 2026 12:43:02 +0000 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.stl.internal (Postfix) with ESMTP id 321AA1D00094 for ; Tue, 13 Oct 2026 08:42:57 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 13 Oct 2026 08:42:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kurilemu.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to; s=fm3; t=1791895377; x= 1791981777; bh=3FUhtDHUvXU9ztCa/Ga+2F23gmpJ3DsqwC1CQzU+xgc=; b=R pJerBTVKvquRoopQBBKHJy0xwtmOqIs7yhVShmU9uLkQCk5mgm4REaU3wOaQznFe rxs9LMZk1LrfqAUa9qnyQ0BIXcCyJ8XOfZ5k+AVA4UEn1c2jRliuIkeY52zG3u6V dlzDgoiL1xmjkk8U/d3muU6TvGYqe8uez0GaRRZU0i/NuRosSdkazPY9Uh6l7Txj d9IpqZTt6zEXEzNW0HSFRjKPB6Ql+I0K2giqvVSylHNbZhZNsITetYUI7XOr4j3Y 40IXPyBpIfRbU1KMNTfdC8XKWsEmuohuzXRfZiexICA5P/L69DsgdDEfdnjPIp3y k+E7PEqZf/Tl/3SjXAG8g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1791895377; x=1791981777; bh=3 FUhtDHUvXU9ztCa/Ga+2F23gmpJ3DsqwC1CQzU+xgc=; b=JgxqSKVflOetzAOGS YSbd2DEGndiKJ2n+GXtuCeEnoz9AaHHGlXUcnyiQjgOvuI5QUOXFn6oA0yvvCf7q cWyX7ONE7vXlDCzVnWWpw9v4Z1Y+zTR2I9O6DCKxOg4o9C1+aG2BqGLTkFDaGP4p LT35dlVyiiXAUYkjzyRS1S7xps4IcL/3QGOs+qwfKDvES1d21OSp2kmqev3IPoSS DuJxsQNoSayWdG/XtyBufPafU4dfIYSy0rRG5SNl97aJICSfqOoH0bBLXSTZ+YW8 sh8DiPsvQD7uT82Ra5owfkfeJwwA5GkAA/y/Wm/04UzRRRHIw3x27swqsJ4mLIED 4Ic7g== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-06; repo=github.com/dkim2wg/interop; date=2026-10-04; sw=lmtpprox; action=sign d=kurilemu.de a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1791895377; d=kurilemu.de; mf=PGFsdmhlcnJlQGt1cmlsZW11LmRlPg==; rt=PHBnc3FsLWhhY2tlcnNAbGlzdHMucG9zdGdyZXNxbC5vcmc+; s=fm3:rsa-sha256:x/aOnzo4XzbsSkzZjtclffaTOX7W7nbiqoe9k02vV719F7X NoBc9jJ+ZXTmeUSW32ywjARZlILHLUcte8OjLUgy+ouCMprSk+kC4cD2tFNfx/BI 0jHhgfL2pIuVNAUZc7yhGPvmf6ViUpsmFtmXPWbLPwgl2VimdCf0AUSb4MuAOzt1 a/Da+QU/2pUXltZ+TAT8IvTstM7gXG9jtpgUoHQAXRPe1PjZyiVAAkgVYyYbsh8R tMfU0wZQBT7wvbeN4z/cWgE7LgNAf2oFP01WtiAWaHP897QjkUmPQoQta2+nCnll h1FzXMP5bSv9QLcb4euN0aRFd60eIy/kNchO5qA==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-06; repo=github.com/dkim2wg/interop; date=2026-10-04; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-disposition,content-transfer-encoding, content-type,date,feedback-id,from,in-reply-to,message-id, mime-version,subject,to; Message-Instance: m=1; h=sha256:WN9yHMCbwcABiVdzgDk1eVqf4Y4521w8tjUiZRwuL1A=:CttzPE5dWEbeLW8WuEFaHGadgWcrd0rMISmBsAngZ/Q=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTG3vS0Ce8zE2hbLck25hNDIgoenHf4Rs2XAcEPorjOWsY49sDVnWGq59zzodbhxZq oc3IUA7IJOiF/GT0yr5gYxjyCpegJcJjxeZXZ22S9d8tj++B19x2ZkFHfTd9Os+JleMNsZ NUR4+yhxQGSAYJmVvUN2nWsu8Aby947l4/sxS662UkUKagF6KGcN3NerX4PuhbzHivNhHi yhV9rCXdtYIqyQ7rqVou4k4m56B5fxrtgHCmq+q/ZdAOBlypvrbseZDhA3+IgEIz3pnyqN AMlnTDuugj2v7aPxdLR4NRzwNnjFI+qZT2kckXv6pz5sonIB3TvC1JhqWCFP72PbMRgeHM iLw//NhsNnboVOi6KhnKr6dF+hAKHJMdh8phcP6K7SDvCtGA6TpSoaI2d+ac5tnqq6ZEK9 B2S2YfuejHA6ddd+PJL3nXS6XbmUGSpmJ1zE9r+U0wetz5RvlE0AU9jzF3VdiO4mmS58kg YymPwugjFaNRpl9+yGHXflfMM0u6Ng96iflwXZr3T5cWqk6VqrAJsczbtOHV5pxWxKbm/r eyLq5uLP4h0FRz6urwM7Llo9J7PHkn0QowaxZOPDHqzv4Htz+aaqPzxlmcrIjB9kf1FxrH hzZG1tfq4jSD0UcDKX+oi7N8SQUyD2Djd0SGPXOY41S6QnEkV/NvMRJ+tYDg X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Oct 2026 08:42:56 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1791895371; bh=CttzPE5dWEbeLW8WuEFaHGadgWcrd0rMISmBsAngZ/Q=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=OfLDOY0QxThkyweL4hZAZBbn/pGhUvfgYo1W1TwaPuyHdBsO0smKwuphToT346/11 yvDQ5vRHuGI9TBAvbq0zHUflsc4UxtxWv3Cry8OKO1rJ1HqrIRCUZQhXkjuGIumKny E3uey2jHVooZb6DCKtaZrJ492XQgdgLKOyuzv2FssPRAil+9Ptey0QH3CVCOUlrPkQ 8tbbTnDFTYUQPggMZqLXyExk5rvwmJpRR3jUx04cH2ytgmL8y11Ud7peMgL/rD6RGF 3kMzhE5MfdJ6mc+7gcjUmWgZwwwh9JlC+wdVZctIFX/6phhgiTa1HQZjzg145AHyek vJXBxV/Dvgdrg== Received: by ida.kurilemu.internal (Postfix, from userid 1000) id AE398B00198; Tue, 13 Oct 2026 14:42:51 +0200 (CEST) Date: Tue, 13 Oct 2026 14:42:51 +0200 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Richard Guo Cc: pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Don't trust NOT NULL on virtual generated columns of partitioned Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2026-Oct-10, Richard Guo wrote: > Don't trust NOT NULL on virtual generated columns of partitioned tables [...] > That is not safe for a partitioned table. A partition can have a > generation expression different from its parent's, and it enforces the > NOT NULL constraint against its own expression, whereas a query on the > parent computes the column using the parent's expression. So the > column can be NULL when read through the parent despite the > constraint, and the anti-join would then produce wrong results, as it > returns rows that NOT IN should have rejected. I find this very surprising. Are we sure that it makes sense for a partition to have a generating expression that differs from the one in the parent table? Copying from the test case you added, CREATE TABLE gtestnn_parent2 (a int NOT NULL, b int GENERATED ALWAYS AS (nullif(a, 0)) VIRTUAL NOT NULL) PARTITION BY LIST (a); CREATE TABLE gtestnn_child2 PARTITION OF gtestnn_parent2 (b GENERATED ALWAYS AS (a + 1) VIRTUAL) FOR VALUES IN (0); INSERT INTO gtestnn_parent2 VALUES (0); we read a NULL value from a column that's marked as not-null, which shouldn't happen. alvherre=# select * from gtestnn_parent2 ; a | b ---+-------- 0 | (null) (1 row) alvherre=# \d gtestnn_parent2 Partitioned table "public.gtestnn_parent2" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+------------------------------------ a | integer | | not null | b | integer | | not null | generated always as (NULLIF(a, 0)) Partition key: LIST (a) Number of partitions: 1 (Use \d+ to list them.) The row is of course different if I read it directly from the partition. alvherre=# select * from gtestnn_child2 ; a | b ---+--- 0 | 1 (1 row) I didn't try but I imagine that allowing partitions to have a different generating expression than the parent can break all kinds of constraint, not just not-null ones, if generating expressions are "broken" enough. Maybe we should disallow expressions to be different, and force users to use STORED virtual columns if they want to do that. This seems dangerous. Alternatively, you could argue that at read time the row should get its virtual column values using the expressions from the children rather than for the parent. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "Las navajas y los monos deben estar siempre distantes" (Germán Poo)