using spmfupdatetableInbatches for batch updates¶
Examples of using spMFUpdateTableinBatches to update a large class table in bulk. The background, and what to expect from each run, is in Update large tables in bulk using batch mode.
Why use it:
when taking on the records from M-Files into SQL with a large volume. It can also be used for mass updating of records from SQL into M-Files.
there is nothing that prevents the use of this procedure for low volumes, but it is advisable for record sets in excess of 10,000.
the procedure updates records in batches of 500. If it is stopped, or fails, the records already updated stay intact.
it is easier to monitor progress through a large data set (
@WithStats = 1).in the case of update method 1 the objects are processed in object ID order, from
@FromObjidto@ToObjid. Only objects of this class that the table audit marks as new or changed are processed; every batch holds 500 of them except the last.only one class within an object type can be processed at a time.
in the case of update method 0 the records to update are all records set to
Process_ID = 1.@FromObjidand@ToObjidare ignored.when updating with update method 0 and something goes wrong, the outstanding records show
Process_ID = 99. It is not necessary to reset them. Just rerun the procedure to continue the update.
Parameters:
@FromObjid: only applies to update method 1. The first object ID of the range, default 1. To restart after a stop, run again with the same@FromObjidand@ToObjidand@WithTableAudit = 0: objects already loaded are skipped.
@ToObjid: only applies to update method 1. The last object ID of the range, default 1,000,000. It is an upper limit, so a value above the highest object ID does no harm. Best practice: the highest object ID of the class plus 500 (see below).
@WithTableAudit: set to 1 to refresh the table audit first. Use 1 for a first load; with 0 the procedure uses the result of the last table audit, and nothing is processed if none has run. In the current release batch mode loads nothing into an empty class table: load a few objects withspMFUpdateTableand@ObjIDsfirst, then run batch mode with@WithTableAudit = 1(see Update large tables in bulk using batch mode).
@WithStats: set to 1 to show the progress of each batch, or 0 to run without messages.The batch size is fixed at 500. For very large volumes, run in ranges of object IDs (for example 100,000 at a time) and let M-Files background processing catch up between runs. Earlier releases used
@maxobjid,@BatchesToRunand@MinObjid, which no longer exist.
how to get the max id’s in a vault¶
EXEC dbo.spMFObjectTypeUpdateClassIndex @IsAllTables = 1 -- setting to 0 will only include includedinapp class tables
,@Debug = 0 -- smallint
SELECT COUNT(*), MAX(ah.ObjID) FROM dbo.MFAuditHistory AS ah
INNER JOIN dbo.MFClass AS mc
ON mc.MFID = ah.Class
WHERE mc.TableName = 'MFLarge_Volume'
Update from M-Files to SQL¶
EXEC dbo.spMFUpdateTableinBatches @MFTableName = 'MFLarge_Volume' -- nvarchar(100)
,@UpdateMethod = 1 -- int
,@WithTableAudit = 1 -- int: 1 on a first load; 0 reuses the last table audit
,@FromObjid = 1 -- bigint
,@ToObjid = 12000 -- bigint: highest object ID + 500
,@WithStats = 1 -- bit
,@Debug = 0; -- int
Interpreting the results.¶
Each batch shows its processing time in seconds, the object ID it started from (“From objid ID”), and the number of records processed. A batch holds only objects of this class that the table audit marks as new or changed, so its object IDs need not be consecutive. Every batch holds 500 objects except the last.
If every batch processes 0 records on a class table that was empty, see the note on empty class tables in Update large tables in bulk using batch mode.
Update from SQL to M-Files¶
UPDATE mlv
SET Process_ID = 1 , Name_Or_Title = Name_Or_Title + '(' + CAST(Objid AS NVARCHAR(10)) + ')'
FROM dbo.MFLarge_volume AS mlv
WHERE id BETWEEN 10000 AND 12000
EXEC dbo.spMFUpdateTableinBatches @MFTableName = 'MFLarge_Volume' -- nvarchar(100)
,@UpdateMethod = 0 -- int
,@WithStats = 1 -- bit
,@Debug = 0;
Interpreting the next result¶
(2000 rows affected) the run will show the total number of records to be updated remaining: 1500 this show the number of records still to be processed.