1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Method for truncating tables

Discussion in 'XenForo Suggestions' started by digitalpoint, Apr 9, 2015.

  1. digitalpoint

    digitalpoint Well-Known Member

    It would be handy (maybe for XF 2.0?) if the database handler had a method to empty tables. Some storage engines do different things internally when TRUNCATE TABLE is called. Most notably:
    So if you are doing something like a backup while a TRUNCATE statement happens, the statement hangs until the backup is done because drop table/create table isn't allowed during a hot backup. If the backup takes too long, the truncate statement ends up just failing after whatever timeout you have for SQL statements in your config.

    Long story short is that a "DELETE FROM [table_name]" *is* allowed during hot backups since it doesn't internally drop the table and recreate it.

    So it would be nice if we had a central "empty table" method of some sort so that we can override it's function in one place vs. extending a bunch of models with truncate SQL queries in them. A bonus step further would be to have a standard toggle option (similar to the one for using "INSERT DELAYED" [which btw is a deprecated MySQL function and should probably just be removed as an option]) that lets you toggle between "TRUNCATE TABLE xxxx" and "DELETE FROM xxxx" as the underlying statement.
    Last edited: Apr 9, 2015
    Eagle, Mijo, Daniel Hood and 6 others like this.

Share This Page