Which index is used in the index scan. - Mailing list pgsql-general

From Sakai, Teppei
Subject Which index is used in the index scan.
Date
Msg-id 99C4246E73ED1B478BBB9671718426203E3C31E4@G01JPEXMBKW03
Whole thread Raw
Responses Re: Which index is used in the index scan.
List pgsql-general
Hi

We have question about index scan.

We created table and indexes and executed SQL, but the index used by day is different.
One day the index of c1 was used, and on another day the index of c2 was used.
 - CREATE TABLE tbl1 (c1 varchar, c2 varchar, c3 timestamptz);
 - CREATE INDEX tbl1_idx_c1 ON tbl1(c1);
 - CREATE INDEX tbl1_idx_c2 ON tbl2(c2);
 - SELECT * FROM tbl1 WHERE c1 = 'XXX' AND C2 = 'YYY' AND C3 >= 'yyyy/mm/dd' AND C3 <= 'yyyy/mm/dd';

We calculated cost from the source code using pg_class and pg_statistic, but the cost values at each index were the
same.
We did not rebuild or update indexes.

What are the reasons why the index has been changed besides the following factors?
 - cost values
 - Index creation order

PostgreSQL version : 9.5.2

Regards,
SAKAI Teppei



pgsql-general by date:

Previous
From: Joshua White
Date:
Subject: Re: Problem creating a database
Next
From: Laurenz Albe
Date:
Subject: Re: Problem creating a database