【问题标题】:filter a table on a cluster key efficiently有效地过滤集群键上的表
【发布时间】:2021-01-28 13:07:28
【问题描述】:

我有一个雪花表,有一个格式为yyyy-mm-dd-hh 的聚类键,我想根据某个日期的所有值对其进行过滤。

我以这些方式编写了 where 子句:

  1. WHERE dt >= current_date() || '-00' AND dt <= current_date() || '-23' - 耗时 0.7 秒
  2. WHERE dt IN (current_date() || '-00',current_date() || '-01',current_date() || '-02',current_date() || '-03',current_date() || '-04',current_date() || '-05',current_date() || '-06',current_date() || '-07',current_date() || '-08',current_date() || '-09',current_date() || '-10',current_date() || '-11',current_date() || '-12',current_date() || '-13',current_date() || '-14',current_date() || '-15',current_date() || '-16',current_date() || '-17',current_date() || '-18',current_date() || '-19',current_date() || '-20',current_date() || '-21',current_date() || '-22',current_date() || '-23') - 与 #1 相同
  3. WHERE dt LIKE current_date() || '%' - 耗时 2.9 秒
  4. WHERE left(dt, 10) = current_date - 耗时 9.2 秒

我设置了ALTER SESSION SET USE_CACHED_RESULT = FALSE 以确保结果缓存未被使用

我的问题是:

  1. 是比 #1 更有效的查询方式吗?
  2. 什么类型的查询可以利用集群?我希望 #3 的性能类似于 #1,所以我正在徘徊编写高效查询的规则是什么

【问题讨论】:

    标签: snowflake-cloud-data-platform


    【解决方案1】:

    @lev 您是否检查了所有这些查询的查询配置文件,查询处理的微分区很可能在 3 &4 中比在 1 &2 中更多。

    【讨论】:

    • 我检查了查询配置文件,确实所有查询都处理了相同数量的分区,但是对于#4,Bytes scanned 的值比其他查询翻了一番
    猜你喜欢
    • 1970-01-01
    • 2021-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    相关资源
    最近更新 更多