Re: SELECT DISTINCT Performance Issue

From: George Essig <george(dot)essig(at)gmail(dot)com>
To: K C Lau <KCLau(at)attglobal(dot)net>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: SELECT DISTINCT Performance Issue
Date: 2005-06-08 13:34:29
Message-ID: 6744b38505060806342e6a07d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 6/2/05, K C Lau <KCLau(at)attglobal(dot)net> wrote:
...
>
> select DISTINCT ON (PlayerID) PlayerID,AtDate from Player where
> PlayerID='22220' order by PlayerID desc, AtDate desc;
> The Player table has primary key (PlayerID, AtDate) representing data over
> time and the query gets the latest data for a player.
>
>
...
> esdt=> explain analyze select DISTINCT ON (PlayerID) PlayerID,AtDate from
> Player
> where PlayerID='22220' order by PlayerID desc, AtDate desc;
> Unique (cost=0.00..2507.66 rows=1 width=23) (actual time=0.000..187.000
> rows=1 loops=1)
> -> Index Scan Backward using pk_player on player (cost=0.00..2505.55
> rows=8
> 43 width=23) (actual time=0.000..187.000 rows=1227 loops=1)
> Index Cond: ((playerid)::text = '22220'::text)
> Total runtime: 187.000 ms
>

Is PlayerID an integer datatype or a text datatype. It seems like
PlayerID should be an integer data type, but postgres treats PlayerID
as a text data type. This is because the value '22220' is quoted in
your query. Also, the explain analyze output shows "Index Cond:
((playerid)::text = '22220'::text".

George Essig

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Grega Bremec 2005-06-08 13:49:16 Re: Filesystem
Previous Message Kim Bisgaard 2005-06-08 12:32:28 Re: full outer performance problem