Re: Nested query performance issue

From: Віталій Тимчишин <tivv00(at)gmail(dot)com>
To: Glenn Maynard <glennfmaynard(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Nested query performance issue
Date: 2009-04-09 09:25:26
Message-ID: 331e40660904090225y3c2ddc37gcfb8cb97e301d2f8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

OK, got to my postgres. Here you are:

create or replace function explode_array(in_array anyarray) returns setof
anyelement as
$$
select ($1)[s] from generate_series(1,array_upper($1, 1)) as s;
$$
language sql immutable;

SELECT s.* FROM score s
WHERE s.id IN (
select
-- Get the high scoring score ID for each game:
explode_array(ARRAY(
-- Get the high score for game g:
SELECT s2.id FROM score s2 WHERE s2.game_id = g.id ORDER BY
s2.score DESC LIMIT 5
))
FROM game g
);

It takes ~64ms for me

Best regards, Vitaliy Tymchyshyn

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Heikki Linnakangas 2009-04-09 11:29:11 Re: Nested query performance issue
Previous Message Rainer Mager 2009-04-08 22:49:39 Re: difficulties with time based queries