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

Re: window function docs

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: window function docs
Date: 2008-12-30 12:28:49
Message-ID: 495A1401.9090805@enterprisedb.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Robert Haas wrote:
> Currently, use of window functions always forces sorting, ...

That's not strictly true, actually. No sort is done if the input happens 
to be sorted already, as in:

postgres=# CREATE TABLE foo (id integer PRIMARY KEY);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index 
"foo_pkey" for table "foo"
CREATE TABLE
postgres=# INSERT INTO foo SELECT generate_series(1,100);
INSERT 0 100
postgres=# explain SELECT SUM(id) OVER (ORDER BY id) FROM (SELECT * FROM 
foo WHERE id < 100) AS a;
                                  QUERY PLAN 

-----------------------------------------------------------------------------
  WindowAgg  (cost=0.00..70.25 rows=800 width=4)
    ->  Index Scan using foo_pkey on foo  (cost=0.00..58.25 rows=800 
width=4)
          Index Cond: (id < 100)
(3 rows)

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

In response to

pgsql-hackers by date

Next:From: Heikki LinnakangasDate: 2008-12-30 12:40:46
Subject: Re: Synchronous replication, network protocol
Previous:From: Simon RiggsDate: 2008-12-30 10:42:45
Subject: Re: Synchronous replication, network protocol

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