List:General Discussion« Previous MessageNext Message »
From:Anders Karlsson Date:May 3 2004 8:16pm
Subject:Re: urban myth?
View as plain text  
Also, I'd say that it depends on what you mean by "row". If you mean the 
same physical data as
was previously displayed, then they probably WILL come back in the same 
order, but there
are no guarantees (a dataset is always unordered, unless something else 
is specified).

But on the other hand, if by row, we mean "the same unique data", well 
then it might change as someone
else might delete a row, and then someone else again might insert the 
same unique data. Same data, but
a different physical row. In this case, data will certainly come back in 
a different order, and if you only
look at, say, the unique identifier to determine row position, then the 
row might well have changed it's
position within the row, fact is, it is much more likely that it has!

Finally, a quote from Chris Date, as read in "Relatuional databases - 
Selected writings", rom the
section entitled "Relational Database: An overview": "If the entire 
ORDER BY clause is omitted, the result appears in
unpredictable order" and "A table is an unordered set of rows". And as 
the result of a SELECT is
also considered a relation (or a table), this latter quote applies too.

Boyd E. Hemphill wrote:

>To all who answered thank you.  This answer below is the one that I can
>use to convince him what he proposes is not necessarily safe.  
>Now I just need to decide how to convince him it was his idea :-)
>Best Regards,
>Boyd E. Hemphill
>Triand, Inc.
>O:  (512) 248-2287
>M:  (713) 252-4688
>-----Original Message-----
>From: Michael Stassen [mailto:Michael.Stassen@stripped] 
>Sent: Monday, May 03, 2004 12:57 PM
>To: Bob Ramsey
>Cc: mysql@stripped
>Subject: Re: urban myth?
>Bob Ramsey wrote:
>>Ah, but the ordering is not random.  As your example has it, the
>>are in the order that the entries were inserted into the table.  There
>>is an explanation for the order of the returned data.
>Apparently not random, but not in the order inserted either.  Consider:
>create temporary table foo (num int(10));
>insert into foo values (1), (2), (3), (4), (5);
>select * from foo;
>delete from foo where num = 3;
>insert into foo values (6);
>insert into foo values (3);
>mysql> select * from foo;
>| num  |
>|    1 |
>|    2 |
>|    6 |
>|    4 |
>|    5 |
>|    3 |
>6 rows in set (0.01 sec)
>(Same example as before with the "delete...where num=6" removed.)  Note
>6 is where the 3 was originally, because the slot where the first 3 was 
>inserted/deleted was reused for the 6.
>This trivial example yields results which are ordered neither by num nor
>the order inserted.  The lesson is clear: The *only* way to be sure your
>rows are sorted in a particular way is to explicitly request it with an 
>ORDER BY clause, as several others have pointed out.  This is really a 
>fundamental principle: It is the data in the row that matters, not how
>where it is stored.

    __  ___     ___ ____  __
   /  |/  /_ __/ __/ __ \/ /  Anders Karlsson (anders@stripped)
  / /|_/ / // /\ \/ /_/ / /__ MySQL AB, Sales Engineer
 /_/  /_/\_, /___/\___\_\___/ Stockholm
        <___/ Cellphone: +46 708 608121

Create table results in (errno: 121)Tom Brown22 Apr
  • Re: Create table results in (errno: 121)Martijn Tonies22 Apr
  • Re: Create table results in (errno: 121)Tom Brown22 Apr
  • Re: Create table results in (errno: 121)Adam28 Apr
    • urban myth?Boyd E. Hemphill3 May
      • Re: urban myth?Peter J Milanese3 May
      • Re: urban myth?Daniel Clark3 May
      • Re: urban myth?Garth Webb3 May
        • Re: urban myth?Bob Ramsey3 May
          • Re: urban myth?Josh Trutwin3 May
          • Re: urban myth?Garth Webb3 May
          • Re: urban myth?Michael Stassen3 May
            • RE: urban myth?Boyd E. Hemphill3 May
              • Re: urban myth?Anders Karlsson3 May
              • Re: urban myth?Michael T. Babcock13 May
      • Re: urban myth?Josh Trutwin3 May
      • Re: urban myth?Jeremy Zawodny3 May
      • Re: urban myth?gerald_clark3 May
        • Re: urban myth?Peter J Milanese3 May
Re: Create table results in (errno: 121)beacker22 Apr
RE: urban myth?Mike Johnson3 May
Re: urban myth?Udikarni3 May