pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedmultiple indexes on the same column
6+ messages / 4 participants
[nested] [flat]
* multiple indexes on the same column
@ 2019-04-12 10:54 Tiffany Thang <tiffanythang@gmail.com>
0 siblings, 2 replies; 6+ messages in thread
From: Tiffany Thang @ 2019-04-12 10:54 UTC (permalink / raw)
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Hi,
Can someone explain the use of creating multiple indexes on the same
column?
How would the optimizer determine which index to use? From my brief
testing, the optimizer picked the latest created index, testidx3. Can you
provide a scenario where creating multiple indexes on the same column would
be beneficial?
create table test (a int, b int);
create index testidx1 on test (a);
create index testidx2 on test (a);
create index testidx3 on test (a);
Thanks.
Tiff
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: multiple indexes on the same column
@ 2019-04-12 11:52 Geoff Winkless <pgsqladmin@geoff.dj>
parent: Tiffany Thang <tiffanythang@gmail.com>
1 sibling, 0 replies; 6+ messages in thread
From: Geoff Winkless @ 2019-04-12 11:52 UTC (permalink / raw)
To: Tiffany Thang <tiffanythang@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
On Fri, 12 Apr 2019 at 11:54, Tiffany Thang <tiffanythang@gmail.com> wrote:
> Can you provide a scenario where creating multiple indexes on the same
> column would be beneficial?
>
When you have too much disk space?
When your table writes are too fast?
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: multiple indexes on the same column
@ 2019-04-12 13:51 Tom Lane <tgl@sss.pgh.pa.us>
parent: Tiffany Thang <tiffanythang@gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: Tom Lane @ 2019-04-12 13:51 UTC (permalink / raw)
To: Tiffany Thang <tiffanythang@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Tiffany Thang <tiffanythang@gmail.com> writes:
> Can someone explain the use of creating multiple indexes on the same
> column?
There is none, unless the indexes have different properties (e.g.
different opclasses and/or index AMs).
I'd suggest reading
https://www.postgresql.org/docs/current/indexes.html
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: multiple indexes on the same column
@ 2019-04-12 16:55 Andres Freund <andres@anarazel.de>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 6+ messages in thread
From: Andres Freund @ 2019-04-12 16:55 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Tiffany Thang <tiffanythang@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Hi,
On 2019-04-12 09:51:51 -0400, Tom Lane wrote:
> Tiffany Thang <tiffanythang@gmail.com> writes:
> > Can someone explain the use of creating multiple indexes on the same
> > column?
>
> There is none, unless the indexes have different properties (e.g.
> different opclasses and/or index AMs).
Well, it can be beneficial to create a new index concurrently, and then
drop the old one concurrently. Before v12 that's the only way to
recreate an index during production, if it e.g. bloated.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: multiple indexes on the same column
@ 2019-04-12 17:07 Tom Lane <tgl@sss.pgh.pa.us>
parent: Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 6+ messages in thread
From: Tom Lane @ 2019-04-12 17:07 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Tiffany Thang <tiffanythang@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Andres Freund <andres@anarazel.de> writes:
> On 2019-04-12 09:51:51 -0400, Tom Lane wrote:
>> Tiffany Thang <tiffanythang@gmail.com> writes:
>>> Can someone explain the use of creating multiple indexes on the same
>>> column?
>> There is none, unless the indexes have different properties (e.g.
>> different opclasses and/or index AMs).
> Well, it can be beneficial to create a new index concurrently, and then
> drop the old one concurrently.
Right, but in that situation there's no intent to keep both indexes
in place. You're just putting up with extra overhead temporarily
as a means to avoid taking an exclusive lock.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: multiple indexes on the same column
@ 2019-04-12 20:42 Tiffany Thang <tiffanythang@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 6+ messages in thread
From: Tiffany Thang @ 2019-04-12 20:42 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Andres Freund <andres@anarazel.de>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Got it! Thanks Andres and Tom!
Tiff
On Fri, Apr 12, 2019 at 1:07 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Andres Freund <andres@anarazel.de> writes:
> > On 2019-04-12 09:51:51 -0400, Tom Lane wrote:
> >> Tiffany Thang <tiffanythang@gmail.com> writes:
> >>> Can someone explain the use of creating multiple indexes on the same
> >>> column?
>
> >> There is none, unless the indexes have different properties (e.g.
> >> different opclasses and/or index AMs).
>
> > Well, it can be beneficial to create a new index concurrently, and then
> > drop the old one concurrently.
>
> Right, but in that situation there's no intent to keep both indexes
> in place. You're just putting up with extra overhead temporarily
> as a means to avoid taking an exclusive lock.
>
> regards, tom lane
>
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2019-04-12 20:42 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-04-12 10:54 multiple indexes on the same column Tiffany Thang <tiffanythang@gmail.com>
2019-04-12 11:52 ` Geoff Winkless <pgsqladmin@geoff.dj>
2019-04-12 13:51 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-04-12 16:55 ` Andres Freund <andres@anarazel.de>
2019-04-12 17:07 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-04-12 20:42 ` Tiffany Thang <tiffanythang@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