On 10/30/15, aa <woshishaoda07 at 163.com> wrote: > But recently I meet a problem about inserting data into table.It is > too slow whit index. > The first I create a table like this: > CREATE TABLE mac_tb (mac BIGINT PRIMARY KEY? > If I insert into mac_tb with mac ordey by num desc or asc , then the > speed is fast. > If I insert the mac randomly, then the speed will grow slower whit > the increasing of data.
Don't forget that you should use transactions. Start a transaction with the BEGIN TRANSACTION statement, insert many rows (possibly all million you have, possibly just ten thousand), and then use the COMMIT TRANSACTION statement. If you do not explicitly start a transaction, then sqlite will execute each statement in a separate transaction, which could mean a transaction per row. This can be expensive, as described in "http://sqlite.org/faq.html" . Further, if I understand correctly, if you do lots of inserts at the same time, then WAL mode might slow down the operation a bit. WAL mode is not the default, but someone might have enabled it in your database. Check with the PRAGMA journal_mode command that it is not enabled: if that command returns "wal", then WAL mode is active. Try to disable WAL mode if you're doing mass inserts. -- ambrus