pg.ddx.io pgsql-general@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Gavin Flower <GavinFlower@archidevsys.co.nz>
To: pgsql-general@lists.postgresql.org
Subject: Re: Multicolumn index for single-column queries?
Date: Fri, 19 Apr 2019 11:05:46 +1200
Message-ID: <a1e6a67c-45fb-b3c0-5718-77ff744b3ecb@archidevsys.co.nz> (raw)
In-Reply-To: <87muknwhle.fsf@protecting.net>
References: <95ade9a3-6846-3f55-f936-85b8bb4b46a8@mail.ru>
<af88e7c8-8274-70f6-e1c7-e3e59e6bf6c7@a-kretschmer.de>
<87muknwhle.fsf@protecting.net>
On 19/04/2019 01:47, Harald Fuchs wrote:
> Andreas Kretschmer <andreas@a-kretschmer.de> writes:
>
>> 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.
> I think it also depends on the average number of rows having the same foo_id.
>
The number of rows referenced by an index entry for the multi_index will
always be less than or equal to those for the matching foo_index.
Also there will be fewer index entries per block for the multi_index.
Which is why the I/O count will be higher; even in the best case, where
there is an equal row referenced by the index entries.
view thread (12+ messages) latest in thread
Message-ID: <a1e6a67c-45fb-b3c0-5718-77ff744b3ecb@archidevsys.co.nz> Permalink: ../a1e6a67c-45fb-b3c0-5718-77ff744b3ecb@archidevsys.co.nz/ Also on: postgresql.org/message-id/a1e6a67c-45fb-b3c0-5718-77ff744b3ecb@archidevsys.co.nz ·
reply
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Reply to all the recipients from your mail client; the link fills in the headers below: reply via email Some clients, webmail especially, drop In-Reply-To and References from a link, and the reply then starts a new thread: use the mbox below. To: pgsql-general@postgresql.org Cc: GavinFlower@archidevsys.co.nz Subject: Re: Multicolumn index for single-column queries? In-Reply-To: <a1e6a67c-45fb-b3c0-5718-77ff744b3ecb@archidevsys.co.nz> References: <95ade9a3-6846-3f55-f936-85b8bb4b46a8@mail.ru> <af88e7c8-8274-70f6-e1c7-e3e59e6bf6c7@a-kretschmer.de> <87muknwhle.fsf@protecting.net> <a1e6a67c-45fb-b3c0-5718-77ff744b3ecb@archidevsys.co.nz> * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox
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