cancel
Showing results for 
Search instead for 
Did you mean: 

count(*) or count(id) ?

Former Member
0 Kudos

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?

Accepted Solutions (1)

Accepted Solutions (1)

lbreddemann
Active Contributor
0 Kudos

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)
Former Member
0 Kudos

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.

Answers (0)