Well, I ran some tests and came to a conclusion.
Follows the detailing:
- "Which of these options is better and faster ..."
Faster
The fastest way to get into the database is to implement with Insert_RecordSet
.
Caption:
- Insert Regular ->
buffer.insert()
- Insert List ->
RecordInsertList
- Insert UOW ->
UnitOfWork
- Insert_recordset ->
Insert_RecordSet
Code used in tests
class PerformanceTestes_COL
{
MuBuffer buffer;
int rows;
int timeStart;
int timeEnd;
int i;
str timeConsumed;
}
private void process() {
rows = 10000;
this.InsertTest();
this.RecordInsertListTest();
this.UOWTest();
this.insertRecordSetTest();
}
private void InsertTest() {
buffer.clear();
timeStart = timeNow();
for (i = 0; i < rows; i++)
{
buffer.InventSiteId = "001";
buffer.ItemId = "161634";
buffer.RetailVariantId = "53458";
buffer.insert();
}
timeEnd = timeNow();
timeConsumed = timeConsumed(timeStart, timeEnd);
info(strFmt("Insert Regular (%1) rows - time: %2", rows, timeConsumed));
}
private void RecordInsertListTest() {
RecordInsertList list = new RecordInsertList(tableNum(MixItemCovCopy_TestPerformance_COL));
;
buffer.clear();
timeStart = timeNow();
for (i = 0; i < rows; i++)
{
buffer.InventSiteId = "002";
buffer.ItemId = "161634";
buffer.RetailVariantId = "53458";
list.add(buffer);
}
list.insertDatabase();
timeEnd = timeNow();
timeConsumed = timeConsumed(timeStart, timeEnd);
info(strFmt("Insert List (%1) rows - time: %2", rows, timeConsumed));
}
private void UOWTest() {
UnitofWork uow = new UnitofWork();
;
buffer.clear();
timeStart = timeNow();
for (i = 0; i < rows; i++)
{
buffer.InventSiteId = "003";
buffer.ItemId = "161634";
buffer.RetailVariantId = "53458";
uow.insertonSaveChanges(buffer);
}
uow.saveChanges();
timeEnd = timeNow();
timeConsumed = timeConsumed(timeStart, timeEnd);
info(strFmt("Insert UOW (%1) rows - time: %2", rows, timeConsumed));
}
private void insertRecordSetTest() {
// Buffer 2 contém 10000 registros
Buffer2 buffer2;
;
buffer.clear();
timeStart = timeNow();
insert_recordset buffer (InventSiteId, ItemId, RetailVariantId)
select InventSiteId, ItemId, RetailVariantId from buffer2;
timeEnd = timeNow();
timeConsumed = timeConsumed(timeStart, timeEnd);
info(strFmt("Insert_recordSet (%1) rows - time: %2", rows, timeConsumed));
}
Best
The best way to insert in the bank is .. depends on! Because each case can be treated differently where it will not be possible to use one of the possibilities I mentioned in the answer.
For example: If a customization requires a processing in the data with some IF’s and business logic it will no longer be possible to use the Insert_RecordSet
because even though this is the faster, this form of insertion is not very malleable to treat the records before or at the time of the Insert.
Knowing this, we should evaluate the customization in which we will work and encode to implement and process the data according to the best practices of Microsoft. If this requires an appropriate mapping for different buffers it is convenient to implement with the UnitOfWork
. If only a business logic is needed during the iteration of a query
no doubt that we must use RecordInsertList
(2° faster) and not deal with a simple buffer.insert()
, this will bring a great gain in data processing.
My recommendation is not to use buffer.insert()
unless the customization is too simple or if all the other insertion options are exhausted, believe me, your server will thank you!
Useful links:
Insert -
Recordinsertlist -
Unitofwork -
Insert_recordset
I hope I’ve helped and clarified the matter.
Right, I already understand these processes superficially. But the 3 processes (
RecorInsertList
,insert_recordset
andUnitOfWork
) not only make a trip to the server ? insert_recordset ok, makes a trip to the server, already the methodsinsertDataBase()
ofRecordInsertList
and thesaveChanges()
ofUnitOfWork
also do not behave in the same way ?– 8biT