r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[SQLite] C library embeddable DB .

Janko
17-Mar-2009
[943]
I hope this doesn't mean I something else won't work as it should
Dockimbel
17-Mar-2009
[944]
Have your application execute the following SQL statement and then 
look at the result : select sqlite_version(); 

AFAICT, sqlite3_prepare_v2 is available starting from SQLite 3.5.2.
Janko
17-Mar-2009
[945]
aha.. stupid me.. apt-get usually doesn't provide latest versions 
but a more "stable" ones ... yes it's  3.3.8
Dockimbel
17-Mar-2009
[946]
You don't need to use apt-get for sqlite, just download the latest 
library and put it in your app folder near sqlite.r : http://www.sqlite.org/sqlite-3.6.11.so.gz
(I guess you'll need to rename it to libsqlite3.so).
Janko
17-Mar-2009
[947]
thanks Doc!
amacleod
1-Apr-2009
[948]
I did not realize sqlite.r was set up to use mysql3.so (linux libs) 
Got my app running on linux witout a hitch...
Auto detects OS...great!
Janko
11-Apr-2009
[949]
this might be usefull to users of sqlite.. I yesterday encountered 
the "db is locked" error and it got me a little worried, but with 
this (simple) aproach it seems to solve that http://itsystementwicklung.de/pipermail/list-pysqlite/2009-April/000380.html
Janko
14-Apr-2009
[950x2]
.
I don't get this ... I started getting very long loading times with 
my webapp when I changed or inserted the and it was very fast before 
... now I saw that it's the sqlite making these delays.. this is 
not the problem of sqlite.r but the sqlite itself because I get the 
same behaviour with sqlite3 shell.


But I can't believe this , I am certain I am doing something wrong.. 
I remember sqlite can handle GB of data and is very fast, but in 
my case... I have 183 rows in a simple 5 column table (db file is 
10kb) .. if I do single update table X set y = ".." where Z = ".."; 
 it takes like 3 seconds. This updates just 1 row out of 183. Does 
anyone have any idea? I tried to do the "Vacuum" command but it's 
the same after it.
Pekr
14-Apr-2009
[952]
can you post whole query?
Janko
14-Apr-2009
[953x5]
I also added the indexes now and it is maybe a little faster but 
on single where but on both that I need it looks more or less the 
same (select by same condition is imeddiate)
Pekr.. I will
This is a very small VPS, but I have 300kb raw rebol data structures 
in ordinary files, and I edit and seek them without any indexes and 
it works immediatelly..  I only moved this part of data to sqlite 
because it handeles the file locking ( these are sort of mailboxes 
so that the app and bots can communicate over them )
CREATE TABLE [domains] (
[id] INTEGER  NOT NULL PRIMARY KEY,
[domain] VARCHAR  NOT NULL,
[user] VARCHAR  NOT NULL,
[processed] DATETIME  NULL,
[ok_count] INT NOT NULL DEFAULT 0,
[fail_count] INT NOT NULL DEFAULT 0,
[error] TEXT NULL
)

test query is as straighforward as it can be: 


update domains set user = "u3" where domain = "www.todelete.com" 
and user = "u3";
I tried now with transaction .. it has no point here becauase it's 
just one query at the time ... but results were as expected.. update 
did finish imediatelly , but commit took the 1-3s time also
Pekr
14-Apr-2009
[958x2]
try to index domain, and maybe even user fields, or it will go sequentially 
thru all of record lines ...
btw - why do you set user="u3" for records, where user is already 
of "u3" value?
Janko
14-Apr-2009
[960x4]
Because times vary from 1s to 5s I suspect taht vps's disk or something 
might be a little owerburdened, but as I said 300kb rebol (this is 
10kb) worked im ms range according to cheyenne
u3
 is just here for testing purposes, so I can repeat the query :)
I added the indexes to both, and each separate .. but it's roghly 
the same ... before indexes select returned imediatelly on the same 
where
I will insert random rows so I will have couple of 1000 , and then 
I will see what I get
Pekr
14-Apr-2009
[964]
OK, index you ID field, then also user and domain field
Janko
14-Apr-2009
[965]
I did before when trying stuff

