On Fri, Nov 29, 2013 at 2:37 PM, Igor Tandetnik <i...@tandetnik.org> wrote:

> On 11/29/2013 8:33 AM, Carlos Ferreira wrote:
>
>> Any of you know how to speed up the creation of empty tables in SQlite?
>>
>> If I have to create more than 1000 empty tables to initialize my
>> application
>> document it takes a while..
>>
>
> Make sure you run all CREATE TABLE statements within a single transaction.
> My guess is you don't, and then most of the time is spent in committing an
> implicit transaction after every statement.


Here's a simple test which shows that in action:

[stephan@host:~/tmp]$ i=0; while [ $i -lt 1000 ]; do echo "create table t$i
(a,b,c);"; i=$((i + 1)); done > foo.sql
[stephan@host:~/tmp]$ wc -l foo.sql
1000 foo.sql
[stephan@host:~/tmp]$ echo 'begin;' > bar.sql
[stephan@host:~/tmp]$ cat foo.sql >> bar.sql
[stephan@host:~/tmp]$ echo 'commit;' >> bar.sql
[stephan@host:~/tmp]$ time sqlite3 x.db < foo.sql

real 2m25.208s
user 0m0.380s
sys 0m0.468s
[stephan@host:~/tmp]$ rm x.db
[stephan@host:~/tmp]$ time sqlite3 x.db < bar.sql

real 0m0.344s
user 0m0.148s
sys 0m0.000s


BIG difference.

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Since tyranny's the only guaranteed byproduct of those who insist on a
perfect world, freedom will have to do." -- Bigby Wolf
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to