Re: integer[] indexing. - Mailing list pgsql-performance

From Harald Fuchs
Subject Re: integer[] indexing.
Date
Msg-id puhdp5mm0r.fsf@srv.protecting.net
Whole thread Raw
In response to integer[] indexing.  (Dawid Kuroczko <qnex42@gmail.com>)
List pgsql-performance
In article <opsfjonlc0cq72hf@musicbox>,
=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= <lists@boutiquenumerique.com> writes:

>     disclaimer : brainless proposition

> (SELECT * FROM table WHERE (icount(ids) <= 1 AND ids[1] = 33)
> UNION ALL
> (SELECT * FROM table WHERE (icount(ids) > 1 AND ids && '{33}'));

I guess my proposition is even more brainless :-)

If 95% of all records have only one value, how about putting the first
(and most often only) value into a separate column with a btree index
on it?  Something like that:

  CREATE TABLE tbl (
    -- other columns
    id1 INT NOT NULL,
    idN INT[] NULL
  );

  CREATE INDEX tbl_id1_ix ON tbl (id1);

If id1 is selective enough, you probably don't need another index on idn.

pgsql-performance by date:

Previous
From: Pierre-Frédéric Caillaud
Date:
Subject: Re: sequential scan on select distinct
Next
From:
Date:
Subject: Re: Re: Data warehousing requirements