index|dom_user|domains|11|CREATE INDEX dom_user on domains ( domain, 
user )
index|dom1|domains|16|CREATE INDEX dom1 on domains ( domain )
index|user1|domains|21|CREATE INDEX user1 on domains ( user )
Pekr
14-Apr-2009
[966x3]
I would left out first index and add index for your primary key .... 
(not sure though :-)
simply put - how db chooses, which index to use? You have them separate 
as well as mixed. I would use mixed index (domain,user) only if those 
two fields would be defined as a primary key together ...
... well, I am not good at sql internals, so .... try various combinations, 
and you'll see ..
Janko
14-Apr-2009
[969x4]
but I am sure even if I write that data inf ile as rebol blocks and 
load and foreach them to find the one it would take far less than 
1s , it's just 180 rows!!!! :)
(maybe I just need a better VPS)
hm.. very interesting results... and positive basically :) with 4000 
records insert time, and update time for the same query is just the 
same as with 183 , and select is fast as before...  then it's survivable 
.. I was afraid that if with so few rows it's so bad with couple 
more it will be unworkable
have to go..storm
sqlab
14-Apr-2009
[973]
If you update an index field, the index too has to be updated.

Do you open and close your db, as it is recommended in the link you 
posted?
Then you have to add the time for that too.
Janko
14-Apr-2009
[974]
I had it without indexes at first , and later added indexes while 
I was trying various things, at 180 records there wasn't any noticable 
change. Well the result doesn't seem so bad to me right now.. if 
it has the same delay with 4000 records it's okey-ish. On my local 
computer which is much better than some small VPS I noticed no delays. 
I just realized that the delay at web-app was 3x bigger than this 
because I have 3 bots and each has it's own "mailbox" ... The solution 
for this situation will be affloading the inserts from the request 
process, for the future when things will need to scale up I will 
try doing this different anyway, that's why I was playing with actor 
like systems anyway
Oldes
14-Apr-2009
[975x2]
1s to 5s on 180 rows is bad. whatever you do.
I'm not sqlite user but I would probably tried to use EXPLAIN to 
see, what's going on when you do the query - http://www.sqlite.org/lang_explain.html
Janko
14-Apr-2009
[977x2]
yes, I think so too.. it is interesting that the time looks the same 
on 4000 rows ...  maybe reason for this is also because I am on some 
very cheap VPS (12EUR, 180MB ram, ? CPU) ...
aha, thanks for idea.. I will use explain .. although it's so simple 
query that it shouldn't do any strange things I think
Oldes
14-Apr-2009
[979]
also... if you want to index domain and user, you should not use 
varchar without length.
Janko
14-Apr-2009
[980x2]
aha, I will try that .. and I can use Integer for user ... because 
now each user get's folder like u<Int> ... and I could maybe put 
all 3 mailboxes into the same table so it would be only 1 insert 
/ update instead of 3 on changes ... I didn't think performance will 
be the problem here (it still seems a little funny) , because it's 
just a simple table without any relations or anything and no big 
amunt of data
I used sqlite here and there for more real DB work and I never seen 
any critical slownes (extept if you do a typical like inserting 100 
rows each in it's own transaction (without begin commit), in fact 
it seemed always very fast to me ... thats why I suspect all this 
wouldn't show up if I had some better VPS. Also because if fluctuates 
so much I suspect disk on computer vps is on is maybe busy doing 
other stuff so at one moment it is idle and it works faster at another 
it waits for >3 seconds
Oldes
14-Apr-2009
[982]
Yes.. it's possible, that the VPS does many other disk IO oparations 
so you have to wait.
Janko
14-Apr-2009
[983]
but the changes you proposed will help me get it faster anyway and 
I will try them
Pekr
14-Apr-2009
[984]
you can use varchar even for indexes, it should speed up things significantly 
...
amacleod
16-Apr-2009
[985]
Is there a way to reorder columns in SQLITE?
Janko
16-Apr-2009
[986]
alter table supports just renaming table and adding rows, for all 
else you need to create new table -> insert .. select ... ; data 
and drop old and rename new
sqlab
16-Apr-2009
[987]
In sql there is no need for reordering the column order, as you can 
get any order you desire by using the column names in your select 
statement.
amacleod
16-Apr-2009
[988x3]
That sounds helpful..thanks sqlab.
Can you do the same for inserting values?

I know I can do it for updating row data but I can not figure out 
the syntax for inserting..
For example:

SQL reduce [{UPDATE books SET bk=?, chap=? WHERE ref_number=?} blk/2 
blk/3 blk/1]
sqlab
16-Apr-2009
[991]
should be like
insert into table (col3, col2, col1) values (?, ?, ?)
amacleod
16-Apr-2009
[992]
works...thanks a lot. 

I had this fear of having to change large parts of my code if I added 
or removed columns...This solves that problem.