On 27 Jul 2009, at 11:09pm, W.-H. Gu wrote:

>  In my C application, I create a table and insert 32 rows every  
> second.
> Each row has about 28KB. Every 5 seconds, it deletes old rows with  
> timestamp
> <= current time - PERIOD. I did create an index on the column  
> 'timestamp,'
> but I observed that every 5 seconds, cpu usage hits up to 9%.  
> Without index,
> cpu usage is just a bit more (10~11%). This doesn't happen when I  
> disable
> the delete operations.

First, I assume that this deletion is done with one DELETE command.

Second, percentage CPU figures don't mean much unless the computer is  
doing other CPU-intensive tasks.  If this SQL application is the only  
real task it's doing, a change of even 50% in CPU usage means  
nothing.  Look at CPU usage as a total, not as a percentage.

>  My question is: is there a discussion saying that delete in SQLite  
> may use
> more cpu usage than others like MySQL?

This may be an insert/delete payoff.  MySQL may do the bare minimum  
when you delete records, on the assumption that you want the DELETE to  
run as fast as possible.  SQLite may do some clean-up work when you  
delete records to make any subsequent INSERT command run as quickly as  
possible.  So you need to look at the total CPU usage over all  
transactions, not just the DELETE commands in isolation.

> is there a way to fix it?

First, make sure something is wrong.  Don't engage in premature  
optimisation.

Simon.

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to