From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
---|---|
To: | Andreas Kretschmer <andreas(at)a-kretschmer(dot)de>, pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Multicolumn index for single-column queries? |
Date: | 2019-04-18 08:40:16 |
Message-ID: | 9d7e9ba9296084129986d9658e47afca00882d4d.camel@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Andreas Kretschmer wrote:
> Am 18.04.19 um 08:52 schrieb rihad:
> > Hi. Say there are 2 indexes:
> >
> > "foo_index" btree (foo_id)
> >
> > "multi_index" btree (foo_id, approved, expires_at)
> >
> >
> > foo_id is an integer. Some queries involve all three columns in their
> > WHERE clauses, some involve only foo_id.
> > Would it be ok from general performance standpoint to remove foo_index
> > and rely only on multi_index? I know that
> > PG would have to do less work updating just one index compared to
> > updating them both, but wouldn't searches
> > on foo_id alone become slower?
>
> it depends .
>
> it depends on the queries you are using, on your workload. a
> multi-column-index will be large than an index over just one column,
> therefore you will have more disk-io when you read from such an index.
To be more explicit: if you can live with a slightly less efficient
index scan and want fast data modifications, use only the second index.
If you hardly ever update the table, don't mind the wasted space and
want every bit of query speed (data warehouse), having both indexes
might be better.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
From | Date | Subject | |
---|---|---|---|
Next Message | Ron | 2019-04-18 13:24:17 | Re: Multicolumn index for single-column queries? |
Previous Message | Andreas Kretschmer | 2019-04-18 07:14:47 | Re: Multicolumn index for single-column queries? |