pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: George Essig <george.essig@gmail.com>
To: K C Lau <KCLau@attglobal.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: SELECT DISTINCT Performance Issue
Date: Wed, 8 Jun 2005 08:34:29 -0500
Message-ID: <6744b38505060806342e6a07d@mail.gmail.com> (raw)
In-Reply-To: <6.2.1.2.0.20050602190756.05ab2c70@localhost>
References: <6.2.1.2.0.20050602190756.05ab2c70@localhost>

On 6/2/05, K C Lau <KCLau@attglobal.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



view thread (6+ messages)  latest in thread

Message-ID: <6744b38505060806342e6a07d@mail.gmail.com>
Permalink:  ../6744b38505060806342e6a07d@mail.gmail.com/
Also on:    postgresql.org/message-id/6744b38505060806342e6a07d@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: george.essig@gmail.com, KCLau@attglobal.net
  Subject: Re: SELECT DISTINCT Performance Issue
  In-Reply-To: <6744b38505060806342e6a07d@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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