Full scan for simple count(*) query?

For Workes & Pages, what is the name of the domain?


What is the issue or error you’re encountering

D1 select count(*) returns “rows_read” equal to total rows count, which is confusing when one have to pay per every million read

What steps have you taken to resolve the issue?

  • primary key field named “key” is presented;
  • select count(key) - shows total rows count in “rows_read” as well;
  • select count(key) … where key IS NOT NULL - shows total rows count in “rows_read” as well;

Screenshot of the error

A select count(*) from table query reads all the rows so it can count them. It does the same if you use the primary key, or another indexed column. I don’t think it’s possible in SQLite to count rows without reading them, because the index doesn’t store the row count.