sqlite storage: Working recursive CTE for excess data

This commit is contained in:
Matt Joiner 2020-10-23 11:03:42 +11:00
parent 1fc63bdded
commit 7fa8c604ab
1 changed files with 11 additions and 0 deletions

11
storage/sqlite/sql Normal file
View File

@ -0,0 +1,11 @@
with recursive excess(
usage_with,
last_used,
blob_rowid,
data_length
) as (
select * from (select (select sum(length(data)) from blob), last_used, rowid, length(data) from blob order by last_used, rowid limit 1)
union all
select usage_with-data_length, blob.last_used, blob.rowid, length(data) from excess join blob
on blob.rowid=(select rowid from blob where (last_used, rowid) > (excess.last_used, blob_rowid))
) select * from excess limit 10;