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

  • Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: How can I disable DeleteAction on query?

    It's not the only solution - you could also use delete_from. If you're concerned about performance, you should do it anyway, because calling database once is clearly much more efficient than calling it forty-thousand times.

    You said you can't do it, but if I was you, I would review if it's really impossible.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: How can I disable DeleteAction on query?

    One more question - why does it have to work with a query? If it's some cleanup job, I've many times added a field "older than x days" in the setup dialog, which I can use with a "delete_from" statement, instead of iterating the query hundreds of thousands of times. Would this work out for you?

  • Ireneusz Smaczny Profile Picture
    Ireneusz Smaczny 1,535 on at
    RE: How can I disable DeleteAction on query?

    @Nikolaos Mäenpää

    I want to disable delete action on MyTable because in previous step I deleted all connected to parent rows from child table TableCHILDFromDeleteAction. It was very fast because it is one query and deleting about 350 000 rows. In second step I want to delete in one query 40 000 rows from MyTable but with DeleteAction I have one main query and redundant 40000 queries with range to TableCHILDFromDeleteAction. And I don’t know why deleting each 1000 rows takes more and more time (20x more time !!!)

    @Martin Dráb

    I understand that I must change DeleteAction on my MyTable from Cascade to None. It is only one solution.

  • Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: How can I disable DeleteAction on query?

    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.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: How can I disable DeleteAction on query?

    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.

  • Ireneusz Smaczny Profile Picture
    Ireneusz Smaczny 1,535 on at
    RE: How can I disable DeleteAction on query?

    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

  • Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: How can I disable DeleteAction on query?

    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
    Ireneusz Smaczny 1,535 on at
    RE: How can I disable DeleteAction on query?

    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
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: How can I disable DeleteAction on query?

    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
    Ireneusz Smaczny 1,535 on at
    RE: How can I disable DeleteAction on query?

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

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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans