Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Does SELECT TOP N work in Sybase ASE

I was wondering how this query is executed :

SELECT TOP 10 * FROM aSybaseTable
WHERE aCondition

The fact is that this query is taking too much time to return results. So I was wondering if the query is smart enough to stop when the results reach 10 rows of if it returns all the possible results and then print only the 10 first rows.

Thanks in advance for your replies !

like image 794
Fares Avatar asked Oct 25 '25 14:10

Fares


1 Answers

When using select top N the query is still executed fully, just the data page reads stop after the specified number of rows is affected. All the index page reads, and sorts still have to occur, so depending on the complexity of the where condition or subqueries, it can definitely still take time to execute. select top N is functionally similar to using set rowcount

like image 109
Michael Gardner Avatar answered Oct 28 '25 03:10

Michael Gardner