optimize the following SQL query for Vertica
"""
ELECT 
 perf.Month, 
 rep.publisher\_department AS 'Biz group', 
 COUNT(CASE 
 WHEN perf.Month = (DATE\_PART('month',perf.min\_date) || '.' || DATE\_PART('year',perf.min\_date)) 
 OR (perf.min\_date IS NULL AND perf.Month = (DATE\_PART('month',p.date\_created) || '.' || DATE\_PART('year',p.date\_created))) 
 THEN 1
 ELSE 0
 END) AS 'Num. of New Pubs.',
 -- p.description AS Publisher, 
 -- date(p.date\_created) AS 'Create Date', 
 -- IFNULL(datediff(day, DATE(p.date\_created), min\_date),NULL) AS 'Days to Launch', 
 -- rep.pub\_sales\_rep AS 'Pub Sales Rep.',
 -- rep.pub\_am AS 'Pub AM',
 taboola\_functions.format\_currency(SUM(perf.total\_revenue)) AS 'Gross MTD'
 -- taboola\_functions.format\_currency(total\_revenue / active\_days) AS 'Daily Average',
 -- taboola\_functions.format\_currency(run\_rate) AS 'Monthly rate',
 -- p.currency AS 'Currency',
 -- taboola\_functions.format\_percent(1-perf.publisher\_revenue/perf.total\_revenue) AS Margin,

FROM apps\_config.publishers\_reps\_and\_departments AS rep
INNER JOIN trc.publishers p on p.id = rep.publisher\_id
INNER JOIN analysts.publishers\_in\_networks\_all\_admins AS net ON net.publisher\_id = p.id
LEFT JOIN (SELECT 
 (DATE\_PART('month',f.data\_timestamp) || '.' || DATE\_PART('year',f.data\_timestamp)) AS 'Month',
 publisher\_id, 
 MIN(MIN(f.data\_timestamp)) OVER (PARTITION BY publisher\_id) AS min\_date, 
 MAX(MAX(f.data\_timestamp)) OVER (PARTITION BY publisher\_id) AS max\_date, 
/\* SUM(CASE
 WHEN f.data\_timestamp BETWEEN '\$start\_date' AND '\$end\_date' THEN views\_with\_ad
 ELSE 0
 END) AS views\_with\_ad, 
 SUM(CASE
 WHEN f.data\_timestamp BETWEEN '\$start\_date' AND '\$end\_date' THEN publisher\_revenue\*cc.rate
 ELSE 0
 END) AS publisher\_revenue, \*/ 
 SUM(total\_revenue\*cc.rate) AS total\_revenue, 
 COUNT(f.data\_timestamp) AS active\_days
/\* SUM(CASE
 WHEN f.data\_timestamp BETWEEN '\$start\_date' AND '\$end\_date' THEN total\_revenue\*cc.rate
 ELSE 0
 END)/(NULLIF( SUM(CASE
 WHEN f.data\_timestamp BETWEEN '\$start\_date' AND '\$end\_date' THEN 1
 ELSE 0
 END), 0 )) AS daily\_average,\*/
/\* SUM(CASE
 WHEN f.data\_timestamp BETWEEN '\$start\_date' AND '\$end\_date' THEN total\_revenue\*cc.rate
 ELSE 0
 END) / (NULLIF( sum(CASE
 WHEN f.data\_timestamp BETWEEN '\$start\_date' AND '\$end\_date' THEN 1
 ELSE 0
 END), 0 )) \* 30 AS run\_rate,\*/
/\* CASE
 WHEN day(max(f.data\_timestamp)) = day(SYSDATE - INTERVAL '1 day') THEN 1
 ELSE 0
 END AS active\*/
 FROM reports.publishers\_vendors\_revenue\_report\_daily\_v5 AS f
 LEFT JOIN trc.publishers AS p on p.id = f.publisher\_id
 LEFT JOIN common.currency\_conversion AS cc ON DATE(cc.currency\_date) = DATE(f.data\_timestamp) 
 AND cc.to\_currency='USD' AND cc.from\_currency = p.currency
 WHERE f.data\_timestamp BETWEEN SYSDATE - INTERVAL '2 YEAR' and date(SYSDATE-INTERVAL '1 day')
 AND total\_revenue > 0
 GROUP BY 1,2 ) AS perf 
 ON rep.publisher\_id = perf.publisher\_id

WHERE /\*( 
 (DATE\_PART('month',f.data\_timestamp) = DATE\_PART('month',perf.min\_date) AND DATE\_PART('year',f.data\_timestamp) = DATE\_PART('year',perf.min\_date)) 
 OR (perf.min\_date IS NULL AND (DATE\_PART('month',f.data\_timestamp) = DATE\_PART('month',p.date\_created) AND DATE\_PART('year',f.data\_timestamp) = DATE\_PART('year',p.date\_created)) ) 
 )
 AND\*/ (p.has\_sv=1 OR p.description NOT LIKE '% - SC%')
 -- AND rep.pub\_sales\_rep IS NOT NULL
 -- AND (rep.publisher\_department IN ('\$biz') OR '\$biz'='-100'
 -- OR('\$biz'='Unknown' AND rep.publisher\_department IS NULL))
 -- AND(rep.pub\_am='\$am' OR'\$am'='-100')
 -- AND(rep.pub\_sales\_rep='\$sales' OR '\$sales'='-100') 
/\* AND (CASE
 WHEN perf.max\_date = date(now()-1) then 'Active'
 WHEN perf.max\_date is null then 'Was Not Launched'
 ELSE 'Churned'
 END IS NOT 'Churned') \*/
GROUP BY 1,2
ORDER BY "Month","Num. of New Pubs." DESC, ZEROIFNULL(SUM(perf.total\_revenue)) DESC
;
"""
Vertica에 대해 다음 SQL 쿼리를 최적화합니다."""ELECT  perf.Month,  rep.publisher\_department AS 'Biz group',  COUNT(CASE  WHEN perf.Month = (DATE\_PART('month',perf.min\_date) || '.' || DATE\_PART('year',perf.min\_date))  또는 (perf.min\_date가 NULL이고 perf.Month = (DATE\_PART('month',p.date\_created) || '.')) || DATE\_PART('year',p.date\_created)))))  THEN 1 ELSE 0 END) AS '새 게시물의 수.', -- p.description AS Publisher,  -- date(p.date\_created) AS '생성 날짜',  -- IFNULL(datediff(day, DATE(p.date\_created), min\_date),NULL) AS '출시 일수',  -- rep.pub\_sales\_rep AS 'Pub 영업 담당자', -- rep.pub\_am AS 'Pub AM', taboola\_functions.format\_currency(SUM(perf.total\_revenue)) AS '총 MTD' -- taboola\_functions.format\_currency(total\_revenue / active\_days) AS 'Daily Average', -- taboola\_functions.format\_currency(run\_rate) AS '월별 요율',, -- p.currency AS '통화', -- taboola\_functions.format\_percent(1-perf.publisher\_revenue/perf.total\_revenue) AS Margin,FROM apps\_config.publishers\_reps\_and\_departments AS repINNER JOIN trc.publishers p on p.id = rep.publisher\_idINNER JOIN analysts.publishers\_in\_networks\_all\_admins AS net ON net.publisher\_id = p.id좌측 조인 (선택  (DATE\_PART('month',f.data\_timestamp) || '.' || DATE\_PART('year',f.data\_timestamp)) AS '월', PUBLISHER\_ID,  MIN(MIN(f.data\_timestamp)) OVER (PARTITION BY publisher\_id) AS min\_date,  MAX(MAX(f.data\_timestamp)) OVER (PARTITION BY publisher\_id) AS max\_date, /\* SUM(CASE WHEN f.data\_timestamp가 '\$start\_date' AND '\$end\_date' 사이일 때 조회 수\_with\_ad ELSE 0 END) AS views\_with\_ad,  SUM(CASE WHEN f.data\_timestamp가 '\$start\_date' AND '\$end\_date' 사이이면 publisher\_revenue\*cc.rate ELSE 0 END) AS publisher\_revenue, \*//  SUM(total\_revenue\*cc.rate) AS total\_revenue,  COUNT(f.data\_timestamp) AS active\_days/\* SUM(CASE WHEN f.data\_timestamp가 '\$start\_date' AND '\$end\_date' 사이이면 total\_revenue\*cc.rate ELSE 0 END)/(NULLIF( SUM(CASE WHEN f.data\_timestamp '\$start\_date' AND '\$end\_date' THEN 1 ELSE 0 END), 0 )) AS daily\_average,\*//\* SUM(CASE WHEN f.data\_timestamp가 '\$start\_date' AND '\$end\_date' 사이이면 total\_revenue\*cc.rate ELSE 0 END) / (NULLIF( sum(CASE WHEN f.data\_timestamp '\$start\_date' AND '\$end\_date' THEN 1 ELSE 0 END), 0 )) \* 30 AS run\_rate,\*//\* CASE WHEN day(max(f.data\_timestamp)) = day(SYSDATE - INTERVAL '1 day') THEN 1 ELSE 0 END AS active\*/ FROM reports.publishers\_vendors\_revenue\_report\_daily\_v5 AS f LEFT JOIN trc.publishers AS p on p.id = f.publisher\_id LEFT JOIN common.currency\_conversion AS cc ON DATE(cc.currency\_date) = DATE(f.data\_timestamp)  AND cc.to\_currency='USD' AND cc.from\_currency = p.currency WHERE f.data\_timestamp가 SYSDATE - INTERVAL '2 YEAR'와 date(SYSDATE-INTERVAL '1 day') 사이인 경우 AND total\_revenue > 0 GROUP BY 1,2 ) AS perf  ON rep.publisher\_id = perf.publisher\_idWHERE /\*(  (DATE\_PART('월',f.data\_timestamp) = DATE\_PART('월',perf.min\_date) AND DATE\_PART('연도',f.data\_timestamp) = DATE\_PART('연도',perf.min\_date))  OR (perf.min\_date IS NULL AND (DATE\_PART('month',f.data\_timestamp) = DATE\_PART('month',p.date\_created) AND DATE\_PART('year',f.data\_timestamp) = DATE\_PART('year',p.date\_created)) )  ) AND\*/ (p.has\_sv=1 OR p.description NOT LIKE '% - SC%') -- AND rep.pub\_sales\_rep IS NOT NULL -- AND (rep.publisher\_department IN ('\$biz') OR '\$biz'='-100' -- OR('\$biz'='Unknown' AND rep.publisher\_department IS NULL)) -- AND(rep.pub\_am='\$am' OR'\$am'='-100') -- AND(rep.pub\_sales\_rep='\$sales' OR '\$sales'='-100') /\* AND (CASE WHEN perf.max\_date = date(now()-1) then 'Active' WHEN perf.max\_date가 null이면 '시작되지 않음' ELSE 'Churned' END IS NOT 'Churned') \*/GROUP BY 1,2ORDER BY "Month","Num. of New Pubs." DESC, ZEROIFNULL(SUM(perf.total\_revenue)) DESC;"""