I have an iOS app that uses sqlite3 databases extensively. I need to add a column to a good portion of those tables. None of the tables are what I’d really consider large (I’m used to dealing with many millions of rows in MySQL tables), but given the hardware constraints of iOS devices I want to make sure it won’t be a problem. The largest tables would be a few hundred thousand rows. Most of them would be a few hundred to a few thousand or tens of thousands.
I noticed that sqlite3 can only add columns to the end of a table. I’m assuming that’s for some type of speed optimization, though possibly it’s just a constraint of the database file format.
-
What is the time cost of adding a row to an sqlite3 table?
-
Does it simply update the schema and not change the table data?
-
Does the time increase with number of rows or number of columns already in the table?
I know the obvious answer to this is “just test” and I’ll be doing that soon, but I couldn’t find an answer on StackOverflow after a few minutes of searching so I figured I’d ask so others can find this information easier in the future.
From the SQLite ALTER TABLE documentation:
The documentation implies the operation is O(1). It should run in negligible time.