liveBook · Manning

Count

As explained in ScyllaDB in Action

A COUNT function is a database aggregate function that returns the number of rows matching a query.

COUNT is a database aggregate function that returns how many rows match a SELECT query’s WHERE clause instead of returning the rows themselves. section 7.1.5

Use COUNT with the same querying rules as other ScyllaDB queries:

  • Count rows in a specified partition with COUNT(*), such as the five article summaries in date bucket 0. section 7.1.5
  • Include at least the partition key in the query and do not filter by non-primary-key values. section 7.1.5
  • Avoid counting an entire table when possible: ScyllaDB must inspect every partition, so the operation becomes more expensive as records increase. section 7.1.5

Count published article summaries

Run SELECT COUNT(*) FROM article_summaries_by_date WHERE date_bucket = 0; ScyllaDB returns one result containing count = 5. section 7.1.5

cqlsh:reviews> SELECT COUNT(*)
    FROM article_summaries_by_date
    WHERE date_bucket = 0;

View the complete cqlsh query for counting rows in a date partition. section 7.1.5

How ScyllaDB in Action covers it

How deep it goes
Defines aggregate counting, demonstrates partition-level queries, and warns against expensive full-table counts.
Examples
Uses article summaries in a date bucket and an authors table to demonstrate returned counts.
What it assumes
Assumes familiarity with SELECT queries, WHERE clauses, tables, and partition keys.
What you can do after
Apply it via CQL to count rows in a specified ScyllaDB partition.
How it connects
Connects COUNT with SELECT statements, WHERE clauses, partition keys, primary keys, and aggregate functions.

Also explained in

Compare how 5 books explain count →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ScyllaDB in Action. The section links point to the parts of the book it draws on.