Skip site navigation (1) Skip section navigation (2)

Re: slow subselects

From: ismo(dot)tuononen(at)solenovo(dot)fi
To: Marko Niinimaki <manzikki(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: slow subselects
Date: 2007-02-20 07:21:45
Message-ID: Pine.LNX.4.64.0702200918510.10066@ismoli.solenovo.jns (view raw, whole thread or download thread mbox)
Lists: pgsql-performance

select studentid,max(score) from studentprofile group by studentid;

or if you want only those which exists in students

select s.studentid,max(p.score)
from studentprofile p,students s
where s.studentid=p.studentid
group by s.studentid;

if it takes longer than 1-2 seconds something is seriously wrong


On Tue, 20 Feb 2007, Marko Niinimaki wrote:

> Hello,
> I'm having a surprising performance problem with the following simple
> 'highscore report'
> select studentid, (select max(score) from
> studentprofile prof where prof.studentid = students.studentid) from students;
> I have indexes on students(studentid) and studentprofile(studentid).
> Row counts: about 160 000 in each students and studentprofile.
> Postgres version:
> postgresql-8.1.8-1.fc5
> postgresql-server-8.1.8-1.fc5
> This is a dual-processor 3Ghz 64bit box with 2 GB mem.
> Running the query takes 99% CPU and 1% mem.
> I have the same data in MSSQL and there the query takes less than a
> minute. With postgres it seems to take several hours.
> Is there a way of making this faster?
> Marko
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>       choose an index scan if your joining column's datatypes do not
>       match

In response to

pgsql-performance by date

Next:From: Tom LaneDate: 2007-02-20 07:43:06
Subject: Re: slow subselects
Previous:From: Marko NiinimakiDate: 2007-02-20 07:10:55
Subject: slow subselects

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group