Re: Different order by behaviour depending on where clause?

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Jan Bakuwel <jan(dot)bakuwel(at)greenpeace(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Different order by behaviour depending on where clause?
Date: 2011-10-28 05:13:26
Message-ID: CAFj8pRBRJkJS-KSOL-1wdnhmG4ZEv9LFfXmUZFxmzUfzA+ymgw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello

2011/10/28 Jan Bakuwel <jan(dot)bakuwel(at)greenpeace(dot)org>:
> Hi,
>
> I have a compound query with some grouping, having and order by's saved
> as a view, say with name "myview".
>
> A) select * from "myview" returns the results as expected in the correct
> order (the order by is on fields "Category", "Year", "Month" and a few
> other fields). The results are correctly ordered by these fields as
> specified in the view.
>
> B) select * from "myview" where "Year"=2011 and "Month"=1 also returns
> the results as expected in the correct order (a subset of A).
>
> however
>
> C) select * from "myview" where "Year"=2011 and "Month" >= 1 and "Month"
> <= 1 returns the same resultset as B but the order of the rows is not
> correct (not even close; haven't been able to see any pattern).
>
> Any idea how I can further analyse/diagnose this?
>
> regards,
> Jan
>

Look on EXPLAIN - these queries will have a different execution plan

http://www.postgresql.org/docs/8.4/static/sql-explain.html

Regards

Pavel Stehule

>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Harald Fuchs 2011-10-28 09:31:58 Re: optimize self-join query
Previous Message Lee Hachadoorian 2011-10-28 05:12:41 Re: optimize self-join query