Ah, OK, I see that doing 'SELECT 1 FROM MyTable' returns a 1 for every row, so I can see where the effort is probably going. However, 'SELECT max(rowid) - 1 FROM MyTable' still only produces one result row (obviously I'm experimenting with a much smaller database now). Still need an explanation rather than just relying on my own speculation.

Cheers
guy

Guy Hindell wrote:
I have a fairly large table (10million rows) with a simple INTEGER PRIMARY KEY AUTOINCREMENT field.

Executing 'SELECT max(rowid) FROM MyTable' is very fast, as is 'SELECT min(rowid) FROM MyTable'.

However, 'SELECT max(rowid) - min(rowid) FROM MyTable' is slow (apparently accessing every row). Further, 'SELECT max(rowid) - 1 FROM MyTable' is slow - in fact using any constant in this expression (including 0) results in a slow query.

Finally, 'SELECT (SELECT  max(rowid) FROM MyTable') - 10' is very fast.

I am curious and would be grateful if someone can explain what is going on here.

guy


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------






-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to