Benjamin,

Benjamin Pflugmann wrote:

> Hi.
>
> I guess your "problem" comes from the fact that SQL has no concept of
> internal order. If you do not specify an ORDER BY clause, the order or
> records returned is undefined, i.e. random.

That's what I was figuring.  I asked because I wanted it confirmed.  Thank
you.

>
>
> Of course, MySQL has some kind of internal order depending on many
> factors, but you may not rely on it. And neither you may rely on the
> fact that a PRIMARY KEY influences the internal order. You have to use
> an ORDER BY clause if you want to get a sorted result (of course, you
> want a key to speed up the ORDER BY clause).

Hmmm.  Perhaps I'm misled by the default behaviour of other database engines,
but I was taught that the primary key was stored in the database to optimize
search/insert/delete - which meant *sorted*.  That is why you don't want a
large (complex) primary key on tables that must run "fast" - the overhead of
sorting each insert/delete negatively affects performance. Or so I was taught,
anyway (back in the dark ages - primative data structures and all that <G>).

Cheers,

-Richard

>
>
> As said, the (sorting) behaviour without ORDER BY is undefined
> according to the specification and may change without notice.
>
> Bye,
>
>         Benjamin.
>
> On Mon, Mar 04, 2002 at 09:56:53PM -0700, [EMAIL PROTECTED] wrote:
> > Greetings!
> >
> > If you do not have an index on any column in a table, how does mysql
> > handle repeated queries (i.e. SELECT * FROM report;)
> >
> > I am noticing that if I run the following three queries, I get different
> > results for the third query:
> >
> > SELECT * FROM report;
> > SELECT * FROM report ORDER BY lastname;
> > SELECT * FROM report;
> >
> [...]
> > p.s. This is for my understanding.  I solved my actual problem by simply
> > placing a primary key on the appropriate columns - as I should have from
> > the beginning! <G>).
> [...]
>
> --
> [EMAIL PROTECTED]


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to