оптимизация постановки кейса в PostgreSQL - PullRequest
0 голосов
/ 29 мая 2018

добавьте еще два набора условий case, чтобы увидеть, поможет ли это оптимизироваться ..

Мне нужно оптимизировать оператор case, поскольку он слишком длинный. У меня 1500 строк с аналогичным оператором case в запросе.,я просто выбрал один набор этого запроса для оптимизации

select 
          case when ((
                    lower (id) like '%hol%' 
                  or lower (campaign_name) like '%hol%' 
                  or lower (marketing_source_code) like '%hol%' 
                  or lower (call_to_action) like '%hol%'
                  or lower(program_type) like '%hol%'
                  or lower (campaign_lvl1_name) like '%hol%'
                  or lower (campaign_lvl2_name) like '%hol%'
                  or lower (campaign_lvl3_name) like '%hol%'
                  or lower (campaign_lvl4_name) like '%hol%'
                )            
         and not (position ('HOLLYWOOD' in upper(campaign_name)) > 0 or 
                  position ('HOLE' in upper(campaign_name)) > 0 or
                  position ('HOLDER' in upper(campaign_name)) > 0 or
                  position ('STOCKHOLM' in upper(campaign_name)) > 0 or
                  position ('HOLIDAY' in upper(campaign_name)) > 0 or
                  position ('CATHOLIC' in upper(campaign_name)) > 0 or
                  position ('HOLISTIC' in upper(campaign_name)) > 0 or
                  position ('HOLY' in upper(campaign_name)) > 0 or
                  position ('HOLTKAMP' in upper(campaign_name)) > 0 or
                  position ('HOLDING' in upper(campaign_name)) > 0 or
                  position ('CUSTHOLRECP' in upper(campaign_name)) > 0 
                 )
         and (  position('VSOM' in upper(campaign_name) ) > 0 
                 or position('VSPHERE WITH OPERATIONS MANAGEMENT' in upper(campaign_name)) > 0
                 or position('VSOM' in upper(products) ) > 0  
                 or position('VSPHERE WITH OPERATIONS MANAGEMENT' in upper(products)) > 0
             )) 
         then 1 else 0 end as vsom_hol_response,
case when (( 
                    lower (campaign_name) like '%seminar%' 
                 or lower (marketing_source_code) like '%seminar%'  
                 or lower (call_to_action) like '%seminar%'
                 or lower (program_type) like '%seminar%'
                 or lower (campaign_lvl1_name) like '%seminar%'
                 or lower (campaign_lvl2_name) like '%seminar%'
                 or lower (campaign_lvl3_name) like '%seminar%'
                 or lower (campaign_lvl4_name) like '%seminar%'
               )                       
         and (      position('VSOM' in upper(campaign_name) ) > 0 
                or  position('VSPHERE WITH OPERATIONS MANAGEMENT' in upper(campaign_name)) > 0
                or position('VSOM' in upper(products) ) > 0  
                or position('VSPHERE WITH OPERATIONS MANAGEMENT' in upper(products)) > 0
             ))
            then 1 else 0 end as vsom_seminar_response,    
   case when ((
                    lower (id) like '%webinar%' 
                 or lower (campaign_name) like '%webinar%' 
                 or lower (marketing_source_code) like '%webinar%' 
                 or lower (call_to_action) like '%webinar%'
                 or lower (program_type) like '%webinar%'
                 or lower (campaign_lvl1_name) like '%webinar%'
                 or lower (campaign_lvl2_name) like '%webinar%'
                 or lower (campaign_lvl3_name) like '%webinar%'
                 or lower (campaign_lvl4_name) like '%webinar%'
                 )                       
            and (      
                   position('VSOM' in upper(campaign_name) ) > 0 
                or position('VSPHERE WITH OPERATIONS MANAGEMENT' in upper(campaign_name)) > 0
                or position('VSOM' in upper(products) ) > 0  
                or position('VSPHERE WITH OPERATIONS MANAGEMENT' in upper(products)) > 0)
                 )
         then 1 else 0 end as vsom_webinar_response

             from base.vdim_campaign 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...