[GENERAL] index duplicates primary key, but is used more? - Mailing list pgsql-general

From jonathan vanasco
Subject [GENERAL] index duplicates primary key, but is used more?
Date
Msg-id 8D07ECA6-1B49-45AF-9B30-2FEF2360236C@2xlp.com
Whole thread Raw
Responses Re: [GENERAL] index duplicates primary key, but is used more?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: [GENERAL] index duplicates primary key, but is used more?  (Steven Chang <stevenchang1213@gmail.com>)
List pgsql-general
i'm doing a performance audit and noticed something odd.

we tested a table a while back, by creating lots of indexes that match different queries (30+).

for simplicity, here's a two column table:

    CREATE TABLE foo (id INT PRIMARY KEY
                          value INT NOT NULL DEFAULT 0,
                          );

The indexes were generated by a script, so we had things like:

    CREATE INDEX idx_test_foo_id_asc ON foo(id ASC);
    CREATE INDEX idx_test_foo_id_desc ON foo(id DESC);
    CREATE INDEX idx_test_foo_val_asc ON foo(value ASC);
    CREATE INDEX idx_test_foo_value_desc ON foo(value DESC);

What I noticed when checking stats earlier, is that although `idx_test_foo_id_asc` is the same as the PKEY... it was
usedabout 10x more than the pkey. 

Does anyone know of this is just random (perhaps due to the name being sorted earlier) or there is some other reason
thatindex would be selected ? 

my concern in deleting it, is that it might be preferred for queries due to hinting from the explicit 'order by'  (even
thoughthe contents are the same) and I may lose an index being leveraged in that query. 

It's on a GIANT table, so it would be hard to recreate.



pgsql-general by date:

Previous
From: Neil Anderson
Date:
Subject: Re: [GENERAL] dump to pg
Next
From: Tom Lane
Date:
Subject: Re: [GENERAL] index duplicates primary key, but is used more?