From: | Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Multicolumn index for single-column queries? |
Date: | 2019-04-18 07:14:13 |
Message-ID: | 263b8e6a-668b-4ae3-dc63-f7e6cf0d3aa9@archidevsys.co.nz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 18/04/2019 18:52, rihad wrote:
> 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?
>
> Thanks.
>
>
>
The multi column index will require more RAM to hold it. So if there is
memory contention, then there would be an increased risk of swapping,
leading to slower query times.
I suspect that if there is more than enough RAM, then a multi column
index will be slightly slower than a single column index. However, the
difference will probably be lost in the noise -- in other words, the
various things happening in the background will most likely to have far
more significant impact on query duration. IMHO
Cheers,
Gavin
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Kretschmer | 2019-04-18 07:14:47 | Re: Multicolumn index for single-column queries? |
Previous Message | rihad | 2019-04-18 06:52:00 | Multicolumn index for single-column queries? |