On 5/29/17, x <tam118...@hotmail.com> wrote:
> Thanks Clemens, that clears that up.
>
> I’m still left wondering though why it calculates 2+2 every step in
>
> ‘select 2+2 from Tbl;’
>

All result values must be recomputed on every step because the
application can change the value by (for example) calling
sqlite3_column_text and thus causing the integer result to be
converted into a string result.  The result needs to be reset back to
an integer for the next row.

It is true that SQLite could compute 2+2 and store the result then
copy the result into the result register for each result row, but
doing the copy is not measurably faster than simply redoing the 2+2
computation.

You will notice that in a more complex computation like:

    SELECT 2*15-5+11/5<<3*1 FROM tbl

That the "2*15-5+11/5" and "3*1" subexpressions are computed just
once, and only the final "<<" operator is repeated for each row.

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

Reply via email to