2017-03-17 58 views
0

查看以下三個查詢。我無法理解,如果評估爲TRUE的條件在附加到where子句時不會返回行。我期望在第二個查詢中獲得User1,因爲第一個查詢顯示條件評估爲TRUE。評估爲TRUE的表達式在WHERE子句中不起作用

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) 
+0

在GitHub中添加了與此相關的故障單:https://github.com/crate/crate/issues/5132 –

回答

0

您的期望是正確的 - 第二個查詢也應該返回User1。

此行爲是由select中的表達式的求值與where子句中的表達式不同而引起的。後者利用底層的lucene索引,似乎做了NOT的錯誤轉換,從而防止找到空列表。

這個問題將在即將發佈的版本1.0.6和1.1.1中解決。

+0

這不提供問題的答案。一旦你有足夠的聲譽,你將能夠評論任何帖子;而是提供不需要提問者澄清的答案。 –