Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Derp, yes. It's not an auxiliary index. However, it still seems weird for a full table scan to be implemented this way instead of whatever's convenient given the page layout. Why does it guarantee that the results will be in PK order?


It does not guarantee it. A select without a order by clause is not guaranteed to be in a repeatable or consistent order, neither in SQL nor MySQL.

MySQL does have an implicit ordering on GROUP BY queries, but it is deprecated and should not be relied on.


It always amazes me how many people don't know that there is no guaranteed repeatable order in a select statement without an order by clause.


The problem is compounded by the fact that with the small data sets people tend to use to test during development, things are usually returned in insertion order.


Oh, it can often be worse. People sometimes try to do tricky things like running totals by relying on implicit order in SQL queries. Often they are trying to squeeze as much performance out of the database server as possible (usually SQL Server) by avoiding cursors.

My favourite ever SQL Server hack was one done by a guy called Jeff Moden, who came up with a running total update that relied on a specific quirk of SQL Server clustered indexes. The amount of effort he put into it is quite remarkable! [1]

1. (Create a temp account to check it out, they're not spammers) http://www.sqlservercentral.com/articles/T-SQL/68467/


Many MySQL applications expect results to be delivered in primary key order if no "order by" clause is supplied


That seems dumb. If you require a particular ordering, you should have to specify it and it might cost extra to put the results in that order.


Then those MySQL apps are broken.


One issue might be that InnoDB by default uses a single idb file where all tables are stored. Further, this file also never shrinks even if you delete rows or drop indecies. So basically if page n contains your data page n + 1 might be useless to you, so InnoDB looks at pages by pk instead to only read pages it needs. (All this is my wild speculation.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: