<?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>Question Re: Sql COUNT Performance Question in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/sql-count-performance-question/qaa-p/13814232#M4845075</link>
    <description>&lt;P&gt;My vote: &lt;STRONG&gt;no diff&lt;/STRONG&gt;!&lt;BR /&gt;
In old database servers, count(Id) or count(1) was faster than count(*).&lt;/P&gt;</description>
    <pubDate>Tue, 17 Nov 2009 12:00:05 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-11-17T12:00:05Z</dc:date>
    <item>
      <title>Sql COUNT Performance Question</title>
      <link>https://community.sap.com/t5/technology-q-a/sql-count-performance-question/qaq-p/13814231</link>
      <description>&lt;P&gt;Structure of Example table:&lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;Id, Integer (PK)
Name, Varchar(100)
Description, Text
&lt;/LI-CODE&gt;

&lt;P&gt;I need to know if exists difference in performance between:&lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;SELECT COUNT(*) FROM Example;
&lt;/LI-CODE&gt;

&lt;P&gt;and&lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;SELECT COUNT(Id) FROM Example;
&lt;/LI-CODE&gt;

&lt;P&gt;Or does not exists differences?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2009 11:37:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sql-count-performance-question/qaq-p/13814231</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-17T11:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sql COUNT Performance Question</title>
      <link>https://community.sap.com/t5/technology-q-a/sql-count-performance-question/qaa-p/13814232#M4845075</link>
      <description>&lt;P&gt;My vote: &lt;STRONG&gt;no diff&lt;/STRONG&gt;!&lt;BR /&gt;
In old database servers, count(Id) or count(1) was faster than count(*).&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2009 12:00:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sql-count-performance-question/qaa-p/13814232#M4845075</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-17T12:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sql COUNT Performance Question</title>
      <link>https://community.sap.com/t5/technology-q-a/sql-count-performance-question/qaa-p/13814233#M4845076</link>
      <description>&lt;P&gt;In version 10.0 and above, &lt;CODE&gt;COUNT( x )&lt;/CODE&gt; is translated to &lt;CODE&gt;COUNT(*)&lt;/CODE&gt; if x is an expression that is known to not allow NULL. In your example, I think you have Id as a primary key (non-NULL), and therefore &lt;CODE&gt;COUNT(Id)&lt;/CODE&gt; is treated identically to COUNT(*) unless your Example table appears on the NULL-supplying side of an outer join.&lt;/P&gt;

&lt;P&gt;For expressions &lt;CODE&gt;Y&lt;/CODE&gt; that might be &lt;CODE&gt;NULL&lt;/CODE&gt;, there are at least three ways that &lt;CODE&gt;COUNT(Y)&lt;/CODE&gt; may be slower than &lt;CODE&gt;COUNT(*)&lt;/CODE&gt;:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;The expression &lt;CODE&gt;Y&lt;/CODE&gt; needs to be computed. This means it must be fetched from the table if it is a column; if it is a more complex expression, it needs to be evaluated to determine if it is NULL. If the &lt;CODE&gt;COUNT(Y)&lt;/CODE&gt; appears above a work table, the server may need to materialize Y in the work table so that it would be available at the group-by node.&lt;/LI&gt;
&lt;LI&gt;The server can not combine &lt;CODE&gt;COUNT(Y1)&lt;/CODE&gt; and &lt;CODE&gt;COUNT(Y2)&lt;/CODE&gt; for different expressions, and materialized views can not be used unless they have an appropriate &lt;CODE&gt;COUNT(Y)&lt;/CODE&gt; that matches the query.&lt;/LI&gt;
&lt;LI&gt;The server can not perform semantic transformations that eliminate a table needed to compute &lt;CODE&gt;Y&lt;/CODE&gt;. This also means that index-only retrieval is not possible if Y can not be recovered from the index.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I do not know of any reason why &lt;CODE&gt;COUNT(Y)&lt;/CODE&gt; might be &lt;EM&gt;faster&lt;/EM&gt; than &lt;CODE&gt;COUNT(*)&lt;/CODE&gt;. So, use &lt;CODE&gt;COUNT(*)&lt;/CODE&gt; if you want to count rows, and &lt;CODE&gt;COUNT(Y)&lt;/CODE&gt; if you really need to distinguish how many rows had a NULL value for Y.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2010 21:18:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sql-count-performance-question/qaa-p/13814233#M4845076</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-10T21:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Sql COUNT Performance Question</title>
      <link>https://community.sap.com/t5/technology-q-a/sql-count-performance-question/qaa-p/13814234#M4845077</link>
      <description>&lt;P&gt;If the exact value is not important, but you just want to get an idea if 1000 or 1Mio entries exists you can use the super fast access to the column count of systab. This value is updated during each successful checkpoint.&lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;select count from systab where table_name = 'Example'
&lt;/LI-CODE&gt;

&lt;P&gt;Use case is for instance: The application wants to display total count of customers in the database in its status bar, updated every 5min...&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2010 12:27:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sql-count-performance-question/qaa-p/13814234#M4845077</guid>
      <dc:creator>MCMartin</dc:creator>
      <dc:date>2010-03-11T12:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sql COUNT Performance Question</title>
      <link>https://community.sap.com/t5/technology-q-a/sql-count-performance-question/qaa-p/13814235#M4845078</link>
      <description>&lt;P&gt;@Breck: I wanted to correct "tabel_name", too, but seems unable to. Why don't I have an "edit" button for other people's post - am I still missing reputation in these times of boot-strapping?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2010 13:57:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sql-count-performance-question/qaa-p/13814235#M4845078</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2010-03-11T13:57:09Z</dc:date>
    </item>
  </channel>
</rss>

