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 1gwCj0-0001Sh-BN for pgsql-general@arkaria.postgresql.org; Tue, 19 Feb 2019 21:14:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwCiy-0004HI-6e for pgsql-general@arkaria.postgresql.org; Tue, 19 Feb 2019 21:14:44 +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 1gwCix-0004HB-UJ for pgsql-general@lists.postgresql.org; Tue, 19 Feb 2019 21:14:43 +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 1gwCiv-0008Oa-JF for pgsql-general@postgresql.org; Tue, 19 Feb 2019 21:14:43 +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 x1JLEbbJ031591; Tue, 19 Feb 2019 16:14:37 -0500 From: Tom Lane To: Samuel Williams cc: pgsql-general Subject: Re: Partial index on JSON column In-reply-to: References: Comments: In-reply-to Samuel Williams message dated "Wed, 20 Feb 2019 09:41:40 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31589.1550610877.1@sss.pgh.pa.us> Date: Tue, 19 Feb 2019 16:14:37 -0500 Message-ID: <31590.1550610877@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Samuel Williams writes: > When I do this query: > EXPLAIN SELECT COUNT(*) FROM "user_event" WHERE ((parameters ->> > 'suggestion_id'::text)::integer = 26) AND what = 'suggestion_notification'; > It's slow. I need to explicitly add the NULL constraint: Try it like EXPLAIN SELECT COUNT(*) FROM "user_event" WHERE ((parameters ->> 'suggestion_id'::text) = '26') AND what = 'suggestion_notification'; I don't think we assume that CoerceViaIO is strict, and without that the deduction that the value couldn't be null doesn't hold. In any case you're better off without the runtime type conversion: that isn't doing much for you except raising the odds of getting an error. regards, tom lane