Re: Partial index on JSON column

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Samuel Williams <space(dot)ship(dot)traveller(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Partial index on JSON column
Date: 2019-02-19 21:14:37
Message-ID: 31590.1550610877@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Samuel Williams <space(dot)ship(dot)traveller(at)gmail(dot)com> 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Samuel Williams 2019-02-19 21:24:44 Re: Partial index on JSON column
Previous Message Reid Thompson 2019-02-19 20:51:16 PG 9.6 managed fail over of master, how do i manage a pg_logical subscriber