3

This question is the same as MySQL - Complexity of: SELECT COUNT(*) FROM MyTable;.

The difference is that instead MySQL i want to know the answer for HDB.

I Googled it, and looked for it in SAP Knowledge Base without finding an answer.

To clarify: The question is regarding selecting count without any additional conditions:

SELECT COUNT( * ) FROM dbtab.

What is the complexity of the above query. Does HDB stores a counter on top of each table?

Dorad
  • 3,413
  • 2
  • 44
  • 71

1 Answers1

2

HANA supports a large variety of table types, e.g. ROW-, COLUMN-, VIRTUAL-, EXTENDED-, and MULTISTORE-tables come to mind here.

For some of those, the current raw record count is kept as part of the internal storage structures and does not need to computed upon query time. This is specifically true for ROW and COLUMN tables.

VIRTUAL tables are on the extreme other end and behave a lot more like complex views when it comes to SELECT count(*). Depending on the DB "behind" the virtual table, the performance of this can vary wildly!

Also, be careful assuming that ROW and COLUMN store tables will return the information with nearly no effort. HANA is a shared-nothing distributed database (in scale-out setups), which means that this kind of information is only known to the node that a table is located on. Finding out the row count of, e.g. a partitioned table with X partitions on Y number of nodes can take a considerable amount of time!

Finally, this raw record count is only available for tables that are currently in memory. Running a SELECT count(*) on a table that is currently unloaded will trigger the load of the columns that are required to answer that query (basically all primary key columns + some internal table management structures).

In the ideal case (a column table, loaded to memory and all partitions on a single node) this query should return instantaneous; but the other mentioned scenarios need to be considered, too.

Hope that answers the rather broad question.

Lars Br.
  • 9,949
  • 2
  • 15
  • 29