web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How can I disable DeleteAction on query?

(0) ShareShare
ReportReport
Posted on by 1,535

I want to delete about 40 000 records from table with 200 000 records. This table has DeleteAction with properties = Cascade.
I made query (not select!!!, not delete_from !!!) but it is strange becouse time for deleting each 1000 rows increasing !!!

new QueryRun(query);
while(queryRun.next())
{
MyTable= queryRun.get(tableNum(MyTable));
MyTable.doDelete();
}

Diff: 18,03 seconds (Sum: 18,03 seconds) : DeleteMethod BEFORE
Diff: 1,74 seconds (Sum: 19,77 seconds) : DeleteMethod row=1
Diff: 5,36 seconds (Sum: 25,13 seconds) : DeleteMethod row=1000
Diff: 7,55 seconds (Sum: 32,67 seconds) : DeleteMethod row=2000
Diff: 9,86 seconds (Sum: 42,53 seconds) : DeleteMethod row=3000
Diff: 12,03 seconds (Sum: 54,56 seconds) : DeleteMethod row=4000
Diff: 14,39 seconds (Sum: 68,95 seconds) : DeleteMethod row=5000
Diff: 18,05 seconds (Sum: 87,00 seconds) : DeleteMethod row=6000
Diff: 21,22 seconds (Sum: 108,22 seconds) : DeleteMethod row=7000
Diff: 24,78 seconds (Sum: 133,00 seconds) : DeleteMethod row=8000
..
Diff: 67,08 seconds (Sum: 741,38 seconds) : DeleteMethod row=20000
..
Diff: 96,05 seconds (Sum: 2 151,22 seconds) : DeleteMethod row=37000
Diff: 96,70 seconds (Sum: 2 247,92 seconds) : DeleteMethod row=38000
Diff: 97,23 seconds (Sum: 2 345,16 seconds) : DeleteMethod row=39000

Why time for deleting first 1000 rows is about 5 second but time for deleting rows 38001-39000 is about 100 seconds???


When I changed DeleteAction from Cascade to None all Diff is normal, about 0.6 seconds / 1000 rows. How can I disable DeleteAction on query (something like skipDeleteAction) ?

*This post is locked for comments

I have the same question (0)
  • nmaenpaa Profile Picture
    101,160 Moderator on at

    Please note that your query is not doing any deletion. It just fetches you the records. Did you try calling MyTable.skipDeleteActions() before calling doDelete?

    For mass deletion you can also use delete_from statement, which will delete everything on one database call (as long as delete() method is not overridden on the table).

  • Ireneusz Smaczny Profile Picture
    1,535 on at

    I have a query and it must be query!!!

    SkipDeleteAction not working with query.

    I know, that skipDeleteActions + delete_from working fine but I have query !

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Regarding the question "why?", consider using Trace Parser to find the answer.

  • Ireneusz Smaczny Profile Picture
    1,535 on at

    OK. I can find solution for long time using Trace Parser.

    But main question is: Can I disable DeleteAction in query ?

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    These are two different things - query is merely for fetching the data you want to delete; it doesn't delete anything. You delete records by delete() / doDelete() methods, regardless whether you fetched them from database by the query framework or a language-integrated select statement.

    skipDeleteActions(true) should work in these cases.

  • Ireneusz Smaczny Profile Picture
    1,535 on at

    In trace parser I have:

    MyTable.next

    select MyTable.next ...

    QueryRun::get

    MyTable.doDelete

    delete from MyTable ...

    TableCHILDFromDeleteAction::checkRestrictedDeleteAction

    delete from TableCHILDFromDeleteAction

    MyTable.next

    QueryRun::get

    MyTable.doDelete

    delete from MyTable ...

    TableCHILDFromDeleteAction::checkRestrictedDeleteAction

    delete from TableCHILDFromDeleteAction

    ...

    But I don't know how to made in query not to check TableCHILDFromDeleteAction (table from DeleteAction on MyTable) ???

    MyTable.skipDeleteActions() before while(queryRun.next()) not working :(

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    First of all, skipDeleteActions() doesn't set the flag - you must use skipDeleteActions(true) instead. Also, try calling it just before doDelete().

  • Ireneusz Smaczny Profile Picture
    1,535 on at

    Of course I writed in code skipDeleteActions(true) like this:

       MyTable.skipDeleteActions(true);    

       while(queryRun.next())

       {

           MyTable = queryRun.get(tableNum(PPLPayrollAbsence));

           MyTable.skipDeleteActions(true);    

           MyTable.doDelete();

       }

    But it is not working :-(

    In trace parser I still have:

    TableCHILDFromDeleteAction::checkRestrictedDeleteAction

    delete from TableCHILDFromDeleteAction

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    By the way, why do you want to disable the delete action? Just because of the performance of the deletion?

    What if you first deleted all matching records from the related table, and then from the parent table? Would that help with the performance? I guess you don't intend to leave orphan records behind.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Aha, according to Microsoft support blog (Using skipDeleteActions with doDelete still calls the delete actions), it seems it's more or less by design. It seems that Microsoft too was surprised by this behavior by they weren't going to change it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans