Skip to content
Commit Detail

Commit 4df1161

Author
Justin Mazzola Paluska <jmp@cloudflare.com> 2024-11-15 10:44:39 -0500
Parents
8ba7052
Tree
f7c0549
Remove cached column names from the statement cache

In production, we saw the assertion in
SqlStorage::Cursor::rowIteratorNext fail:

```
failed: expected names.size() == values.size() [9 == 10];
```

The assertion fires when the set of values in returned by the next row
in the statement (`values`) doesn’t match the set of column names when
we first compiled the statement.  This can happen if the tables that
the statement refers to have been altered to have a different number
of columns after the statement was compiled and cached.

Compiled SQLite statements themselves become invalid when the schema
of the tables they reference change.  However, if you use
`sqlite3_prepare_v2` or later (and we do because we use
`sqlite3_prepare_v3`!), SQLite will automatically recompile the
statement against the current schema when SQLite notices the statement
is out of date.

It would be better if we could figure out how to detect recompilation
and fix the column name cache, but doing so looks like a big
change.  Instead, this commit removes the column name cache, which
isn’t a huge deal.

(NOTE: there’s still a bug where if someone changes the schema while
iterating through the results of a query, we could hit the same error.
But… you shouldn’t be doing that.)

Files changed

3 files changed~3 modified