Re: optimizer choosing the wrong index

From: Martin Below <machtin(dot)below(at)googlemail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: optimizer choosing the wrong index
Date: 2010-07-08 12:12:51
Message-ID: AANLkTils07zKqrtxfdLxvE4eD3udGhUlH_aoFp_xu5E7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello Merlin,

thanks for your help.

> can you supply the plans on the actual tables?  the 'wrong' index
> might actually be the 'right' one if expires_on is of high cardinality
> (perhaps it's distributed badly and the table needs a stats tweak to
> make it correct).

test=# select count(*) total, count(distinct client_id) ids,
count(distinct expires_on) dates from ps;
total | ids | dates
--------+--------+--------
213645 | 123366 | 213549

I played arround with set statistics on both columns, but that didn't
seem to help. (I did run analyze)

> You can probably force the right index like this:
> explain analyze select * from ps where (client_id, expires_on) =
> ('foo', '2010-11-24'::timestamp);

That didn't seem to work either:
test=# explain select * from ps where (client_id, expires_on) =
('123', '24.11.2010'::timestamp);
QUERY PLAN
---------------------------------------------------------------------------------
Index Scan using idx_wrong on ps (cost=0.00..8.29 rows=1 width=53)
Index Cond: (expires_on = '2010-11-24 00:00:00'::timestamp without time zone)
Filter: ((client_id)::text = '123'::text)

>
> merlin
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-07-08 14:11:30 Re: optimizer choosing the wrong index
Previous Message Peter Geoghegan 2010-07-08 11:57:32 Re: CREATE PROCEDURAL LANGUAGE plpythonu on windows, with EDB's 8.4.2 installer causes error