在不使用not-in的情况下提高性能

0sgqnhkj  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(331)

我想从输出中的action\u name属性中排除一个包含值'pre\u d\u eng\u tb'的行,使用not in会使查询速度变慢(~45秒),是否有其他可能提高性能,而不使用此筛选器查询所需时间少于(~4秒)

select
    date(action_event_time),
    syndicator_id,
    ac.action_name as 'conversion_type',
    count (distinct ac.syndicator_id || '|' ||
                    ac.campaign_id || '|' ||
                    ac.target_item_id || '|' ||
                    ac.source_item_id || '|' ||
                    ac.affiliate_id || '|' ||
                    ac.country|| '|' ||
                    ifnull(ac.platform_id,5) || '|' ||
                    ac.user_id || '|' ||
                    ac.ip_address || '|' ||
                    ifnull(SUBSTRING(ac.action_goal_page_url, 1, 500),'--') || '|' ||
                    ifnull(ac.action_name,'--') || '|' ||
                    ifnull(ac.action_revenue,0) || '|' ||
                    ifnull(ac.action_order_id,'--') || '|' ||
                    ifnull(ac.action_currency,'--') || '|' ||
                    CASE
                        WHEN ac.action_name in ('video_page_view', 'text_page_view', 'photo_page_view', 'homepage_page_view', 'article_page_view','category_page_view', 'page_view', 'home_page_view', 'video_view','pages_per_visit')
                            then ifnull(EXTRACT(EPOCH FROM ac.action_event_time),0)

                        ELSE ifnull(FLOOR(EXTRACT(EPOCH FROM ac.action_event_time)/ 900),0) end) as 'conversions'
from rawdata.action_conversion_v2 ac join trc.publishers sy on sy.id = ac.syndicator_id
where ac.action_name not in ('pre_d_eng_tb')
  and NEW_TIME(ac.click_event_time,'GMT',sy.time_zone_name) >= date('2020-05-01')
  and NEW_TIME(ac.click_event_time,'GMT',sy.time_zone_name) < date('2020-06-15') + interval '1' day
  and syndicator_id = 1223211
group by 1,2,3
order by 1 asc;

查询工作正常,结果格式如下,只是需要较长的时间,我想改进一下

date   syndicator_id   conversion_type conversions
    2020-04-30  1223211 page_view             2
    2020-05-01  1223211 make_purchase         45
    2020-05-01  1223211 page_view             3645
    2020-05-02  1223211 make_purchase         36
    2020-05-02  1223211 page_view             4936
    2020-05-03  1223211 make_purchase         39

t98cgbkg

t98cgbkg1#

从目前的情况来看,可能无法加快查询速度。但是,通过构建和维护一个“摘要表”,您可以使查询的运行速度提高几倍。
每天晚上,汇总一天的流量,并将小计添加到汇总表中。它将被一个日期索引,(从 date(action_event_time) 、联合体id和“转换类型”。
“报告”将汇总小计。
然而,有一个活动扳手 COUNT(DISTINCT...) . 这类资产很难进行“小计”。你真的想找出不同值的数目,不包括pre\u d\u eng\u tb吗?
我假设有一个以 syndicator_id ?
另一个想法。。。

NEW_TIME(ac.click_event_time,'GMT',sy.time_zone_name)

抑制了优化的一个关键因素--在 WHERE 条款。在将单击时间存储到 ac . 那样的话,你就可以 INDEX(syndicator_id, click_time) ,这将加快过滤速度( action_name 仍然是个大麻烦。)
如果需要,为click\u time添加第二列——其中一列是原始时间;另一个是“新时代”。

相关问题