From: Josh Berkus <josh@agliodbs.com>
To: Greg Spiegelberg <gspiegelberg@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Can WINDOW be used?
Date: Fri, 13 Aug 2010 14:17:02 -0700
Message-ID: <4C65B64E.9070005@agliodbs.com> (raw)
In-Reply-To: <AANLkTim5vdL6Q_Y3odgPEQAmBYrOVa=gDKzmNLko2abU@mail.gmail.com>
References: <AANLkTim5vdL6Q_Y3odgPEQAmBYrOVa=gDKzmNLko2abU@mail.gmail.com>
> wxd0812=# EXPLAIN ANALYZE
> wxd0812-# SELECT * FROM
> wxd0812-# (SELECT DISTINCT ON (key1_id,key2_id) * FROM sid120.data
> ORDER BY key1_id,key2_id,time_id DESC) x
> wxd0812-# WHERE NOT deleted;
SELECT * FROM (
SELECT data.*,
rank() as rank over
( partition by key1_id, key2_id order by time_id DESC )
FROM data
) as rankings
WHERE rank = 1 AND NOT deleted;
--
-- Josh Berkus
PostgreSQL Experts Inc.
http://www.pgexperts.com
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: josh@agliodbs.com, gspiegelberg@gmail.com
Subject: Re: Can WINDOW be used?
In-Reply-To: <4C65B64E.9070005@agliodbs.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