On Fri, Oct 19, 2012 at 5:08 AM, Steinar Midtskogen
<stei...@latinitas.org>wrote:

> Hi
>
> Suppose I have a virtual table v with a column c.  Then, if I do:
>
>   SELECT c, c+1, c-1 FROM v;
>
> xColumn() will then only be called once per row.  Which is all good.
>
> But if I add any constraints on c, e.g.:
>
>   SELECT c, c+1, c-1 FROM v WHERE c IS NOT NULL;
>
> Then xColumn() will get called a second time for c, which seems
> wasteful if c takes time to compute.  Or very bad if the computation
> has side effects (which it probably shouldn't have).
>
> Is there any reason for this behaviour?
>

xColumn() might be called any number of times for a single column - once,
one hundred times, not at all.  SQLite makes no guarantees about this.  The
virtual table implementation must return the same value for all calls.

The reason is that it is sometimes convenient for the SQLite core to call
xColumn multiple times and that it is not normally a problem for the
virtual table to implement this efficiently, using caching if necessary.


>
> My SQlite version is 3.7.14.
>
> --
> Steinar Midtskogen
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



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

Reply via email to