Would it be possible to utilize a GIN index to query for distinct values ?

Started by Danny Shemeshalmost 4 years ago1 messagesgeneral
Jump to latest
#1Danny Shemesh
dany74q@gmail.com

Hey everyone !

Bumping an older thread
</messages/by-id/CA+KBOKwJkG5_vMi3W6D9mXMbLJA_i4qrpPfa-Kg5EqLvBBMYow@mail.gmail.com&gt;,
I've read the GIN readme in the code base and have skimmed through the
implementation, it made me wonder -
would it be possible to use the index to query for distinct / count
distinct values, at least for some key types ?

For instance, say I have a GIN index on a single, highly cardinal but
non-unique text column (a-la 'name'); from my very limited understanding,
would it be possible to query for distinct / count distinct values via
roughly:
- Traversing the GIN entry tree tuples
- Gathering the key data from said tuples
- Discarding keys with no / empty posting lists, as they aren't discarded
from the tree
- Traversing the pending list for indices with fastupdate & merging the
result set

I'm probably off by quite a lot, but I'd really appreciate your great
insight on the above.

Thanks !
Danny