<?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 Re: How to optimize this query? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-to-optimize-this-query/m-p/643131#M11055</link>
    <description>&lt;P&gt;Thanks much.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This search has completed and has returned 5,225 results by scanning 29,868 events in 0.592 seconds. Where the older one's was 1.606 seconds which is great news |||&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2023 05:04:48 GMT</pubDate>
    <dc:creator>spoo</dc:creator>
    <dc:date>2023-05-12T05:04:48Z</dc:date>
    <item>
      <title>How to optimize this query?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-optimize-this-query/m-p/642966#M11052</link>
      <description>&lt;P&gt;index="abcd"&lt;BR /&gt;| eval _time = strptime(TS_Changed_At,"%d/%m/%Y %H:%M")&lt;BR /&gt;| sort 0 ID _time&lt;BR /&gt;| dedup ID _time&lt;BR /&gt;| eventstats last(Status) as current_status by ID&lt;BR /&gt;| where current_status="AAA" OR current_status="BBB" OR current_status="CCC"&lt;BR /&gt;| streamstats current=f window=1 values(Status) as prev_status by ID&lt;BR /&gt;| where NOT Status=prev_status&lt;BR /&gt;| eval Cal= if(Status="CCC" AND (NOT prev_status="AAA " AND NOT prev_status="BBB"),substr(TS_Last_Status_Change,1,16),if(Status="BBB" AND NOT prev_status="AAA",substr(TS_Last_Status_Change,1,16),if(Status="AAA",substr(TS_Last_Status_Change,1,16),"")))&lt;BR /&gt;| where NOT Cal=""&lt;BR /&gt;| eventstats max(eval(strptime(Cal,"%d/%m/%Y %H:%M"))) as max_ by ID&lt;BR /&gt;| where max_ = strptime(Cal,"%d/%m/%Y %H:%M")&lt;BR /&gt;| table ID Cal&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 12:24:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-optimize-this-query/m-p/642966#M11052</guid>
      <dc:creator>spoo</dc:creator>
      <dc:date>2023-05-11T12:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to optimize this query?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-optimize-this-query/m-p/643050#M11054</link>
      <description>&lt;P&gt;What is the goal of the query?&amp;nbsp; There may be a more efficient way to accomplish the same thing.&lt;/P&gt;&lt;P&gt;Here are some general tips:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Make the base search (before the first pipe) as specific as possible to reduce the number of events read from the index.&lt;/LI&gt;&lt;LI&gt;Use the &lt;FONT face="courier new,courier"&gt;fields&lt;/FONT&gt; command early to eliminate unused fields.&lt;/LI&gt;&lt;LI&gt;Sort only when and where necessary.&lt;/LI&gt;&lt;LI&gt;Use non-distributable commands as late in the query as possible.&amp;nbsp; The first non-distributable command makes the entire query single-threaded (so to speak).&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="markup"&gt;index="abcd" ID=* TS_Changed_At=* sourcetype=foo
| fields ID TS_Changed_At Status Cal
| eval _time = strptime(TS_Changed_At,"%d/%m/%Y %H:%M")
| dedup ID _time
| eventstats last(Status) as current_status by ID
| where current_status="AAA" OR current_status="BBB" OR current_status="CCC"
| sort 0 ID _time
| streamstats current=f window=1 values(Status) as prev_status by ID
| where NOT Status=prev_status
| eval Cal= if(Status="CCC" AND (NOT prev_status="AAA " AND NOT prev_status="BBB"),substr(TS_Last_Status_Change,1,16),if(Status="BBB" AND NOT prev_status="AAA",substr(TS_Last_Status_Change,1,16),if(Status="AAA",substr(TS_Last_Status_Change,1,16),"")))
| where NOT Cal=""
| eventstats max(eval(strptime(Cal,"%d/%m/%Y %H:%M"))) as max_ by ID
| where max_ = strptime(Cal,"%d/%m/%Y %H:%M")
| table ID Cal&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 13:41:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-optimize-this-query/m-p/643050#M11054</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-05-11T13:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to optimize this query?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-optimize-this-query/m-p/643131#M11055</link>
      <description>&lt;P&gt;Thanks much.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This search has completed and has returned 5,225 results by scanning 29,868 events in 0.592 seconds. Where the older one's was 1.606 seconds which is great news |||&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 05:04:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-optimize-this-query/m-p/643131#M11055</guid>
      <dc:creator>spoo</dc:creator>
      <dc:date>2023-05-12T05:04:48Z</dc:date>
    </item>
  </channel>
</rss>

