agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Question on PostgreSQL DB behavior w.r.t JOIN and sort order.
Date: Mon, 8 Feb 2016 22:33:43 -0700
Message-ID: <56B97A37.5010905@gmail.com> (raw)
In-Reply-To: <F84DE43FDACD4C45AA84E2DA016FAE2F1C65BEC8@MX105CL01.corp.emc.com>
References: <F84DE43FDACD4C45AA84E2DA016FAE2F1C65BE54@MX105CL01.corp.emc.com>
	<21082.1454994009@sss.pgh.pa.us>
	<F84DE43FDACD4C45AA84E2DA016FAE2F1C65BEC8@MX105CL01.corp.emc.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>



On 02/08/2016 10:21 PM, Venkatesan, Sekhar wrote:
>
> Hi Tom,
>
> You can disregard the "TOP 10" modifier. That was added by me to bring 
> down the huge number of results being returned.
>
> Even without the TOP modifier, SQL server is returning rows in sorted 
> order (sorting columns based on the r_object_id (1^st ) column I 
> think) but PostgreSQL doesn’t.
>
> Is this anything to do with indexes?
>
> So from what I understand, you say in postgres, if the sort order is 
> not specified, postgres returns results in any order. Am I right?
>
> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Sent: Tuesday, February 09, 2016 10:30 AM
> To: Venkatesan, Sekhar
> Cc: pgsql-sql@postgresql.org
> Subject: Re: [SQL] Question on PostgreSQL DB behavior w.r.t JOIN and 
> sort order.
>
> "Venkatesan, Sekhar" <sekhar.venkatesan@emc.com 
> <mailto:sekhar.venkatesan@emc.com>> writes:
>
> > I am seeing this behavior change in postgreSQL DB when compared to 
> SQL Server DB when JOIN is performed. The sort order is not retained 
> when JOIN is performed in PostgreSQL DB.
>
> What sort order?  You did not specify any ORDER BY clause, so the DBMS 
> is entitled to return rows in any order it feels like.
>
> I do not know anything about this "top 10" modifier you've got in the 
> SQL Server version, but I suspect it's implying a sort order.  In 
> Postgres, if you want a specific row ordering, you need to say ORDER BY.
>
> regards, tom lane
>
In my experience, this is ofter termed "disc order", implying what ever 
order the resultant tuples were discovered while processing the data.  
If MSSQL server is giving an order without explicit instruction to do so 
you may be incurring an unwanted sort operation.  Is (any of) the data 
in a "clustered index": iirc that implies an on-disc ordering and the 
result set my be reflecting that.

view thread (17+ messages)  latest in thread

Message-ID: <56B97A37.5010905@gmail.com>
Permalink:  ../56B97A37.5010905@gmail.com/
Also on:    postgresql.org/message-id/56B97A37.5010905@gmail.com

reply

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-sql@postgresql.org
  Cc: robjsargent@gmail.com
  Subject: Re: Question on PostgreSQL DB behavior w.r.t JOIN and sort order.
  In-Reply-To: <56B97A37.5010905@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox