Reducing locking
BorisK
Member Posts: 45
Imagine you have a table, let's call it MyRec, primary key "Entry No."
You run some kind of processing on it, and when an entry gets processed a temporary entry TempMyRec is inserted with the same Entry No.
When the processing has finished you want to update your MyRec with "Processed" flag.
The most obvious way of doing it (to me) would be
IF TempMyRec.FINDSET THEN REPEAT
MyRec.GET(TempMyRec."Entry No.");
MyRec.Processed := TRUE;
MyRec.MODIFY;
UNTIL TempMyRec.NEXT = 0;
Slight problem is if you have millions of records this may lock MyRec table for long time causing problems for other users.
So I thought of an alternative:
IF TempMyRec.FINDSET THEN REPEAT
MyRec.GET(TempMyRec."Entry No.");
MyRec.MARK(TRUE);
UNTIL TempMyRec.NEXT = 0;
MyRec.MARKEDONLY;
MyRec.MODIFYALL(Processed,TRUE);
Question: will this lock the table for shorter time or will it not make any difference?
You run some kind of processing on it, and when an entry gets processed a temporary entry TempMyRec is inserted with the same Entry No.
When the processing has finished you want to update your MyRec with "Processed" flag.
The most obvious way of doing it (to me) would be
IF TempMyRec.FINDSET THEN REPEAT
MyRec.GET(TempMyRec."Entry No.");
MyRec.Processed := TRUE;
MyRec.MODIFY;
UNTIL TempMyRec.NEXT = 0;
Slight problem is if you have millions of records this may lock MyRec table for long time causing problems for other users.
So I thought of an alternative:
IF TempMyRec.FINDSET THEN REPEAT
MyRec.GET(TempMyRec."Entry No.");
MyRec.MARK(TRUE);
UNTIL TempMyRec.NEXT = 0;
MyRec.MARKEDONLY;
MyRec.MODIFYALL(Processed,TRUE);
Question: will this lock the table for shorter time or will it not make any difference?
0
Answers
-
Hi,
It may take possibly much much longer as the filtering based on MARKed records is getting very slow with begger number of records. Or at least it used to in versions pre-NAV2013.
Since you are now on RTC you have Text variable available which can be VERY long. I would try to build a filter for Entry No. field. The simple version would be Entry1|Entry2|Entry3.. and so on, then apply this filter to the MyRec table and use MODIFYALL.
Slawek
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-032 -
As far as i know, SQL server has maximum no of parameters (2100).
Therefore, you cannot add Entry No in text filter for large tables.
MODIFYALL could save some time.
Usually, all such modifications are scheduled during non-working hours with job queue.
And with log entries you could further analyze how much time it takes for each of these solutions.1 -
Maybe you can try to change the physical structure of the table using different Clustered key - this could reduce locking on the same pages.
clustered key GUID - can help, will store entries out-of-order
clustered key USERID, Entry No. - will keep blocks of records by users (don't know if possible in your case)
or create another key, which will make blocks more user dependend ...Regards
xStepa1 -
Why not MyRec.Processed := TRUE + MODIFY instead of Temping it? And then every 100 recs or so give it a COMMIT1
-
That is actually true. The string having 2101 Entry Nos separated by the | char would fail.As far as I know, SQL server has maximum no of parameters (2100).
In 'advanced' version of the filter, the filter expression could be built by a function like GetSelectionFilter in C46 in NAV 2017 (it was on the page/form 18 in earlier versions), which compresses consecutive PK values and could give much shorter (and more effective) expressions like Entry1|Entry3...Entry10|Entry11.. Which of course also does not guarantee that the parameter limit would not be hit
Perhaps the simplest solution as suggested by Duikmeester would be the bestSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions


