Sqlite3: how to reorder columns in a table?

后端 未结 4 784
别跟我提以往
别跟我提以往 2020-12-31 03:42

It seems that it is not straightforward for reordering columns in a sqlite3 table. At least the sqlite manager in firefox

4条回答
  •  孤城傲影
    2020-12-31 03:50

    The order in sqlite3 does matter. Conceptually, it shouldn't, but try this experiment to prove that it does:

    CREATE TABLE SomeItems (identifier INTEGER PRIMARY KEY NOT NULL, filename TEXT NOT NULL, path TEXT NOT NULL, filesize INTEGER NOT NULL, thumbnail BLOB, pickedStatus INTEGER NOT NULL, deepScanStatus INTEGER NOT NULL, basicScanStatus INTEGER NOT NULL, frameQuanta INTEGER, tcFlag INTEGER, frameStart INTEGER, creationTime INTEGER);
    

    Populate the table with about 20,000 records where thumbnail is a small jpeg. Then do a couple of queries like this:

    time sqlite3 Catalog.db 'select count(*) from SomeItems where filesize = 2;'
    time sqlite3 Catalog.db 'select count(*) from SomeItems where basicscanstatus = 2;'
    

    Does not matter how many records are returned, on my machine, the first query takes about 0m0.008s and the second query takes 0m0.942s. Massive difference, and the reason is because of the Blob; filesize is before the Blob and basicscanstatus is after.

    We've now moved the Blob into it's own table, and our app is happy.

提交回复
热议问题