pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
GIN Index for low cardinality
9+ messages / 5 participants
[nested] [flat]

* GIN Index for low cardinality
@ 2018-10-17 10:46  Ravi Krishna <srkrishna1@aol.com>
  0 siblings, 2 replies; 9+ messages in thread

From: Ravi Krishna @ 2018-10-17 10:46 UTC (permalink / raw)
  To: ; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

In  https://www.cybertec-postgresql.com/en/ideas-for-scaling-postgresql-to-multi-terabyte-and-beyond/

it is mentioned:

"GIN, the most know non-default index type perhaps, has been actually around for ages (full-text search) and in short is perfect for indexing columns where there are lot of repeating values – think all kinds of statuses or good old Mr/Mrs/Miss. GIN only stores every unique column value only once as for the default B-tree you’ll have e.g. 1 millon leaf nodes with the integer “1” in it."


Does it mean that GIN is a very good choice for low cardinality columns.  =

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: GIN Index for low cardinality
@ 2018-10-25 13:36  Олег Самойлов <splarv@ya.ru>
  parent: Ravi Krishna <srkrishna1@aol.com>
  1 sibling, 2 replies; 9+ messages in thread

From: Олег Самойлов @ 2018-10-25 13:36 UTC (permalink / raw)
  To: Ravi Krishna <srkrishna1@aol.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>


> 17 окт. 2018 г., в 13:46, Ravi Krishna <srkrishna1@aol.com> написал(а):
> 
> In  https://www.cybertec-postgresql.com/en/ideas-for-scaling-postgresql-to-multi-terabyte-and-beyond/ <https://www.cybertec-postgresql.com/en/ideas-for-scaling-postgresql-to-multi-terabyte-and-beyond/;
> 
> it is mentioned:
> 
> "GIN, the most know non-default index type perhaps, has been actually around for ages (full-text search) and in short is perfect for indexing columns where there are lot of repeating values – think all kinds of statuses or good old Mr/Mrs/Miss. GIN only stores every unique column value only once as for the default B-tree you’ll have e.g. 1 millon leaf nodes with the integer “1” in it."
> 
> 
> Does it mean that GIN is a very good choice for low cardinality columns.  

Not necessary. There is other index which also don’t keep column value in an every leaf. Hash, for instance. =

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: GIN Index for low cardinality
@ 2018-10-25 13:55  Ravi Krishna <srkrishna1@aol.com>
  parent: Олег Самойлов <splarv@ya.ru>
  1 sibling, 0 replies; 9+ messages in thread

From: Ravi Krishna @ 2018-10-25 13:55 UTC (permalink / raw)
  To: splarv@ya.ru; +Cc: pgsql-general@lists.postgresql.org

>>Does it mean that GIN is a very good choice for low cardinality columns.  
>Not necessary. There is other index which also don’t keep column value in an every leaf. Hash, for instance. 

Well I asked about GIN's usefulness for low cardinality.  Good to know that Hash can also be considered.
BTW until recently wasn't Hash unsafe for production since it was not WAL logged.





^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: GIN Index for low cardinality
@ 2018-10-26 15:59  Jeff Janes <jeff.janes@gmail.com>
  parent: Ravi Krishna <srkrishna1@aol.com>
  1 sibling, 0 replies; 9+ messages in thread

From: Jeff Janes @ 2018-10-26 15:59 UTC (permalink / raw)
  To: srkrishna1@aol.com; +Cc: pgsql-general@lists.postgresql.org

On Wed, Oct 17, 2018 at 6:47 AM Ravi Krishna <srkrishna1@aol.com> wrote:

> In
> https://www.cybertec-postgresql.com/en/ideas-for-scaling-postgresql-to-multi-terabyte-and-beyond/
>
> it is mentioned:
>
> "GIN, the most know non-default index type perhaps, has been actually
> around for ages (full-text search) and in short is perfect for indexing
> columns where there are lot of repeating values – think all kinds of
> statuses or good old Mr/Mrs/Miss. GIN only stores every unique column value
> only once as for the default B-tree you’ll have e.g. 1 millon leaf nodes
> with the integer “1” in it."
>
>
> Does it mean that GIN is a very good choice for low cardinality columns.
>

