使用GROUP BY进行OrientDB查询

时间:2015-12-18 16:33:10

标签: orientdb

以下查询返回错误的行数:

SELECT keyName.left(keyName.indexOf('_Configuration/')) AS keyValue, 
address.zip AS zip, 
customer_map AS customerMap 
FROM CUSTOMERS
WHERE customer_group = 'xyz' 
GROUP BY keyValue, customerMap, zip

其中列数据类型如下:

keyName String 
address EMBEDDEDMAP 
customer_map EMBEDDEDMAP 

但是,如果更改GROUP BY以使用列名而不是别名,则查询将返回正确的行数:

SELECT keyName.left(keyName.indexOf('_Configuration/')) AS keyValue, 
address.zip AS zip, 
customer_map AS customerMap 
FROM CUSTOMERS 
WHERE customer_group = 'xyz' 
GROUP BY keyValue, customer_map, address.zip

有趣的是,使用keyName.left(...)的别名不会影响GROUP BY,但会影响例如:  ifnull(keyName, 'ABC) AS keyValue 使查询返回错误的行数。

请注意,第一个查询不会给出任何错误/警告,只返回错误的行数。

GROUP BY的预期行为是什么?
不幸的是,OrientDB文档没有太多关于GROUP BY的细节。

1 个答案:

答案 0 :(得分:0)

查询执行流程如下:

  • 查找查询目标(索引优先,然后回退群集迭代器)
  • 迭代目标并根据WHERE条件过滤(不包括已与索引匹配的条件)
  • 计算过滤记录的预测
  • 申请UNWIND和EXPAND
  • 申请分组
  • 申请订购
  • 申请SKIP和LIMIT

您可以使用

select keyValue,zip,customerMap from (SELECT keyName.left(keyName.indexOf('_Configuration/')) AS keyValue, 
address.zip AS zip, 
customer_map AS customerMap 
FROM CUSTOMERS
WHERE customer_group = 'xyz' )
GROUP BY keyValue, customerMap, zip