On 9 Apr 2011, at 8:18pm, Igor Tandetnik wrote:

> Simon Slavin <slav...@bigfraud.org> wrote:
>> On 8 Apr 2011, at 2:34pm, Vadim Smirnov wrote:
>> 
>>> Tbl1(id1 INTEGER, id2 INTEGER, str TEXT)  2 records
>>> Tbl2(id INTEGER, Tbl1_id INTEGER, str TEXT) ~5000 records
>>> And SQL-query: SELECT Tbl2.id, MY_FUNC(Tbl1.str, Tbl2.str) FROM Tbl2 JOIN 
>>> Tbl1 ON Tbl1.id1=Tbl2.Tbl1_id WHERE Tbl2.id>1000 AND
>>> Tbl1.id2=1 LIMIT 50 We expected that MY_FUNC would be evaluated 50 times at 
>>> most, but it appeared 10000!
>>> Why so?
>> 
>> Your SELECT consists of a JOIN which tells SQLite to try every combination 
>> of one record from each table.  For each combination
>> it checks to see that all the conditions you gave are true. 
> 
> But the custom function is not involved in the WHERE clause. There doesn't 
> seem to be any reason to call it for rows that aren't going to be returned.

I guess either EXPLAIN or EXPLAIN QUERY PLAN would be helpful in figuring out 
what's going on.

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

Reply via email to