title: Snowflake Query/task gets canceled cause of timelimit
body: <p>I set up a code, to load  Data from Google Analytics from a raw GA table to an adapted table, that offers more insights.
  Somehow the Task is not running inside the defined time limit of 3600 seconds.
  So the task is getting canceled and no data is loaded.</p>
  <pre><code>&quot;Statement reached its statement or warehouse timeout of 3,600 second(s) and was canceled.&quot;
  </code></pre>
  <p>Then I load it in a manual way by using a fixed Clause: <code>WHERE gae.&quot;DAY&quot;='2020-03-31'</code> instead of
  <code>WHERE gae.&quot;DAY&quot;&gt;=CuRRENT_DATE-1</code>. It takes still much time but works in the end.</p>
  <p>How can I make this query faster? Or anyway, solve my problem.</p>
  <pre><code>CREATE OR REPLACE TASK dm.&quot;Website&quot;.&quot;x009_002_all_GA_events&quot;
          WAREHOUSE = marketing_wh
          SCHEDULE = 'USING CRON 26 5 * * * Europe/Berlin'
          AS
      merge into DM.&quot;Website&quot;.ALL_GA_EVENTS_CLEAN target --DM.&quot;Website&quot;.ALL_GA_EVENTS target
      using (
      SELECT
      GAEVENTACTION AS GAEVENTACTION,
      GAEVENTCATEGORY AS GAEVENTCATEGORY,
      &quot;DAY&quot; AS Datum,
      DEVICE_TYPE AS Device,
      EVENT_COUNT AS EventCount,
      GAUNIQUEEVENTS AS Uniqueevents,
      EVENT_VALUE AS eventvalue,
      LABELS AS labelz,
      URL AS urlz,
      --split_part(LABELS,'/_',2) AS &quot;HITSTAMP&quot;,
      CASE WHEN split_part(LABELS,'/_',2) IS NOT NULL THEN TRY_CAST(split_part(LABELS,'/_',2) AS timestamp) ELSE NULL END AS &quot;HITSTAMP&quot;,
      split_part(LABELS,'/_',3) AS EVENT_INFO,
      split_part(LABELS,'/_',1) AS &quot;SESSIONID&quot;,
      CASE
          WHEN CONTAINS (URL, '/checkout/')=TRUE THEN split_part(URL,'/',3)
          WHEN CONTAINS (URL, '/auto/')=TRUE THEN split_part(split_part(URL,'/',3),'?',1)
          WHEN CONTAINS (URL, '/angebote/')=TRUE THEN split_part(URL,'/',3)
          ELSE 'no vehicle'
      END AS vehicleID,
      rank() over (partition BY &quot;SESSIONID&quot; order by &quot;HITSTAMP&quot;) as &quot;RANK&quot;,
      CASE 
          WHEN (GAEVENTACTION= ('pdp_flash_offer_request' )) THEN 
              CASE WHEN split_part(LABELS,'/_',2)=(SELECT min(split_part(t2.LABELS,'/_',2))
                  FROM &quot;DL_Datatap&quot;.&quot;PUBLIC&quot;.&quot;GA_all_events&quot; t2
                  WHERE split_part(t2.LABELS,'/_',1)=split_part(gae.LABELS,'/_',1) AND gae.GAEVENTACTION=t2.GAEVENTACTION)
              THEN TRUE
              ELSE FALSE
              END
          WHEN (GAEVENTACTION= ('chat_started')) THEN 
              CASE WHEN split_part(LABELS,'/_',2)=(SELECT min(split_part(t2.LABELS,'/_',2))
                  FROM &quot;DL_Datatap&quot;.&quot;PUBLIC&quot;.&quot;GA_all_events&quot; t2
                  WHERE split_part(t2.LABELS,'/_',1)=split_part(gae.LABELS,'/_',1) AND gae.GAEVENTACTION=t2.GAEVENTACTION)
              THEN TRUE
              ELSE FALSE  
              END
          WHEN (GAEVENTACTION= ('Direct_checkout_send')) THEN 
              CASE WHEN split_part(LABELS,'/_',2)=(SELECT min(split_part(t2.LABELS,'/_',2))
                  FROM &quot;DL_Datatap&quot;.&quot;PUBLIC&quot;.&quot;GA_all_events&quot; t2
                  WHERE split_part(t2.LABELS,'/_',1)=split_part(gae.LABELS,'/_',1) AND gae.GAEVENTACTION=t2.GAEVENTACTION)
              THEN TRUE
              ELSE FALSE
              END
          WHEN (GAEVENTACTION= ('pdp_offer_request')) THEN 
              CASE WHEN split_part(LABELS,'/_',2)=(SELECT min(split_part(t2.LABELS,'/_',2))
                  FROM &quot;DL_Datatap&quot;.&quot;PUBLIC&quot;.&quot;GA_all_events&quot; t2
                  WHERE split_part(t2.LABELS,'/_',1)=split_part(gae.LABELS,'/_',1) AND gae.GAEVENTACTION=t2.GAEVENTACTION)
              THEN TRUE
              ELSE FALSE
              END
          WHEN (GAEVENTACTION= ('agent-requested')) THEN 
              CASE WHEN split_part(LABELS,'/_',2)=(SELECT min(split_part(t2.LABELS,'/_',2))
                  FROM &quot;DL_Datatap&quot;.&quot;PUBLIC&quot;.&quot;GA_all_events&quot; t2
                  WHERE split_part(t2.LABELS,'/_',1)=split_part(gae.LABELS,'/_',1) AND gae.GAEVENTACTION=t2.GAEVENTACTION)
              THEN TRUE
              ELSE FALSE 
              END
          WHEN (GAEVENTACTION= ('SERP_softlead_send')) THEN 
              CASE WHEN split_part(LABELS,'/_',2)=(SELECT min(split_part(t2.LABELS,'/_',2))
                  FROM &quot;DL_Datatap&quot;.&quot;PUBLIC&quot;.&quot;GA_all_events&quot; t2
                  WHERE split_part(t2.LABELS,'/_',1)=split_part(gae.LABELS,'/_',1) AND gae.GAEVENTACTION=t2.GAEVENTACTION)
              THEN TRUE
              ELSE FALSE
              END
      ELSE False
      END AS &quot;GOAL_EVENT&quot;
      FROM &quot;DL_Datatap&quot;.&quot;PUBLIC&quot;.&quot;GA_all_events&quot; gae
      ---WHERE gae.&quot;DAY&quot;='2020-03-31'
      WHERE gae.&quot;DAY&quot;&gt;=CuRRENT_DATE-1 
      ) SOURCE
      ON target.SESSIONID=SOURCE.&quot;SESSIONID&quot; AND target.HITSTAMP=SOURCE.&quot;HITSTAMP&quot; AND target.EVENT_ACTION=SOURCE.GAEVENTACTION AND target.&quot;Date&quot;=SOURCE.Datum
      when NOT matched then INSERT (EVENT_ACTION, EVENT_CATEGORY, &quot;Date&quot;, DEVICE, TOTAL_EVENTS, UNIQUE_EVENTS, EVENT_VALUE, EVENT_LABEL, URL, HITSTAMP, EVENT_INFO, SESSIONID, VEHICLEID, EVENT_SEQUENCE, GOAL_EVENT)
      VALUES (SOURCE.GAEVENTACTION, SOURCE.GAEVENTCATEGORY, SOURCE.Datum, SOURCE.Device, SOURCE.eventcount, SOURCE.Uniqueevents, SOURCE. eventvalue, SOURCE.labelz, SOURCE.urlz, SOURCE.&quot;HITSTAMP&quot;, SOURCE.EVENT_INFO, SOURCE.&quot;SESSIONID&quot;, SOURCE.vehicleid, SOURCE.&quot;RANK&quot;, SOURCE.&quot;GOAL_EVENT&quot; 
      )
  </code></pre>