On Thu, Mar 11, 2010 at 7:17 PM, João Eiras <[email protected]> wrote:
> On Fri, 12 Mar 2010 04:07:21 +0100, Dumitru Daniliuc <[email protected]> > wrote: > > joao, >> >> if i understand correctly, you basically want to have an automated system >> implemented in the browser that decides when to vacuum databases (or at >> least make sure it doesn't happen too often). and the vacuum() calls would >> be just one of the parameters that the system takes into account. i think >> having such a system is fine, but doesn't need to be spec'ed. at the same >> time, i think it's worth having a spec'ed vacuum() call that gives the app >> some guarantees. in particular, i would like the completionCallback to be >> a >> signal that the database is in a good shape and ready for more work. so >> how >> about this: >> >> >> 1. if the UA doesn't support the vacuum() call, go to step 3. >> 2. queue up a task to vacuum the database. if the UA decides that >> >> vacuuming is not needed at this time, the vacuuming task scheduled in >> this >> step could be a no-op. >> 3. when the vacuuming task completes, queue up a task to invoke the >> >> completion callback, if one was specified. >> >> i think this spec should allow you to treat the vacuum() call as a hint, >> while also guaranteeing that: >> 1. the UA believes the database is in a good shape when the completion >> callback is called. >> 2. the completion callback is called as soon as UA believes the DB is in a >> good shape. >> >> what do you think? >> > > Looks better, and more flexible. > thanks. is there anything else you'd like to change? i'm pushing for this so hard because i'd like to implement this feature, but i don't want to start before all interested parties agree on a spec. > I wonder if sqlite has a way to query the number of pages in the freelist ? > Probably something like 10% of pages in the freelist would be a good > threshold to allow a vacuum. > you can get the number of free pages with PRAGMA freelist_count ( http://www.sqlite.org/pragma.html). unfortunately, looking only at this number would result in a lot of false negatives. for example, in theory, you could have a DB with 1000 2KB pages, and each page could have only one useful byte written on it. so PRAGMA freelist_count would return 0, even though doing a vacuuming would shrink your DB from ~2MB to ~1KB. but i agree that it could be one of the parameters to take into account.