For extremely low cardinality, like Mr. Mrs. Miss., I doubt any index would
be very useful.  For less extreme cases, like say one million different
values present around 50 times each, yes, it can be useful to keep the
index size down.  It will not support needing to deliver rows in sorted
order, for example to fulfill an ORDER BY or a merge join.  Think carefully
about what setting you want for fast_update, and, if set to on, then what
value to use for gin_pending_list_limit.

Cheers,

Jeff

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: GIN Index for low cardinality
@ 2018-10-26 16:27  Jeff Janes <jeff.janes@gmail.com>
  parent: Олег Самойлов <splarv@ya.ru>
  1 sibling, 3 replies; 9+ messages in thread

From: Jeff Janes @ 2018-10-26 16:27 UTC (permalink / raw)
  To: Olleg Samoylov <splarv@ya.ru>; +Cc: srkrishna1@aol.com; pgsql-general@lists.postgresql.org

On Thu, Oct 25, 2018 at 9:36 AM Олег Самойлов <splarv@ya.ru> wrote:

>
> 17 окт. 2018 г., в 13:46, Ravi Krishna <srkrishna1@aol.com> написал(а):
>
> In
> https://www.cybertec-postgresql.com/en/ideas-for-scaling-postgresql-to-multi-terabyte-and-beyond/
>
> it is mentioned:
>
> "GIN, the most know non-default index type perhaps, has been actually
> around for ages (full-text search) and in short is perfect for indexing
> columns where there are lot of repeating values – think all kinds of
> statuses or good old Mr/Mrs/Miss. GIN only stores every unique column value
> only once as for the default B-tree you’ll have e.g. 1 millon leaf nodes
> with the integer “1” in it."
>
>
> Does it mean that GIN is a very good choice for low cardinality columns.
>
>
> Not necessary. There is other index which also don’t keep column value in
> an every leaf. Hash, for instance.
>

For smallish values (which low cardinality columns tend to be) the
per-tuple overhead and the pointer itself is probably much larger than the
value, so hash won't save you much if any space.  The GIN index removes not
just the value, but the per-tuple overhead.  And also compresses the point
list to further save space.

Here is a real-world example from one of my databases where each value is
about 17 characters long, and is present about 20 times:

gin: 411 MB
btree: 2167 MB
hash: 2159 MB

Cheers,

Jeff

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: GIN Index for low cardinality
@ 2018-10-26 16:49  Ozz Nixon <ozznixon@gmail.com>
  parent: Jeff Janes <jeff.janes@gmail.com>
  2 siblings, 1 reply; 9+ messages in thread

From: Ozz Nixon @ 2018-10-26 16:49 UTC (permalink / raw)
  To: jeff.janes@gmail.com; +Cc: splarv@ya.ru; srkrishna1@aol.com; pgsql-general@lists.postgresql.org

Jeff,
   Great info! Your example on Mr. Mrs. Miss, etc. is there a good rule of
thumb that if the data is under "x"KB an index is overhead not help? I am
not worried about space, more interested in performance.

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* RE: GIN Index for low cardinality
@ 2018-10-26 17:21  Igor Neyman <ineyman@perceptron.com>
  parent: Ozz Nixon <ozznixon@gmail.com>
  0 siblings, 0 replies; 9+ messages in thread

From: Igor Neyman @ 2018-10-26 17:21 UTC (permalink / raw)
  To: Ozz Nixon <ozznixon@gmail.com>; jeff.janes@gmail.com <jeff.janes@gmail.com>; +Cc: splarv@ya.ru <splarv@ya.ru>; srkrishna1@aol.com <srkrishna1@aol.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>



From: Ozz Nixon <ozznixon@gmail.com>
Sent: Friday, October 26, 2018 12:50 PM
To: jeff.janes@gmail.com
Cc: splarv@ya.ru; srkrishna1@aol.com; pgsql-general@lists.postgresql.org
Subject: Re: GIN Index for low cardinality

Jeff,
   Great info! Your example on Mr. Mrs. Miss, etc. is there a good rule of thumb that if the data is under "x"KB an index is overhead not help? I am not worried about space, more interested in performance.

I think, partial/conditional indexes: …. Where greeting = ‘…’ – may help.

Regards,
Igor Neyman


^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: GIN Index for low cardinality
@ 2018-10-26 22:55  Jeff Janes <jeff.janes@gmail.com>
  parent: Jeff Janes <jeff.janes@gmail.com>
  2 siblings, 0 replies; 9+ messages in thread

