Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OR statement in sqlite3: error?

my sql query in sqlite3 ends with a OR statement. It looks like this:

select
   (...)
from
    T1, T2, .... Tn

where
     (...) and
     (
     (T5.v='s1' and T6.v='s2' and T7.v='s3') OR
     (T5.v='s4' and T6.v='s5' and T7.v='s6')
     )

the query returns no result.

However each distinct 'OR' conditions returns some rows (!)

where
     (...) and
     (
     (T5.v='s1' and T6.v='s2' and T7.v='s3')
     )

and

where
     (...) and
     (
     (T5.v='s4' and T6.v='s5' and T7.v='s6')
     )

is it a bug in sqlite3 or is it me ?

$ sqlite3 -version
3.6.20

update: I've got three non-unique indexes on T5.v, T6.v and T7.v

like image 701
Pierre Avatar asked Jun 20 '13 08:06

Pierre


1 Answers

As said previously in the comments, the changelog of sqlite 3-6-22 includes:

Fix bugs that can (rarely) lead to incorrect query results when the CAST or OR operators are used in the WHERE clause of a query.

Another OR bug was fixed in 3-7-4:

http://www.sqlite.org/src/info/80ba201079

Another one in 3-7-14-1:

Fix a bug (ticket [d02e1406a58ea02d]]) that causes a segfault on a LEFT JOIN that includes an OR in the ON clause.

and another one in 3-7-17:

http://www.sqlite.org/src/info/f2369304e4

I would suggest to upgrade to a more recent sqlite version, and see if it fixes the issue.

like image 165
Didier Spezia Avatar answered Nov 09 '22 19:11

Didier Spezia