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 1hl16G-0000ob-Fd for pgsql-bugs@arkaria.postgresql.org; Wed, 10 Jul 2019 01:08:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hl16E-0000Mb-R0 for pgsql-bugs@arkaria.postgresql.org; Wed, 10 Jul 2019 01:08:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hl16E-0000FP-Gy for pgsql-bugs@lists.postgresql.org; Wed, 10 Jul 2019 01:08:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hl16C-0005YH-9j for pgsql-bugs@lists.postgresql.org; Wed, 10 Jul 2019 01:08:46 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x6A18dVS009289; Tue, 9 Jul 2019 21:08:39 -0400 From: Tom Lane To: Manuel Rigger cc: PostgreSQL mailing lists Subject: Re: ERROR: found unexpected null value in index In-reply-to: References: Comments: In-reply-to Manuel Rigger message dated "Wed, 10 Jul 2019 01:51:50 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9287.1562720919.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 09 Jul 2019 21:08:39 -0400 Message-ID: <9288.1562720919@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Manuel Rigger writes: > CREATE TABLE t0(c0 TEXT); > INSERT INTO t0(c0) VALUES('b'), ('a'); > ANALYZE t0; > INSERT INTO t0(c0) VALUES (NULL); > UPDATE t0 SET c0 =3D 'a'; > CREATE INDEX i0 ON t0(c0); > SELECT * FROM t0 WHERE 'baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' > = t0.c0; > -- unexpected: ERROR: found unexpected null value in index "i0" Nifty. As before, the way to make this reproducible is to do it with another open transaction holding a snapshot, so that the NULL entry has to be reflected in the index. (I'm not sure why the HOT-update exception doesn't apply here, but apparently it doesn't.) That is, it's sufficient to set up one session with begin transaction isolation level serializable; select * from some_table; and then run the above script in another session. The error is coming from the planner's get_actual_variable_range: /* Shouldn't have got a null, but be careful */ if (isnull[0]) elog(ERROR, "found unexpected null value in index = \"%s\"", RelationGetRelationName(indexRel)); and I think it's entirely within its rights to complain, because it set up the scan key to reject nulls. In short, somebody seems to have broken btrees' processing of SK_ISNULL | SK_SEARCHNOTNULL scankeys, and they broke it in v11, because prior versions don't show this failure. regards, tom lane