评估为TRUE的表达式在WHERE子句中不起作用

时间:2017-03-17 12:40:58

标签: cratedb

看看以下三个查询。我无法理解当附加到where子句时,求值为TRUE的条件如何不返回行。我希望在第二个查询中获取User1,因为第一个查询显示条件的计算结果为TRUE。

cr> select full_name, labels, not 'autogenerated' = ANY(labels), not 'autogenerated' = ANY(labels) or labels = [] from testdb_master_core_users;
+----------------+-------------------+-------------------------------------+--------------------------------------------------------+
| full_name      | labels            | (NOT 'autogenerated' = ANY(labels)) | ((NOT 'autogenerated' = ANY(labels)) OR (labels = [])) |
+----------------+-------------------+-------------------------------------+--------------------------------------------------------+
| User2 Lastname | ["otherlabel"]    | TRUE                                | TRUE                                                   |
| User3 Lastname | ["autogenerated"] | FALSE                               | FALSE                                                  |
| User1 Lastname | []                | TRUE                                | TRUE                                                   |
+----------------+-------------------+-------------------------------------+--------------------------------------------------------+
SELECT 3 rows in set (0.003 sec)
cr> select full_name, labels, not 'autogenerated' = ANY(labels) from testdb_master_core_users where not 'autogenerated' = ANY(labels);
+----------------+----------------+-------------------------------------+
| full_name      | labels         | (NOT 'autogenerated' = ANY(labels)) |
+----------------+----------------+-------------------------------------+
| User2 Lastname | ["otherlabel"] | TRUE                                |
+----------------+----------------+-------------------------------------+
SELECT 1 row in set (0.002 sec)
cr> select full_name, labels, not 'autogenerated' = ANY(labels) from testdb_master_core_users where not 'autogenerated' = ANY(labels) or labels = [];
+----------------+----------------+-------------------------------------+
| full_name      | labels         | (NOT 'autogenerated' = ANY(labels)) |
+----------------+----------------+-------------------------------------+
| User2 Lastname | ["otherlabel"] | TRUE                                |
| User1 Lastname | []             | TRUE                                |
+----------------+----------------+-------------------------------------+
SELECT 2 rows in set (0.002 sec)

1 个答案:

答案 0 :(得分:1)

您的期望是正确的 - 第二个查询也应返回User1。

此行为是由于select中的表达式的计算方式与where子句中的表达式不同而导致的。后者利用底层的lucene索引,似乎对NOT进行了错误的转换,从而阻止了空列表的发现。

此问题将在即将发布的1.0.6和1.1.1版本中修复。