How can I determine how much storage a D1 query will or did use?

I'm wanting to monitor my query costs, one of which is D1 storage cost. This cost is a function of data size, e.g. inserting 100 bytes costs a function of 100 bytes. After running a query, the returned metadata contains a sizeAfter, but this isn't enough information without knowing the size before. Can the size of a row be estimated just based on its inputs? Something like JSON.stringify(["column 1", "column 2", "column 3"]).length?
4 Replies
quisi.do
quisi.doOP•5mo ago
I don't know if bumping is a thing on Discord, but I still lack the ability to track my D1 spend. 😦
James
James•5mo ago
gotta factor in index storage costs as well when it comes to inserts/updates, look into querying dbstat for byte statistics
quisi.do
quisi.doOP•4mo ago
It seems like I'd need to query it both before and after to determine the difference. Being a "virtual table," does it follow the same expenses as reading from other tables? Turning every query into 3 queries sounds pricey in itself.
James
James•4mo ago
Doesn’t matter how many queries you have querying other queries or using CTEs, it’s all about rows read

Did you find this page helpful?