0

看看以下三个查询。我无法理解评估为 TRUE 的条件在附加到 where 子句时如何不会返回行。我希望在第二个查询中获得 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)
4

1 回答 1

1

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

此行为是由于 select 中的表达式与 where 子句中的表达式的计算方式不同这一事实引起的。后者利用底层的 lucene 索引,似乎对 NOT 进行了错误的转换,这会阻止找到空列表。

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

于 2017-03-21T09:04:36.210 回答