string - How can I make my Athena SQL query faster
问题描述
I am running this on AWS Athena based on PrestoDB. My original plan was to query data 3 months in the past to analyze that data. However, even the query times for 2 hours in the past takes more than 30 minutes, at which point the Query times out. Is there any more efficient way for the query to be carried out?
SELECT column1, dt, column 2
FROM database1
WHERE date_parse(dt, '%Y%m%d%H%i%s') > CAST(now() - interval '1' hour AS timestamp)
The date column is recorded in the form of a string YYYYmmddhhmmss
解决方案
Likely, the problem is that the query applies a function on the column being filtered. This is inefficient, becase the database needs to convert the entire column before it is able to filter it. One says that this predicate is non-SARGable.
Your primary effort should go into fixing your data model and store dates as date
s rather than strings.
That said, the string format that you are using to represent dates still makes it possible to use direct filtering. The idea is to convert the filter value to the target string format (rather than converting the column value to a date):
where dt > date_format(now() - interval '1' hour, '%Y%m%d%H%i%s')
推荐阅读
- c# - C# 不会运行 PowerShell 脚本
- c# - 为什么我的 Web API 没有响应我的请求?
- python - 在python中检查一个字符串是否至少包含五个字符
- java - 如何将 JPA 查询结果映射到 POJO?
- php - 将内联 CSS 添加到 woocommerce 产品列表
- asp.net-mvc - 修改 web.config 文件
- selenium - 硒网格。在各种浏览器中并行执行
- git - 如果包含的项目不在主分支上,则递归推送子模块会抛出“致命:src refspec 必须命名一个 ref”
- php - 身份验证失败后用 PHP 更改 div 类?
- mysql - 我无法让 mysql 和 phpmyadmin 与 Laradock 一起使用,我在这里推荐了所有选项