Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mVg7j-0002Ku-Mh for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Sep 2021 20:24:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mVg7i-0000f2-8w for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Sep 2021 20:24:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mVg7i-0000eu-18 for pgsql-hackers@lists.postgresql.org; Wed, 29 Sep 2021 20:24:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mVg7Y-0005Xy-DF; Wed, 29 Sep 2021 20:24:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 18TKO36B2999547; Wed, 29 Sep 2021 16:24:03 -0400 From: Tom Lane To: David Rowley cc: Jaime Casanova , pgsql-hackers@postgresql.org Subject: Re: jsonb crash In-reply-to: <2998377.1632945612@sss.pgh.pa.us> References: <20210929185544.GB24346@ahch-to> <2998377.1632945612@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 29 Sep 2021 16:00:12 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2999545.1632947043.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 29 Sep 2021 16:24:03 -0400 Message-ID: <2999546.1632947043@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > I think this must be a memoize bug. AFAICS, nowhere in this query > can we be processing a non-null JSONB value, so what are we doing > in jsonb_hash? Something down-stack must have lost the information > that the Datum is actually null. After further inspection, "what are we doing in jsonb_hash?" is indeed a relevant question, but it seems like it's a type mismatch not a nullness issue. EXPLAIN VERBOSE shows -> Memoize (cost=3D0.01..1.96 rows=3D1 width=3D4) Output: subq_0.c5 Cache Key: ref_0.c, ref_0.a -> Subquery Scan on subq_0 (cost=3D0.00..1.95 rows=3D1 width=3D= 4) Output: subq_0.c5 Filter: (CASE WHEN (subq_0.c5 < 2) THEN NULL::jsonb ELSE NU= LL::jsonb END ? ref_0.c) -> Limit (cost=3D0.00..0.78 rows=3D78 width=3D4) Output: (ref_0.a) -> Function Scan on pg_catalog.generate_series sampl= e_0 (cost=3D0.00..3.00 rows=3D300 width=3D4) Output: ref_0.a Function Call: generate_series(1, 300) so unless the "Cache Key" output is a complete lie, the cache key types we should be concerned with are text and integer. The Datum that's being passed to jsonb_hash looks suspiciously like it is a text value '0000', too, which matches the "c" value from the first row of pagg_tab_ml. I now think some part of Memoize is looking in completely the wrong place to discover the cache key datatypes. regards, tom lane