Re: Question on PostgreSQL DB behavior w.r.t JOIN and sort order. - Mailing list pgsql-sql

From Rob Sargent
Subject Re: Question on PostgreSQL DB behavior w.r.t JOIN and sort order.
Date
Msg-id 56B97A37.5010905@gmail.com
Whole thread Raw
In response to Re: Question on PostgreSQL DB behavior w.r.t JOIN and sort order.  ("Venkatesan, Sekhar" <sekhar.venkatesan@emc.com>)
List pgsql-sql
<br /><br /><div class="moz-cite-prefix">On 02/08/2016 10:21 PM, Venkatesan, Sekhar wrote:<br /></div><blockquote
cite="mid:F84DE43FDACD4C45AA84E2DA016FAE2F1C65BEC8@MX105CL01.corp.emc.com"type="cite"><style><!--
 
/* Font Definitions */
@font-face{font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal,
div.MsoNormal{margin:0in;margin-bottom:.0001pt;font-size:11.0pt;font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink{mso-style-priority:99;color:blue;text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed{mso-style-priority:99;color:purple;text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText{mso-style-priority:99;mso-style-link:"Plain Text
Char";margin:0in;margin-bottom:.0001pt;font-size:11.0pt;font-family:"Calibri","sans-serif";}
span.PlainTextChar{mso-style-name:"Plain Text Char";mso-style-priority:99;mso-style-link:"Plain
Text";font-family:"Calibri","sans-serif";}
.MsoChpDefault{mso-style-type:export-only;font-family:"Calibri","sans-serif";}
@page WordSection1{size:8.5in 11.0in;margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1{page:WordSection1;}
--></style><div class="WordSection1"><p class="MsoPlainText">Hi Tom,<p class="MsoPlainText"> <p
class="MsoPlainText">Youcan disregard the "TOP 10" modifier. That was added by me to bring down the huge number of
resultsbeing returned.<p class="MsoPlainText">Even without the TOP modifier, SQL server is returning rows in sorted
order(sorting columns based on the r_object_id (1<sup>st</sup>) column I think) but PostgreSQL doesn’t.<p
class="MsoPlainText">Isthis anything to do with indexes?<p class="MsoPlainText">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?<p
class="MsoPlainText"> <pclass="MsoPlainText">-----Original Message-----<br /> From: Tom Lane [<a
class="moz-txt-link-freetext"href="mailto:tgl@sss.pgh.pa.us">mailto:tgl@sss.pgh.pa.us</a>] <br /> Sent: Tuesday,
February09, 2016 10:30 AM<br /> To: Venkatesan, Sekhar<br /> Cc: <a class="moz-txt-link-abbreviated"
href="mailto:pgsql-sql@postgresql.org">pgsql-sql@postgresql.org</a><br/> Subject: Re: [SQL] Question on PostgreSQL DB
behaviorw.r.t JOIN and sort order.<p class="MsoPlainText"> <p class="MsoPlainText">"Venkatesan, Sekhar" <<a
href="mailto:sekhar.venkatesan@emc.com"moz-do-not-send="true"><span style="color:windowtext;text-decoration:none"><a
class="moz-txt-link-abbreviated"href="mailto:sekhar.venkatesan@emc.com">sekhar.venkatesan@emc.com</a></span></a>>
writes:<pclass="MsoPlainText">> I am seeing this behavior change in postgreSQL DB when compared to SQL Server DB
whenJOIN is performed. The sort order is not retained when JOIN is performed in PostgreSQL DB.<p
class="MsoPlainText"> <pclass="MsoPlainText">What sort order?  You did not specify any ORDER BY clause, so the DBMS is
entitledto return rows in any order it feels like.<p class="MsoPlainText"> <p class="MsoPlainText">I do not know
anythingabout this "top 10" modifier you've got in the SQL Server version, but I suspect it's implying a sort order. 
InPostgres, if you want a specific row ordering, you need to say ORDER BY.<p class="MsoPlainText"> <p
class="MsoPlainText">                                               regards, tom lane</div></blockquote> In my
experience,this is ofter termed "disc order", implying what ever order the resultant tuples were discovered while
processingthe data.  If MSSQL server is giving an order without explicit instruction to do so you may be incurring an
unwantedsort operation.  Is (any of) the data in a "clustered index": iirc that implies an on-disc ordering and the
resultset my be reflecting that.<br /><br /> 

pgsql-sql by date:

Previous
From: "Venkatesan, Sekhar"
Date:
Subject: Re: Question on PostgreSQL DB behavior w.r.t JOIN and sort order.
Next
From: "David G. Johnston"
Date:
Subject: Re: Question on PostgreSQL DB behavior w.r.t JOIN and sort order.