首页 > 解决方案 > Redshift - IN 子句中的参数使查询重新编译

问题描述

我有一个带有 IN 子句的过滤器,可以从我的查询中的用户选择中获取 CustomerID。我正在对查询执行进行基准测试,似乎是通过更改编号。redshift 中 IN 子句中的参数数量会导致重新编译查询。IN 子句中的参数更改后运行的后续查询比上一次运行花费更多时间。

select *  -- some aggregations here
from FactCustomer c 
inner join FactSales s on c.CustomerID = s.CustomerId 
inner join DimDate d on d.DateID = s.DateID
inner join DimTime t on t.TimeID = d.timeID
where d.SalesDate between '01-01-2018' and '12-31-2018'
    and c.CustomerID in ( 1,3,7,9, 11, 13, 15, 17, 19, 21, 23, 25, 27 ) 
-- there are over 200 customers and the user can select as much as they want in the filter
-- the customerIDs comes from the user dyamically thru the dashboard
-- if the no. of parameters in customerID change to less or more the subsequent queries take time

我的问题

Redshift 中的替代方法是什么,以便我可以从用户那里获取可在我的查询中使用的 customerIds,而无需使用 IN 子句?

PS 使用临时表不是我的选择。

任何见解表示赞赏。

标签: amazon-redshift

解决方案


推荐阅读