Re: Hey! ORDER BY in VIEWS? - Mailing list pgsql-sql

From Tom Lane
Subject Re: Hey! ORDER BY in VIEWS?
Date
Msg-id 11521.995233823@sss.pgh.pa.us
Whole thread Raw
In response to Re: Hey! ORDER BY in VIEWS?  ("Josh Berkus" <josh@agliodbs.com>)
List pgsql-sql
"Josh Berkus" <josh@agliodbs.com> writes:
>> Hmm, I just realized that there's a bug here: let's say you have
>> 
>> CREATE VIEW latest AS
>> SELECT * FROM news ORDER BY story_timestamp DESC LIMIT 1;
>> 
>> ie, this view gives you the latest news story.

> Why, exactly, do we need to support ORDER BY ... LIMIT in VIEWS, anyway?
> I'm frankly unclear on the utility of this ...

I think the above example is pretty compelling, don't you?  Easy to read
and it generates a very nice indexscan plan.


> If we gotta have 'em, though, Tom, you'd have to code in an exception to
> the VIEW optimizer that doesn't push down WHERE clauses if the VIEW has
> an ORDER BY ... LIMIT statement.  Sure you wanna get into this?

It's a one-line addition to code that already knows that certain kinds
of clauses (like UNION) prevent pushdown.  Just an oversight, not a
fundamental flaw.
        regards, tom lane


pgsql-sql by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: Hey! ORDER BY in VIEWS?
Next
From: Chris Ruprecht
Date:
Subject: Unknown values in int8 fields?