Using GIN index to retrieve distinct values - Mailing list pgsql-general

From Alexander Hill
Subject Using GIN index to retrieve distinct values
Date
Msg-id CA+KBOKwJkG5_vMi3W6D9mXMbLJA_i4qrpPfa-Kg5EqLvBBMYow@mail.gmail.com
Whole thread Raw
List pgsql-general
Hi all,

My understanding of a GIN index is that it maps each unique key to the set of items containing that key. That suggests to me that enumerating the distinct keys efficiently using the index should be possible in some cases. I understand that given the nature of the GIN framework, the original key won't always be able to be retrieved. But in certain cases like int array, for example, would it be possible?

While on the topic: what's the canonical way to do that kind of query?

CREATE TABLE tagged_items
(
    id serial PRIMARY KEY,
    tag_ids integer[]
);

select array_agg(tag_id)
from (select distinct unnest(tag_ids) from items) tag_id;

Thanks!
Alex

pgsql-general by date:

Previous
From: Virendra Kumar
Date:
Subject: Re: how to slow down parts of Pg
Next
From: Laurenz Albe
Date:
Subject: Re: how to slow down parts of Pg