From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Steven Schlansker <stevenschlansker@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Computed index on transformation of jsonb key set
Date: Sat, 27 Apr 2019 08:55:52 +0100
Message-ID: <87h8ajx4y4.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <8A0F49D1-CA16-445B-BC4E-F53E9925809C@gmail.com>
References: <8A0F49D1-CA16-445B-BC4E-F53E9925809C@gmail.com>
>>>>> "Steven" == Steven Schlansker <stevenschlansker@gmail.com> writes:
Steven> I figured I'd end up with significantly better storage and
Steven> performance characteristics if I first compute a uuid[] value
Steven> and build the GIN over that, and use the array operator class
Steven> instead. Additionally, this eliminates possible confusion about
Steven> uuid casing (text is case sensitive, uuid is not) and this has
Steven> already caused at least one bug in our application.
Steven> I attempted to optimize a query like:
Steven> select * from tbl where array(select jsonb_object_keys(mapData)::uuid) && array['320982a7-cfaa-572a-b5ea-2074d7f3b014'::uuid];
Obvious solution:
create function uuid_keys(mapData jsonb) returns uuid[]
language plpgsql immutable strict
as $$
begin
return array(select jsonb_object_keys(mapData)::uuid);
end;
$$;
create index on tbl using gin (uuid_keys(mapData));
select * from tbl where uuid_keys(mapData) && array[...];
--
Andrew (irc:RhodiumToad)
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: andrew@tao11.riddles.org.uk, stevenschlansker@gmail.com
Subject: Re: Computed index on transformation of jsonb key set
In-Reply-To: <87h8ajx4y4.fsf@news-spur.riddles.org.uk>
References: <8A0F49D1-CA16-445B-BC4E-F53E9925809C@gmail.com> <87h8ajx4y4.fsf@news-spur.riddles.org.uk>
* 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