pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christian Weyer <christian.weyer@thinktecture.com>
To: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Unexpected (bad) performance when querying indexed JSONB column
Date: Sat, 31 Jan 2015 19:02:45 +0000
Message-ID: <7F9BEAD7-C190-4E21-8240-04687FA88435@thinktecture.com> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

Just checked: the execution time is the same when I drop the index.

Execution plan with index:
---
"Bitmap Heap Scan on articles  (cost=16.25..135.64 rows=33 width=427)"
"  Recheck Cond: (data @> '{"locked": true}'::jsonb)"
"  ->  Bitmap Index Scan on idx_data  (cost=0.00..16.24 rows=33 width=0)"
"        Index Cond: (data @> '{"locked": true}'::jsonb)"
---

And without the index:
---
"Seq Scan on articles  (cost=0.00..2289.21 rows=33 width=427)"
"  Filter: (data @> '{"locked": true}'::jsonb)"
---

-C.

From: Christian Weyer
Date: Samstag, 31. Januar 2015 17:00
To: "pgsql-performance@postgresql.org<mailto:pgsql-performance@postgresql.org>"
Subject: [PERFORM] Unexpected (bad) performance when querying indexed JSONB column

Hi all,

The pg version in question is the latest 9.4., running on Windows.

For testing out the NoSQL features of pg I have a simple table called ‘articles’ with a column called ‘data’.

There is an index on ‘data’ like this:
  CREATE INDEX idx_data ON articles USING gin (data jsonb_path_ops);

The current test data set has 32570 entires of JSON docs like this:
{
"title": "Foo Bar",
"locked": true,
"valid_until": "2049-12-31T00:00:00",
"art_number": 12345678,
"valid_since": "2013-10-05T00:00:00",
"number_valid": false,
"combinations": {
"var1": "4711",
"var2": "4711",
"var3": "0815",
"int_art_number": "000001"
}
}

Nothing too complex, I think.

When I run a simple query:
  SELECT data  #>> ‘{"title"}'
  FROM articles
  WHERE data @> '{ “locked" : true }';

Reproducingly, it takes approx. 900ms to get the results back.
Honestly, I was expecting a much faster query.

Any opinions on this?

Thanks,
-C.



view thread (6+ messages)  latest in thread

Message-ID: <7F9BEAD7-C190-4E21-8240-04687FA88435@thinktecture.com>
Permalink:  ../7F9BEAD7-C190-4E21-8240-04687FA88435@thinktecture.com/
Also on:    postgresql.org/message-id/7F9BEAD7-C190-4E21-8240-04687FA88435@thinktecture.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: christian.weyer@thinktecture.com
  Subject: Re: Unexpected (bad) performance when querying indexed JSONB column
  In-Reply-To: <7F9BEAD7-C190-4E21-8240-04687FA88435@thinktecture.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox