| Author |
Topic |
|
gugul
Starting Member
2 Posts |
Posted - 2010-11-12 : 09:36:27
|
| Why in V7 you could do a Select with more then 1 row and fetch the 1st row, using for exemple an order by statment by age."Controling" the -811 error you would get the lowest age.With the V8 it returns the 2nd row. Why change that?Now i've to use fetch first row only.The problem is that now i've to change all my programes!Why change something like that? |
|
|
Arnold Fribble
Yak-finder General
1961 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
gugul
Starting Member
2 Posts |
Posted - 2010-11-12 : 11:47:56
|
| I know how to solve the problem. What i would like to know is why change something that work before.Maybe what i did, using an db2 error to do something, is not a good thing.But it worked, and now it doesn't. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-11-12 : 12:49:59
|
quote: Originally posted by X002548 ...I thought there 5 operators that caused a sort....What am I missing
No idea about DB2, but in SQL there are two ways to do group by, distinct and union. One involves a sort, the other a hash.--Gail ShawSQL Server MVP |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-11-12 : 14:48:38
|
quote: Originally posted by X002548 And I didn't think anything BUT ORDER BY caused an order in sql server
Mostly correct. Nothing but order by guarantees the order of a returned resultset, but there are a number of operators that require the data in a particular order and may either sort the data or require a sort earlier in the planStream aggregateUnion (can be implemented as a Sort/Distinct sort)Distinct (can be implemented as a Sort/Distinct sort)Merge joinWhether or not that affects the final order of results is another matter--Gail ShawSQL Server MVP |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-11-12 : 15:28:19
|
quote: Originally posted by X002548 ok...so it must do something internal..BUT DOES NOT guarantee that order in the result set..correct?
Correctquote: So....ORDER BY is the only guarantee
Correctquote: DB2 USED to guarantee the order...but has now stopped...which is freakin unbelievable
Documented guaranteed order, or just always behaved that way?If the latter, SQL's had the same recently in several cases. Like order by in a view definition. The order by was incorrectly honoured in SQL 2000, lots of people assumed it was by design. 2005 'fixed' it.--Gail ShawSQL Server MVP |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-11-13 : 05:40:56
|
"QL's had the same recently in several cases. Like order by in a view definition. The order by was incorrectly honoured in SQL 2000, lots of people assumed it was by design. 2005 'fixed' it."Although its much wider than that, isn't it Gail?I figure that lots of people forget (or think they don't need) to use ORDER BY because their query is simple and "always" comes back in Clustered Index order, so it gets through DEV and QA tests without breaking ... but in production starts giving random sorts, maybe only very occasionally, when some data happens to be in RAM and SQL short-circuits the normal process to use that data before loading the rest from disk (and in the absence of an explicit ORDER BY returns it in whatever order that turns out to be).On this matter I think there should either be:DEV mode that randomises unsorted-SELECT statements to flush out bugsand/orLINT tool, or "verbose warnings" DEV mode, that moans about "loose" code.JOIN MyOtherTable on MyVarcharCol = MyIntColfor example. Don't want it to moan? Put a CAST in and then SQL 2000 SP4 won't be a disaster for you (old news ... but no doubt there is a similar Gotcha! waiting in the wings for some future S/Pack or Upgrade)I wish I knew how to use a compiler-compiler, or a lexer or somesuch, as I imagine it would not be hard to build. But MS using MS SQL's own Lexer must be a better route as it could easily be coaxed into spitting out a warning when it had to do implicit casts, and in other scenarios like:SELECT FirstColumnIWant SecondColumnButIForgotTheComma where AS was omitted. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-11-13 : 14:35:53
|
quote: Originally posted by Kristen... but in production starts giving random sorts, maybe only very occasionally, when some data happens to be in RAM and SQL short-circuits the normal process to use that data before loading the rest from disk (and in the absence of an explicit ORDER BY returns it in whatever order that turns out to be).
More commonly because parallelism's kicked in or a join or group by has switched to hash.Merry-go-round scans (what you're describing there) only happen under very specific circumstances.quote: LINT tool, or "verbose warnings" DEV mode, that moans about "loose" code.
But how would you tell a query that has no order by but should have one from one that doesn't need to return in any specific order (perhaps because the front end is sorting it)?--Gail ShawSQL Server MVP |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-11-14 : 05:10:18
|
| "But how would you tell a query that has no order by but should have one from one that doesn't need to return in any specific order (perhaps because the front end is sorting it)?"Th LINT tools that I have used (for C/C++ and Javascript) allow a comment (in a special format) to be used to indicate that a particular warning should be ignored. Bit like using a CAST really, you are indicating that you know that such-and-such is happening and are "authorising" it. You can turn a warning off for all/part of a script, and then turn it back on again. |
 |
|
|
|