This was already addressed. If the ORDER BY clause cannot be fulfilled by 
virtue of the query plan, the full result set must be retrieved and sorted 
before even the first row can be returned. This is expensive (memory and/or IO 
bandwidth) and makes the query seem unresponsive and therefore should be 
avoided if possible.

-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] Im 
Auftrag von J Decker
Gesendet: Montag, 18. September 2017 14:59
An: SQLite mailing list <sqlite-users@mailinglists.sqlite.org>
Betreff: *** suspected spam or bulk *** Re: [sqlite] [EXTERNAL] Number of rows 
in answer set

What if the select had an ORDER BY ? wouldn't it have to pull the full set of 
rows ?

On Mon, Sep 18, 2017 at 5:11 AM, Simon Slavin <slav...@bigfraud.org> wrote:

>
>
> On 18 Sep 2017, at 10:41am, David Wellman
> <dwell...@ward-analytics.com>
> wrote:
>
> > So to answer my original question: there isn't an api that gives
> > this
> value ** because ** SQLite doesn't build the full answer set before
> returning from that first sqlite3_step function call.
>
> Correct.  SQLite knows how many results it will return only when you
> tell it to take another sqlite3_step() and it cannot find any more
> rows which fit your "WHERE" clause.
>
> This is because SQLite was designed to be small and work on tiny
> embedded computers (i.e. a handheld recording device or nowdays a
> watch) and storing the complete result-set before returning the first
> row might take a lot of memory.  It might have thousands of rows in.
>
> If you want to know how many rows will be returned, use
>
> SELECT COUNT(*) WHERE whatever
>
> This returns just one row, and does its calculation without having to
> store each row that satisfies the WHERE clause.  With an appropriate
> index it can be surprisingly fast and might let your application work
> the way you had expected.
>
> Simon.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: h...@scigames.at

This communication (including any attachments) is intended for the use of the 
intended recipient(s) only and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication. Thank you for your cooperation.


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to