From: Jeff Janes @ 2018-10-26 22:55 UTC (permalink / raw)
  To: Olleg Samoylov <splarv@ya.ru>; +Cc: srkrishna1@aol.com; pgsql-general@lists.postgresql.org

On Fri, Oct 26, 2018 at 12:27 PM Jeff Janes <jeff.janes@gmail.com> wrote:

Here is a real-world example from one of my databases where each value is
> about 17 characters long, and is present about 20 times:
>
> gin: 411 MB
> btree: 2167 MB
> hash: 2159 MB
>

For what it is worth, that was 9.6 with freshly rebuilt indexes.

On 11.0 with freshly rebuilt indices, the hash index does get a bit smaller:

gin: 411 MB
btree: 2167 MB
hash: 1864 MB

Cheers,

Jeff
>
>

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: GIN Index for low cardinality
@ 2018-11-14 08:45  Олег Самойлов <splarv@ya.ru>
  parent: Jeff Janes <jeff.janes@gmail.com>
  2 siblings, 0 replies; 9+ messages in thread

From: Олег Самойлов @ 2018-11-14 08:45 UTC (permalink / raw)
  To: Jeff Janes <jeff.janes@gmail.com>; +Cc: Ravi Krishna <srkrishna1@aol.com>; pgsql-general@lists.postgresql.org

Eh, I checked, you are right. Something terribly wrong with hash index in PostgreSQL. But there are another hash index gin(jsonb_path_ops), may be correctly say gin+hash index. Looked like it is the best for this purpose.

> 26 окт. 2018 г., в 19:27, Jeff Janes <jeff.janes@gmail.com> написал(а):
> 
> On Thu, Oct 25, 2018 at 9:36 AM Олег Самойлов <splarv@ya.ru <mailto:splarv@ya.ru>> wrote:
> 
>> 17 окт. 2018 г., в 13:46, Ravi Krishna <srkrishna1@aol.com <mailto:srkrishna1@aol.com>> написал(а):
>> 
>> In  https://www.cybertec-postgresql.com/en/ideas-for-scaling-postgresql-to-multi-terabyte-and-beyond/ <https://www.cybertec-postgresql.com/en/ideas-for-scaling-postgresql-to-multi-terabyte-and-beyond/;
>> 
>> it is mentioned:
>> 
>> "GIN, the most know non-default index type perhaps, has been actually around for ages (full-text search) and in short is perfect for indexing columns where there are lot of repeating values – think all kinds of statuses or good old Mr/Mrs/Miss. GIN only stores every unique column value only once as for the default B-tree you’ll have e.g. 1 millon leaf nodes with the integer “1” in it."
>> 
>> 
>> Does it mean that GIN is a very good choice for low cardinality columns.  
> 
> Not necessary. There is other index which also don’t keep column value in an every leaf. Hash, for instance. 
> 
> For smallish values (which low cardinality columns tend to be) the per-tuple overhead and the pointer itself is probably much larger than the value, so hash won't save you much if any space.  The GIN index removes not just the value, but the per-tuple overhead.  And also compresses the point list to further save space.  
> 
> Here is a real-world example from one of my databases where each value is about 17 characters long, and is present about 20 times:
> 
> gin: 411 MB
> btree: 2167 MB 
> hash: 2159 MB
> 
> Cheers,
> 
> Jeff

^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2018-11-14 08:45 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-10-17 10:46 GIN Index for low cardinality Ravi Krishna <srkrishna1@aol.com>
2018-10-25 13:36 ` Олег Самойлов <splarv@ya.ru>
2018-10-25 13:55   ` Ravi Krishna <srkrishna1@aol.com>
2018-10-26 16:27   ` Jeff Janes <jeff.janes@gmail.com>
2018-10-26 16:49     ` Ozz Nixon <ozznixon@gmail.com>
2018-10-26 17:21       ` Igor Neyman <ineyman@perceptron.com>
2018-10-26 22:55     ` Jeff Janes <jeff.janes@gmail.com>
2018-11-14 08:45     ` Олег Самойлов <splarv@ya.ru>
2018-10-26 15:59 ` Jeff Janes <jeff.janes@gmail.com>

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