Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YHMxl-0007mX-4H for pgsql-performance@arkaria.postgresql.org; Sat, 31 Jan 2015 01:35:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YHMxk-0000y2-Gq for pgsql-performance@arkaria.postgresql.org; Sat, 31 Jan 2015 01:35:04 +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 1YHMxj-0000xp-Cx for pgsql-performance@postgresql.org; Sat, 31 Jan 2015 01:35:03 +0000 Received: from mail-bn1on0659.outbound.protection.outlook.com ([2a01:111:f400:fc10::659] helo=na01-bn1-obe.outbound.protection.outlook.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YHMxe-0001vT-8t for pgsql-performance@postgresql.org; Sat, 31 Jan 2015 01:35:02 +0000 Received: from decina.local (24.55.12.91) by BY1PR11MB0342.namprd11.prod.outlook.com (25.160.206.155) with Microsoft SMTP Server (TLS) id 15.1.75.20; Sat, 31 Jan 2015 01:34:50 +0000 Message-ID: <54CC3130.5030604@BlueTreble.com> Date: Fri, 30 Jan 2015 19:34:40 -0600 From: Jim Nasby User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Josh Berkus , Peter Geoghegan CC: "pgsql-performance@postgresql.org" Subject: Re: working around JSONB's lack of stats? References: <54C738E1.8080405@agliodbs.com> <54C93CF2.3020600@2ndquadrant.com> <54C96AAA.9050901@agliodbs.com> <54C973D3.6000808@agliodbs.com> <54CBE902.6000309@agliodbs.com> In-Reply-To: <54CBE902.6000309@agliodbs.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [24.55.12.91] X-ClientProxiedBy: BLUPR08CA0072.namprd08.prod.outlook.com (10.141.200.52) To BY1PR11MB0342.namprd11.prod.outlook.com (25.160.206.155) Authentication-Results: postgresql.org; dkim=none (message not signed) header.d=none; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BY1PR11MB0342; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004); SRVR:BY1PR11MB0342; X-Forefront-PRVS: 0473A03F3F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(51704005)(377454003)(24454002)(479174004)(76176999)(54356999)(65816999)(83506001)(15975445007)(50986999)(59896002)(33656002)(92566002)(87266999)(47776003)(42186005)(19580405001)(50466002)(86362001)(64126003)(23676002)(77156002)(62966003)(65806001)(46102003)(66066001)(36756003)(2950100001)(93886004)(87976001)(65956001)(19580395003)(122386002)(40100003)(85282002)(336755003)(18886065003); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR11MB0342; H:decina.local; FPR:; SPF:None; MLV:sfv; LANG:en; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:BY1PR11MB0342; X-OriginatorOrg: bluetreble.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2015 01:34:50.3272 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR11MB0342 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 1/30/15 2:26 PM, Josh Berkus wrote: > On 01/28/2015 03:50 PM, Peter Geoghegan wrote: >> On Wed, Jan 28, 2015 at 3:42 PM, Josh Berkus wrote: >>> jsonb_col @> '[ "key1" ]' >>> or jsonb_col ? 'key1' >>> if in MCE, assign % from MCE >>> otherwise assign 1% of non-MCE % >>> >>> jsonb_col @> '{ "key1": "value1" }' >>> if in MCE, assign MCE% * 0.1 >>> otherwise assign 0.01 of non-MCE % >>> >>> Does that make sense? >> >> I suspect it makes a lot less sense. The way people seem to want to >> use jsonb is as a document store with a bit of flexibility. Individual >> JSON documents tend to be fairly homogeneous in structure within a >> table, just like with systems like MongoDB. Strings within arrays are >> keys for our purposes, and these are often used for tags and so on. >> But Strings that are the key of an object/pair are much less useful to >> index, in my estimation. > > Yeah, I see your point; except for arrays, people are usually searching > for a key:value pair, and the existence of the key is not in doubt. > > That would make the "element" the key:value pair, no? But > realistically, we would only want to do that for simple keys and values. > > Although: if you "flatten" a nested JSON structure into just keys with > scalar values (and array items as their own thing), then you could have > a series of expanded key:value pairs to put into MCE. > > For example: > > { house : { city : San Francisco, > sqft: 1200, > color: blue, > occupants: [ mom, dad, child1 ] > } > occupation: programmer > } > > ... would get flattened out into the following pairs: > > city: san francisco > sqft: 1200 > color: blue > occupants: [ mom ] > occupants: [ dad ] > occupants: [ child1 ] > occupation: programmer > > This would probably work because there aren't a lot of data structures > where people would have the same key:value pair in different locations > in the JSON, and care about it stats-wise. Alternatetly, if the same > key-value pair appears multiple times in the same sample row, we could > cut the MC% by that multiple. Even if there were multiple occurrences, this would probably still be an improvement. Another idea... at one time in the past when discussing statistics on multiple columns, one idea was to build statistics on indexes. If we built that, we could also do the same thing for at least JSONB (not sure about JSON). Obviously doesn't help for stuff you haven't indexed, but presumably if you care about performance and have any significant size of data you've also indexed parts of the JSON, yes? -- Jim Nasby, Data Architect, Blue Treble Consulting Data in Trouble? Get it in Treble! http://BlueTreble.com -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance