MyBB Community Forums

Full Version: SQLite's `optimize_table()`
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
It looks like SQLite's optimization works on the database (schema) level but not the table level.

Currently, MyBB's using VACUUM is working on tables rather than databases/schemas, which is wrong: https://github.com/mybb/mybb/blob/mybb_1...e.php#L923

And there's more. This function does fail when the VACUUM query tries to closeCursor() in https://github.com/mybb/mybb/blob/mybb_1...e.php#L924 .
Actually the error was from the VACUUM itself. We can read the error using PDO's errorInfo() and the error message states "cannot VACUUM - SQL statements in progress".

Then, there are two things we can get:
1. SQLite's VACUUM works on database (schema), not current MyBB's using on table.
2. As there would be any uncontrollable query [b]without running before the DB class execute VACUUM on the database, there would (nearly) always that error preventing the db engine to optimize the database.

So I suggest to just remove the function body in SQLite and leave out SQLite's database optimization.

For future development, we could start thinking about SQLite's VACUUM [...] INTO ... to optimize the database and generate a new db file and replace the old db file with it.

My old suggestion was: since the function is intended to run over tables, we may pass SQLite's implementation for it and add another optimize_db() function dedicated to SQLite for maintenance usage, such as Database Optimization and Database Backup. However, currently MyBB doesn't have database information such as database name stored in the DB object, it wouldn't be easy to implement such optimize_db() function. It'd be better to defer this part to 1.9.
Hi,

Thank you for your report. We have pushed this issue to our Github repository for further analysis where you can track our commits and progress with fixing this bug. Discussions regarding this bug may also take place there too.

Follow this link to visit the issue on Github: https://github.com/mybb/mybb/issues/4498

Thanks for contributing to MyBB!

Regards,
The MyBB Group