<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Script working very slow using GROUP BY in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Script-working-very-slow-using-GROUP-BY/m-p/157546#M32979</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the future when posting code, try either cutting and pasting to notepad first, and then to the forum from notepad. Or go into settings -&amp;gt; user preferences -&amp;gt; editor, and remove the checkmark next to "Copy as RTF".&lt;/P&gt;&lt;P&gt;On to the question itself.&lt;/P&gt;&lt;P&gt;First, when loading from a QVD, it is best if you can do an optimized load. Things like date(floor(occurrence_date)) and hour(occurrence_date)should already have been done when creating the QVD itself.&lt;/P&gt;&lt;P&gt;As for day, week, month and year, I'd create a separate calendar table for those. There's no reason to redo that sort of logic for every single row in your table, even during QVD creation.&lt;/P&gt;&lt;P&gt;If I'm interpreting your event_params load correctly, you're both creating a separate row for each parameter AND a separate field for each parameter. Shouldn't you have one or the other? And why, at least if you have separate rows, would you left join onto the sessions table, since that will duplicate every row of the sessions table for every parameter you have. I'd just keep the table separate and/or remove the param_name in favor of specific fields for the parameters.&lt;/P&gt;&lt;P&gt;Down in the group by, if you had separate fields for the parameters of interest, and only one row for each ID instead of multiple, the group by would run more quickly.&lt;/P&gt;&lt;P&gt;But I'm probably totally misunderstanding everything. It's kind of hard to read.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 11 Mar 2011 23:02:00 GMT</pubDate>
    <dc:creator>johnw</dc:creator>
    <dc:date>2011-03-11T23:02:00Z</dc:date>
    <item>
      <title>Script working very slow using GROUP BY</title>
      <link>https://community.qlik.com/t5/QlikView/Script-working-very-slow-using-GROUP-BY/m-p/157544#M32977</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm using the GROUP BY statment to load and aggregate 300M recs and it takes huge amount of time to load the data.&lt;/P&gt;&lt;P&gt;Will appreciate your advice on how to reduce the load time.&lt;/P&gt;&lt;P&gt;the script is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sessions:&lt;/P&gt;&lt;B&gt;&lt;/B&gt;&lt;P style="font-weight: bold"&gt;load&lt;/P&gt;&lt;B&gt;&lt;/B&gt;&lt;P style="font-weight: bold"&gt;&lt;/P&gt;&lt;B&gt;&lt;/B&gt;&lt;P style="font-weight: bold"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;id&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;,&lt;/P&gt;&lt;P&gt;"occurrence_date"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;,&lt;/P&gt;&lt;P&gt;date&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(floor(occurrence_date)) as Date,&lt;/P&gt;&lt;P&gt;day&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(floor(occurrence_date)) as e_day,&lt;/P&gt;&lt;P&gt;year&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(floor(occurrence_date)) as e_year,&lt;/P&gt;&lt;P&gt;month&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(floor(occurrence_date)) as e_month,&lt;/P&gt;&lt;P&gt;week&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(floor(occurrence_date)) as e_week,&lt;/P&gt;&lt;P&gt;hour&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(occurrence_date) as e_hour,&lt;/P&gt;&lt;P&gt;"session_id"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;,&lt;/P&gt;&lt;P&gt;"user_id"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FROM sessions.qvd(qvd);&lt;/P&gt;&lt;P&gt;left&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;join&lt;B&gt;&lt;/B&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;load&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"event_id"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;as id,&lt;/P&gt;&lt;P&gt;"param_name"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;,&lt;/P&gt;&lt;P&gt;"param_value"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;,&lt;/P&gt;&lt;P&gt;if&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(param_name='merchantName',param_value) as merchantName,&lt;/P&gt;&lt;P&gt;if&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(param_name='dlsource',param_value) as dlsource_for_the_session,&lt;/P&gt;&lt;P&gt;if&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(param_name='CD_CTID' ,param_value) as dl_Sub_source_for_the_session,&lt;/P&gt;&lt;P&gt;if&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(param_name='category_id',param_value) as Category_ID,&lt;/P&gt;&lt;P&gt;if&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(param_name='source_id',param_value) as Source_ID&lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;event_params.qvd(qvd);&lt;/P&gt;&lt;P&gt;aggr:&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;B&gt;&lt;/B&gt;&lt;P style="font-weight: bold"&gt;load&lt;/P&gt;&lt;P&gt;session_id&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;,&lt;/P&gt;&lt;P&gt;count&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(distinct if (param_name&amp;lt;&amp;gt;'slideUp' and action='initial search', id)) as Total_searches,&lt;/P&gt;&lt;P&gt;count&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(distinct if (action='merchant click',id)) as Total_merchant_click,&lt;/P&gt;&lt;P&gt;count&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(if (action='initial search' and param_name='before' and param_value&amp;lt;&amp;gt;'2',user_id)) as Total_users_initiated_and_slideup,&lt;/P&gt;&lt;P&gt;count&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(if (action='initial search' and param_name='slideUp' and param_value='0',param_name)) as System_searches_no_slideUps,&lt;/P&gt;&lt;P&gt;count&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(if (action='initial search' and param_name='slideUp' and param_value='1',param_name)) as Slideup_searchs&lt;/P&gt;&lt;P&gt;Resident&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sessions group by session_id;&lt;/P&gt;action,&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2011 22:44:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-working-very-slow-using-GROUP-BY/m-p/157544#M32977</guid>
      <dc:creator>david_ze</dc:creator>
      <dc:date>2011-03-11T22:44:19Z</dc:date>
    </item>
    <item>
      <title>Script working very slow using GROUP BY</title>
      <link>https://community.qlik.com/t5/QlikView/Script-working-very-slow-using-GROUP-BY/m-p/157545#M32978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;David,&lt;/P&gt;&lt;P&gt;well, GROUP BY and LEFT JOIN are both pretty heavy operations, especially when applied to some 300M rows - that's a very large database. No matter what, it's going to take time. Here are some of the techniques you might consider:&lt;/P&gt;&lt;P&gt;1. THink of implementing incremental load, to reduce the number of rows that need ot be processed every night.&lt;/P&gt;&lt;P&gt;2. You have many IF() formulas, and those are extremely slow. Typically we neglect the impact of IF() on the load script, but with 300M rows you can't afford it. Consider replacing your IF() formulas with multiple loads using WHERE. For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;LOAD&lt;BR /&gt; &lt;STRONG&gt;&lt;/STRONG&gt;session_id, count (distinct if (param_name&amp;lt;&amp;gt;'slideUp' and action='initial search', id)) as Total_searches,&lt;BR /&gt;&lt;BR /&gt; &lt;STRONG&gt;&lt;/STRONG&gt;count (distinct if (param_name&amp;lt;&amp;gt;'slideUp' and action='initial search', id)) as Total_searches,&lt;BR /&gt;&lt;BR /&gt; ...&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;will be much slower than the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I realize that you might have to run several separate loads like this, but my feeling that it will be faster this way than evaluating multiple IF conditions over 300M rows, each row by row.&lt;/P&gt;&lt;P&gt;I believe that your load will go much faster if you can get rid of your IF() conditions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;LOAD&lt;BR /&gt; &lt;STRONG&gt;&lt;/STRONG&gt;session_id,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;RESIDENT ...&lt;BR /&gt;WHERE param_name&amp;lt;&amp;gt;'slideUp' and action='initial search'&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; count (distinct id) as Total_searches&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2011 23:00:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-working-very-slow-using-GROUP-BY/m-p/157545#M32978</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2011-03-11T23:00:00Z</dc:date>
    </item>
    <item>
      <title>Script working very slow using GROUP BY</title>
      <link>https://community.qlik.com/t5/QlikView/Script-working-very-slow-using-GROUP-BY/m-p/157546#M32979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the future when posting code, try either cutting and pasting to notepad first, and then to the forum from notepad. Or go into settings -&amp;gt; user preferences -&amp;gt; editor, and remove the checkmark next to "Copy as RTF".&lt;/P&gt;&lt;P&gt;On to the question itself.&lt;/P&gt;&lt;P&gt;First, when loading from a QVD, it is best if you can do an optimized load. Things like date(floor(occurrence_date)) and hour(occurrence_date)should already have been done when creating the QVD itself.&lt;/P&gt;&lt;P&gt;As for day, week, month and year, I'd create a separate calendar table for those. There's no reason to redo that sort of logic for every single row in your table, even during QVD creation.&lt;/P&gt;&lt;P&gt;If I'm interpreting your event_params load correctly, you're both creating a separate row for each parameter AND a separate field for each parameter. Shouldn't you have one or the other? And why, at least if you have separate rows, would you left join onto the sessions table, since that will duplicate every row of the sessions table for every parameter you have. I'd just keep the table separate and/or remove the param_name in favor of specific fields for the parameters.&lt;/P&gt;&lt;P&gt;Down in the group by, if you had separate fields for the parameters of interest, and only one row for each ID instead of multiple, the group by would run more quickly.&lt;/P&gt;&lt;P&gt;But I'm probably totally misunderstanding everything. It's kind of hard to read.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2011 23:02:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-working-very-slow-using-GROUP-BY/m-p/157546#M32979</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2011-03-11T23:02:00Z</dc:date>
    </item>
    <item>
      <title>Script working very slow using GROUP BY</title>
      <link>https://community.qlik.com/t5/QlikView/Script-working-very-slow-using-GROUP-BY/m-p/157547#M32980</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;this whole "code" keyword doesn't work with me here, but I hope you can get the point, despite some glitches in presentation...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2011 23:03:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-working-very-slow-using-GROUP-BY/m-p/157547#M32980</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2011-03-11T23:03:22Z</dc:date>
    </item>
  </channel>
</rss>

