so `count` queries are quite expensive in D1
so
count queries are quite expensive in D1count1. Rows read measure how many rows a query reads (scans), regardless of the size of each row. For example, if you have a table with 5000 rows and run a SELECT * FROM table as a full table scan, this would count as 5,000 rows read. A query that filters on an unindexed column may return fewer rows to your Worker, but is still required to read (scan) more rows to determine which subset to return.
offset, limit (so no cursors).totalCount10 this will result in 10 rows being queried.id field and that table also has various other index like on name.rows_read is always similar to the count result.
id column is a PKPRAGMA index_list('driver'); gives me all the indexes (inclduing the unique PK index):
select count(country_of_birth_country_id) from driver where country_of_birth_country_id = 'united-kingdom'country_of_birth_country_id is an indexed column and I use in the count and in the where) but it gives:174 but still 175 rows read.offsetlimittotalCount{
"result": [
{
"results": [
{
"count(*)": 900
}
],
"success": true,
"meta": {
"served_by": "v3-prod",
"duration": 0.2931,
"changes": 0,
"last_row_id": 0,
"changed_db": false,
"size_after": 12607488,
"rows_read": 900,
"rows_written": 0
}
}
],
"success": true,
"errors": [],
"messages": []
}{
"result": [
{
"results": [
{
"count(1)": 900
}
],
"success": true,
"meta": {
"served_by": "v3-prod",
"duration": 0.2308,
"changes": 0,
"last_row_id": 0,
"changed_db": false,
"size_after": 12607488,
"rows_read": 900,
"rows_written": 0
}
}
],
"success": true,
"errors": [],
"messages": []
}{
"result": [
{
"results": [
{
"count(id)": 900
}
],
"success": true,
"meta": {
"served_by": "v3-prod",
"duration": 0.4641,
"changes": 0,
"last_row_id": 0,
"changed_db": false,
"size_after": 12607488,
"rows_read": 900,
"rows_written": 0
}
}
],
"success": true,
"errors": [],
"messages": []
}{
"result": [
{
"results": [
{
"count(name)": 900
}
],
"success": true,
"meta": {
"served_by": "v3-prod",
"duration": 0.4976,
"changes": 0,
"last_row_id": 0,
"changed_db": false,
"size_after": 12607488,
"rows_read": 900,
"rows_written": 0
}
}
],
"success": true,
"errors": [],
"messages": []
}rows_readPRAGMA index_list('driver');select count(country_of_birth_country_id) from driver where country_of_birth_country_id = 'united-kingdom'country_of_birth_country_id{
"result": [
{
"results": [
{
"count(country_of_birth_country_id)": 174
}
],
"success": true,
"meta": {
"served_by": "v3-prod",
"duration": 0.7666,
"changes": 0,
"last_row_id": 0,
"changed_db": false,
"size_after": 12607488,
"rows_read": 175,
"rows_written": 0
}
}
],
"success": true,
"errors": [],
"messages": []
}174175