on 2011 Apr 22 10:03 AM
Hi
If I run SET ROWCOUNT 10; and SELECT * FROM roles ORDER BY sort_order (generally spoken a SELECT statement with an ORDER BY clause)
on SQL Anywhere a 12.0.1:3311 database, SQL Anywhere only returns 9 records instead of 10 records. The same (wrong) result happens in Sybase 11.0.1.2569. The wrong result happens when the SELECT statement uses the ORDER BY clause.
Running the above statements in SQL Anywhere 11.0.1.2472 server version, SQL Anywhere returns 10 records as expected.
Regards, Robert
Thanks for reporting this. The problem with SET ROWCOUNT is indeed a bug, it was introduced in 11.0.1 EBF build 2541 and in version 12.0.0+ as a result of enhancements to support arithmetic expressions in TOP/START AT and LIMIT/OFFSET. We are tracking this problem as issue 667900.
The problem affects simple SELECT statements for which
The problem is fixed in 11.0.1 build 2599. Fixes for 12.0.x releases will also be available shortly.
Possible workarounds are:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not as a solution to this problem - but when you do not need to use T-SQL, I would highly recommend to use the "SELECT TOP n * FROM roles" syntax. IMHO, it's the SQL Anywhere way to restrict result sets.
As to the docs, SET ROWCOUNT seems to be based on estimates and seems to restrict the number of fetched rows - as such I am not sure whether it's guaranteed to restrict the computed result set in the same way as TOP n does.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
According to the Sybase docu, it seems to me the result for SET ROWCOUNT can be non-deterministic. But this also seems to be the case for SELECT TOP n ...
If I run in ISQL for example SELECT TOP 10 * FROM roles - I get a warning saying "The result returned is non-deterministic". This warning doesn't appear when I add the ORDER BY clause.
I agree that TOP n implies an order of rows, therefor "needs" the ORDER BY clause to work properly. But then, TOP can not be the alternative to SET ROWCOUNT, as this does not imply an order (therefor not giving a warning when not using the ORDER BY clause). The background is that we use Servoy as development environment which uses ROWCOUNT (as far as I understand) implicitly to restrict the number of displayed records. And with the above mentioned versions of SQL Anywhere 11 and 12, the whole applications developed are broken.
You did say that your SELECT statements included ORDER BY, so TOP would be an alternative.
There are some statements with ORDER BY clause and some without using the ORDER BY clause. The problem is that the Servoy IDE (www.servoy.com) does handle this "in the background" as it is "automatically" generating an SQL statement depending on a form bound to a table. So as a developer I have no (or limited) influence to this. PS: I figured out how to make a case with Sybase and did open a case.
User | Count |
---|---|
66 | |
11 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.