Re: slow subselects - Mailing list pgsql-performance

From Tom Lane
Subject Re: slow subselects
Date
Msg-id 22952.1171957386@sss.pgh.pa.us
Whole thread Raw
In response to slow subselects  ("Marko Niinimaki" <manzikki@gmail.com>)
Responses Re: slow subselects  ("Marko Niinimaki" <manzikki@gmail.com>)
List pgsql-performance
"Marko Niinimaki" <manzikki@gmail.com> writes:
> 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).

The optimal index for this would be on studentprofile(studentid,score).
A quick test says that PG 8.1 knows what to do with such an index ---
what does EXPLAIN show for this query?

            regards, tom lane

pgsql-performance by date:

Previous
From: ismo.tuononen@solenovo.fi
Date:
Subject: Re: slow subselects
Next
From: "Jim C. Nasby"
Date:
Subject: Re: Query Optimization