Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aLKMD-00039g-V5 for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Jan 2016 00:41:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aLKMD-0001C3-Ho for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Jan 2016 00:41:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aL96M-0001jw-6T for pgsql-bugs@postgresql.org; Mon, 18 Jan 2016 12:40:06 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aL96J-0007WS-5g for pgsql-bugs@postgresql.org; Mon, 18 Jan 2016 12:40:05 +0000 MIME-Version: 1.0 Subject: BUG #13874: The index of a json field which is created after data are inserted doesn't work. To: pgsql-bugs@postgresql.org From: hukim99@gmail.com Date: Mon, 18 Jan 2016 12:39:42 +0000 Message-ID: <20160118123942.2961.98513@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.1 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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