Download the PHP package helbrary/db-performance without Composer
On this page you can find all versions of the php package helbrary/db-performance. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download helbrary/db-performance
More information about helbrary/db-performance
Files in helbrary/db-performance
Package db-performance
Short Description Library for increase performance of db in Nette Database using multi-update and multi-insert.
License BSD-3-Clause GPL-2.0 GPL-3.0
Informations about the package db-performance
DbPerformance
This library is useful for bulk import to database.
Install in composer.json
Multi-insert
Create instance
Third parameter in constructor is buffer limit (optionaly). Default value is 100. It means that if buffer contains 100 records and we wont add next record, it's build multi insert and send to database. Buffer is empty and to buffer is add new record.
Add record to buffer (function don't insert record to database yet)
If we add to buffer all records, it's necessary insert records to database from buffer.
Multi-insert Failed
In case throw exception in database, for example constraint violations, is multi-insert divide into single inserts. These single inserts are send to database individually (one record = one insert). When single insert throw exception, it's invoke callback $onFailure.
OnFailure callback
Multi-update
Create instance
Add record to buffer (function don't update record in database yet)
If we add to buffer all records to update, it's necessary send update records to database from buffer
Recommended buffer limit
Buffer limit defines how many SQL commands will be joined to one multi-command. Default value of buffer limit is 100. It's possible to change this value in constructor by variable $limit. If SQL commands will throw some type of Exception often, it's better set buffer smaller. If SQL commands will throw some type of Exception rarely it's better set buffer higher.
Testing - Insert 100 000 records (no SQL INSERT throw Exceptions)
1) One by one record: 16 min 55 sec
2) One by one record in transaction: 4 min 50 sec
3) Using Helbrary\DbPerformance\MultiInsert with (default) buffer size 100: 0 min 20 sec
4) Using Helbrary\DbPerformance\MultiInsert with buffer size 500: 0 min 14 sec
5) Using Helbrary\DbPerformance\MultiInsert with buffer size 1000: 0 min 12 sec
6) Using Helbrary\DbPerformance\MultiInsert with buffer size 10000: 0 min 11 sec