Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YGbds-0005ZY-FE for pgsql-performance@arkaria.postgresql.org; Wed, 28 Jan 2015 23:03:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YGbdr-0004Rh-G0 for pgsql-performance@arkaria.postgresql.org; Wed, 28 Jan 2015 23:03:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YGbdp-0004RY-DB for pgsql-performance@postgresql.org; Wed, 28 Jan 2015 23:03:21 +0000 Received: from mx-out.zmailcloud.com ([192.198.85.98] helo=mx-out-1.zmailcloud.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YGbde-0004s9-U0 for pgsql-performance@postgresql.org; Wed, 28 Jan 2015 23:03:19 +0000 Received: from smtp.01.com (smtp.01.com [10.10.0.43]) by mx-out-1.zmailcloud.com (Postfix) with ESMTP id B39B1563ECC for ; Wed, 28 Jan 2015 17:03:08 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id B01066029C for ; Wed, 28 Jan 2015 17:03:08 -0600 (CST) X-Virus-Scanned: amavisd-new at smtp-out-2.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-2.01.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9uIfLBm7FNL7 for ; Wed, 28 Jan 2015 17:03:08 -0600 (CST) Received: from smtp.01.com (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 910CE6029D for ; Wed, 28 Jan 2015 17:03:08 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 7BB976029C for ; Wed, 28 Jan 2015 17:03:08 -0600 (CST) X-Virus-Scanned: amavisd-new at smtp-out-2.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-2.01.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id LZUwaubsmbAN for ; Wed, 28 Jan 2015 17:03:08 -0600 (CST) Received: from [172.47.23.103] (50-0-89-53.dsl.dynamic.fusionbroadband.com [50.0.89.53]) by smtp-out-2.01.com (Postfix) with ESMTPSA id 23E0F6029F for ; Wed, 28 Jan 2015 17:03:07 -0600 (CST) Message-ID: <54C96AAA.9050901@agliodbs.com> Date: Wed, 28 Jan 2015 15:03:06 -0800 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: working around JSONB's lack of stats? References: <54C738E1.8080405@agliodbs.com> <54C93CF2.3020600@2ndquadrant.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org 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 -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance