Re: working around JSONB's lack of stats?

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: working around JSONB's lack of stats?
Date: 2015-01-28 23:03:06
Message-ID: 54C96AAA.9050901@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 01/28/2015 11:48 AM, Tomas Vondra wrote:
> On 27.1.2015 08:06, Josh Berkus wrote:
>> Folks,
>>
> ...
>>
>> On a normal column, I'd raise n_distinct to reflect the higher
>> selecivity of the search terms. However, since @> uses contsel,
>> n_distinct is ignored. Anyone know a clever workaround I don't
>> currently see?
>
> I don't see any reasonable workaround :-(
>
> ISTM we'll have to invent a way to collect useful stats about contents
> of JSON/JSONB documents. JSONB is cool, but at the moment we're mostly
> relying on defaults that may be reasonable, but still misfire in many
> cases. Do we have any ideas of how that might work?
>
> We're already collecting stats about contents of arrays, and maybe we
> could do something similar for JSONB? The nested nature of JSON makes
> that rather incompatible with the flat MCV/histogram stats, though.

Well, I was thinking about this.

We already have most_common_elem (MCE) for arrays and tsearch. What if
we put JSONB's most common top-level keys (or array elements, depending)
in the MCE array? Then we could still apply a simple rule for any path
criteria below the top-level keys, say assuming that any sub-key
criteria would match 10% of the time. While it wouldn't be perfect, it
would be better than what we have now.

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Peter Geoghegan 2015-01-28 23:34:41 Re: working around JSONB's lack of stats?
Previous Message Tomas Vondra 2015-01-28 19:48:02 Re: working around JSONB's lack of stats?