Re: Computed index on transformation of jsonb key set
| От | Andrew Gierth |
|---|---|
| Тема | Re: Computed index on transformation of jsonb key set |
| Дата | |
| Msg-id | 87h8ajx4y4.fsf@news-spur.riddles.org.uk обсуждение исходный текст |
| Ответ на | Computed index on transformation of jsonb key set (Steven Schlansker <stevenschlansker@gmail.com>) |
| Ответы |
Re: Computed index on transformation of jsonb key set
|
| Список | pgsql-general |
>>>>> "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)
В списке pgsql-general по дате отправления: