Re: Computed index on transformation of jsonb key set - Mailing list pgsql-general

From Andrew Gierth
Subject Re: Computed index on transformation of jsonb key set
Date
Msg-id 87h8ajx4y4.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to Computed index on transformation of jsonb key set  (Steven Schlansker <stevenschlansker@gmail.com>)
Responses Re: Computed index on transformation of jsonb key set
List 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 by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: 9.6.9 Default configuration for a default installation butdifferent with-krb-srvnam
Next
From: Matthias Apitz
Date:
Subject: Missing pg_config on SuSE SLES 12 for PostgreSQL 10