在sqlite3中的OR语句:错误?

时间:2013-06-20 08:26:55

标签: sql sqlite boolean-expression

我在sqlite3中的sql查询以OR语句结束。它看起来像这样:

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')
     )

查询返回结果。

然而,每个不同的“OR”条件都返回一些行(!)

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

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

是sqlite3中的错误还是我?

$ sqlite3 -version
3.6.20

更新:我在T5.v,T6.v和T7.v上有三个非唯一索引

1 个答案:

答案 0 :(得分:1)

正如之前在评论中所述,sqlite 3-6-22 changelog包括:

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.

3-7-4

修复了另一个OR错误

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

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.

另一个 3-7-17

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

我建议升级到更新的sqlite版本,看看它是否解决了这个问题。