pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hukim99@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #13874: The index of a json field which is created after data are inserted doesn't work.
Date: Mon, 18 Jan 2016 12:39:42 +0000
Message-ID: <20160118123942.2961.98513@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      13874
Logged by:          Hyoungwook Kim
Email address:      hukim99@gmail.com
PostgreSQL version: 9.4.5
Operating system:   OS X 10.11.2
Description:        

Hi team,

Please see the following results.

test=# CREATE TABLE json_test (id serial primary key, data jsonb);
CREATE TABLE
test=# CREATE INDEX idb_json_test_data ON json_test USING GIN (data);
CREATE INDEX
test=# INSERT INTO json_test (data) VALUES ('[ { "id": "id1" }, { "id":
"id3" } ]');
INSERT 0 1
test=# EXPLAIN SELECT * FROM json_test WHERE data @> '[{"id": "id2"}]';
                                    QUERY PLAN                              
     
----------------------------------------------------------------------------------
 Bitmap Heap Scan on json_test  (cost=16.01..20.02 rows=1 width=36)
   Recheck Cond: (data @> '[{"id": "id2"}]'::jsonb)
   ->  Bitmap Index Scan on idb_json_test_data  (cost=0.00..16.01 rows=1
width=0)
         Index Cond: (data @> '[{"id": "id2"}]'::jsonb)
(4 rows)

test=# DROP TABLE json_test;
DROP TABLE
test=# CREATE TABLE json_test (id serial primary key, data jsonb);
CREATE TABLE
test=# INSERT INTO json_test (data) VALUES ('[ { "id": "id1" }, { "id":
"id3" } ]');
INSERT 0 1
test=# CREATE INDEX idb_json_test_data ON json_test USING GIN (data);
CREATE INDEX
test=# EXPLAIN SELECT * FROM json_test WHERE data @> '[{"id": "id2"}]';
                        QUERY PLAN                        
----------------------------------------------------------
 Seq Scan on json_test  (cost=0.00..1.01 rows=1 width=36)
   Filter: (data @> '[{"id": "id2"}]'::jsonb)
(2 rows)

The only difference between two instructions above is whether the index is
created before or after data insertion. Isn't it a bug?

Thanks.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (3+ messages)  latest in thread

Message-ID: <20160118123942.2961.98513@wrigleys.postgresql.org>
Permalink:  ../20160118123942.2961.98513@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20160118123942.2961.98513@wrigleys.postgresql.org

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: hukim99@gmail.com
  Subject: Re: BUG #13874: The index of a json field which is created after data are inserted doesn't work.
  In-Reply-To: <20160118123942.2961.98513@wrigleys.postgresql.org>
  References: <20160118123942.2961.98513@wrigleys.postgresql.org>

* 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