Skip to Content
author's profile photo Former Member
Former Member

count(*) or count(id) ?

Hi folks, just wondering if there is any performance differences in using count(*) or count(id) to get the row count from a column table in HANA? Where "id" say is the primary key in the table.

Some Googling of behavior in other DB engines suggests that they are optimized for using count(*) and this should be faster to get a row count instead of using count(id). Wondering if it is the same with HANA?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Sep 23, 2015 at 11:00 AM

    And it's DB MYTHS TIME again... 🤪

    Even with other DBMS engines this is a mostly wrong claim.

    Most query optimizers nowadays recognize what should be done with a count(*) and optimize accordingly.

    This is where it is important to check for proofs of such claims and the software versions they should be valid for!

    Anyhow, SAP HANA does understand what should be done with a count(*) (count all visible rows) and optimizes for that.

    I highly recommend to use COUNT(*) because

    • it expresses what you want to do
    • HANA can use the visibility vector of a table instead of having to use a data column
    • performance is equal or better than using the primary key column(s)
    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Perfect, thanks for the quick reply!

      I understand the same is also true when getting row counts for Views on HANA- i.e. use count(*) to get the row count rather than specifying a column name.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.