Exploit the fact that a SQLite database is contained in a single file.
It will probably be faster to create a new database, copy there what you
want to keep, then rename tmpfile.db to yournormal.db, reopen the
connection and you're done.
This goes along the lines of:
ATTACH DATABASE 'tmpfile.db' AS pruned;
CREATE TABLE pruned.blob ... ;
INSERT INTO pruned.blob SELECT * FROM blob WHERE <what you need to keep>;
DETACH DATABASE pruned
-- Christian
With the risk of sounding sarcastic, I would suggest: don't use the
database for image storage. Write to files, and keep track of file
paths in the database. It *will* be faster. Since you're using
sqlite, I assume you're not doing replication and such, so that
shouldn't be an issue.
j
--
Joshua Kugler
Part-Time System Admin/Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/ �ID 0x73B13B6A
On 06/10/2010 11:14 PM, durumdara wrote:
> Interesting, that "delete from blobs" is have same speed as "drop
> table blobs"... :-(
I don't quite understand what you mean by that, but the former is
implemented almost exactly as the latter:
http://www.sqlite.org/lang_delete.html
> The blob table is:
>
> filename varchar(255) not null,
> ext varchar(3) not null,
> size integer not null,
> data blob,
> primary key (filename, ext, size)
Is that exactly the order you declared the columns? You should always put
blobs last otherwise SQLite has to walk through the blob to get to columns
after it.
In any event this is not a good use case for SQLite. The images you make
are "produced" from the originals so you only need to store the parameters
of that production in the database rather than the actual output and use the
filesystem for what it is really good at - storing files.
Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkwTHD8ACgkQmOOfHg372QQCyQCgj28l//CvxJteXiiURgz3rFU/
0TUAoNdVUBwlO1TgCE7slkhqBUhqL9iq
=kIlp
-----END PGP SIGNATURE-----
On 06/14/2010 12:05 AM, durumdara wrote:
> I understand it - files are better placed in filesystem - but database
> is protect the operation with transactions in I can keep all data in
> one secure place...
SQLite isn't performing magic. The "secure" part is that it calls fsync()
on the file and parent directory. You can do exactly the same and will have
the same amount of "security".
In any event this is the only way you will get an appreciable improvement in
performance.
Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkwWH6cACgkQmOOfHg372QS53wCdHD+BI7PTyApBZfJKLlPTpdGJ
jc8An14rI8DJ7LPwocTCi8O/ltit7ShF
=s+gW
-----END PGP SIGNATURE-----