pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: ramikvl@gmail.com
To: pgsql-general@lists.postgresql.org
Subject: jsonb Indexing
Date: Fri, 17 Sep 2021 15:55:29 +0200
Message-ID: <3c162c26-e940-e49e-a465-6d484b0ca3a9@gmail.com> (raw)

Hello,

I'm new to jsonb feature of postgres. I have PostgreSQL 13.2 running 
locally in docker.

I've been playing a little bit with jsonb indexes described 
https://www.postgresql.org/docs/13/datatype-json.html#JSON-INDEXING and 
I'm not able make the GIN index work on 'tags'.

I was wondering what I'm doing wrong. There are steps what I've tried:

CREATE TABLE api (
     jdoc jsonb
);

INSERT INTO api (jdoc)
     VALUES ('{
     "guid": "9c36adc1-7fb5-4d5b-83b4-90356a46061a",
     "name": "Angela Barton",
     "is_active": true,
     "company": "Magnafone",
     "address": "178 Howard Place, Gulf, Washington, 702",
     "registered": "2009-11-07T08:53:22 +08:00",
     "latitude": 19.793713,
     "longitude": 86.513373,
     "tags": [
         "enim",
         "aliquip",
         "qui"
     ]
}');

CREATE INDEX idxgintags ON api USING GIN ((jdoc->'tags'));

EXPLAIN ANALYZE SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc -> 
'tags' ? 'qui';

And the result is

Seq Scan on api  (cost=0.00..1.02 rows=1 width=64) (actual 
time=0.019..0.021 rows=1 loops=1)
   Filter: ((jdoc -> 'tags'::text) ? 'qui'::text)

Planning Time: 0.115 ms

Execution Time: 0.047 ms

Do you know why Index Scan on idxgintag is not used?

Thank you,

Vlasta






view thread (5+ messages)  latest in thread

Message-ID: <3c162c26-e940-e49e-a465-6d484b0ca3a9@gmail.com>
Permalink:  ../3c162c26-e940-e49e-a465-6d484b0ca3a9@gmail.com/
Also on:    postgresql.org/message-id/3c162c26-e940-e49e-a465-6d484b0ca3a9@gmail.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 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-general@postgresql.org
  Cc: ramikvl@gmail.com
  Subject: Re: jsonb Indexing
  In-Reply-To: <3c162c26-e940-e49e-a465-6d484b0ca3a9@gmail.com>
  References: <3c162c26-e940-e49e-a465-6d484b0ca3a9@gmail.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