azure - Take vs. Limit vs. Top、Sort vs. Order By

标签 azure azure-data-explorer kql

长期使用传统SQL,习惯了order bylimittop是MS自带的“limit”但更直观。

这里两个 Kusto 查询共享相同的条件和顺序(排序,对吧?),唯一的区别是返回多少,20 与 200。结果令人惊讶:

AzureDiagnostics | where Category contains "postgresql" | take 20  | order by TimeGenerated desc

enter image description here

AzureDiagnostics | where Category contains "postgresql" | take 200  | order by TimeGenerated desc

enter image description here

顶部更加一致

AzureDiagnostics | where Category contains "postgresql" | top 2  by TimeGenerated desc 
AzureDiagnostics | where Category contains "postgresql" | top 20  by TimeGenerated desc 

更新,感谢@Yoni L,总结如下:

  1. 每个 | 部分的顺序很重要。例如,|take 10 | order by x 将在 take 之后排序,这是随机的。
  2. 采取 = 使用限制
  3. 排序依据 = 排序依据
  4. 按 x [asc/desc] 排序的前 10 名 = 按 x [asc/desc] 排序 |取 10,但 top X by Y 使用的内存要少得多,应该是首选。

最佳答案

top不同,对于takelimit(它们是别名),不保证返回哪些记录,除非源数据是已排序。

以下内容是等效的 - top 20 by x descorder by x desc | take 20,但这有不同的语义:take 20 | order by x desc - 它仅对 taken

的(最多)20 条记录进行排序

关于azure - Take vs. Limit vs. Top、Sort vs. Order By,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71253759/

相关文章:

linux - 禁用 SELINUX 选项后无法从 teraterm 连接 Azure Linux VM

azure - EventGrid 与 EventHub

caching - Azure 缓存 - 升级到 SDK 2.1 和缓存 2.1 后失败

azure - Kusto 查询语言 - 如何准确获取前一天的日志 7

java - 由于 SSL 问题,无法使用 JDBC 连接到 Azure(基于连接字符串和提供的示例)

azure-data-explorer - Azure 数据资源管理器 (Kusto) 覆盖创建时间

azure - 来自事件中心的数据未填充到 ADX 数据库中

Azure 数据资源管理器 - 使用 MI 连续数据导出

azure - 在 Kusto - Azure 数据资源管理器中生成唯一字符串

azure-data-explorer - Kusto 查询语言 : Sum a column