View Single Post
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 11-14-2015 , 18:34   Re: Efficient Database Insertion
Reply With Quote #6

I hoped your table structure is a little bit simpler so you could temporarily store the data you'd insert into an finite array which will be used to construct the multi insert query when full or some time has passed.

I have no better idea at the moment so i tested how big the difference would be with 10 simple queries to the sqlite database. The code using a transaction looked like this.
PHP Code:
char query[1024];

Transaction txn SQL_CreateTransaction();
for (
int i=0<= 10i++)
{
    
Format(querysizeof(query), "INSERT INTO `test` (`id`) VALUES (%d)"GetRandomInt(1999999));
    
txn.AddQuery(query);
}

SQL_ExecuteTransaction(g_hDbHandletxnTXN_OnSuccessTXN_OnFailure); 
It took 0.014 ms on average on my machine for 10 queries, 100 took around 0.057 ms.

Then i used normal queries where the code looked like this.
PHP Code:
char query[1024];

for (
int i=0<= 10i++)
{
    
Format(querysizeof(query), "INSERT INTO `test` (`id`) VALUES (%d)"GetRandomInt(1999999));
    
g_hDbHandle.Query(SQLT_ErrorCheckCallbackquery);

This took 0.015 ms on average on my machine for 10 queries, 100 took around 0.075 ms.

Is that what you were interested in?
__________________

Last edited by Impact123; 11-14-2015 at 19:09.
Impact123 is offline