Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YI2tD-0004vw-0T for pgsql-performance@arkaria.postgresql.org; Sun, 01 Feb 2015 22:21:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YI2tC-0007Mk-DY for pgsql-performance@arkaria.postgresql.org; Sun, 01 Feb 2015 22:21:10 +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 1YI2tB-0007Md-Cn for pgsql-performance@postgresql.org; Sun, 01 Feb 2015 22:21:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YI2t3-0007p4-HJ for pgsql-performance@postgresql.org; Sun, 01 Feb 2015 22:21:08 +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 t11MKvIa004792; Sun, 1 Feb 2015 17:20:58 -0500 From: Tom Lane To: Christian Weyer cc: Josh Berkus , "pgsql-performance@postgresql.org" Subject: Re: Unexpected (bad) performance when querying indexed JSONB column In-reply-to: References: <7F9BEAD7-C190-4E21-8240-04687FA88435@thinktecture.com> <54CE954F.7070904@agliodbs.com> Comments: In-reply-to Christian Weyer message dated "Sun, 01 Feb 2015 21:19:29 +0000" Date: Sun, 01 Feb 2015 17:20:57 -0500 Message-ID: <4791.1422829257@sss.pgh.pa.us> 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 Christian Weyer writes: > On 01.02.15 22:06, "Josh Berkus" wrote: >> Please send us the output of EXPLAIN ( ANALYZE ON, BUFFERS ON ) so that >> we can see what the query is actually doing, rather than just what the >> plan was. > Sure. Here we go: > "Bitmap Heap Scan on articles (cost=16.25..135.64 rows=33 width=427) > (actual time=6.425..43.603 rows=18584 loops=1)" > " Recheck Cond: (data @> ‘{"locked": true}'::jsonb)" > " Heap Blocks: exact=1496" > " Buffers: shared hit=1504" > " -> Bitmap Index Scan on idx_data (cost=0.00..16.24 rows=33 width=0) > (actual time=6.090..6.090 rows=18584 loops=1)" > " Index Cond: (data @> ‘{"locked": true}'::jsonb)" > " Buffers: shared hit=8" > "Planning time: 0.348 ms" > "Execution time: 47.788 ms" So that's showing a runtime of 48 ms, not 900. For retrieving 18584 rows, doesn't sound that bad to me. (If the planner had had a better rowcount estimate, it'd likely have not bothered with the index at all but just done a seqscan. This is a consequence of the lack of any very useful stats for JSONB columns, which is something we hope to address soon; but it's not done in 9.4 and likely won't be in 9.5 either ...) regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance