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)

CostSheetCache Table Size Too Large

(0) ShareShare
ReportReport
Posted on by 6,609

Hi,

I was running the top table size report in SMS and was shocked to find that the CostSheetCache table was 31GB with 370K records. Unsure if this translate correctly but I was curious if there are available clean-up jobs available to recover some of the disk space. The larger question being whether I should be cleaning up this table (why / why not?). Thank you!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    raelhefn Profile Picture
    on at

    Try Table indexes, should be rebuilt periodically to ensure optimum data query performance and synchronize database . Re-indexing  via Administration>Periodic>SQL administration + check database

  • bankk Profile Picture
    6,609 on at

    Thanks for the reply Ramy. Actually before jumping to conclusions, I probably should have asked if the size is normal and is to be expected.

  • André Arnaud de Calavon Profile Picture
    301,119 Super User 2025 Season 2 on at

    Hi KBahn,

    The business logic in AX seems to create new records in this table only. There is no cleanup task. I think the best you can do is create a support incident at Microsoft and ask them about this. The number of records and table size is too large in my opinion, but I'm not completely sure.

    You can also try to delete it in a test environment to see if it impacts e.g. BOM cost calculations.

  • bankk Profile Picture
    6,609 on at

    Thank you Andre.

    If anyone's willing to share, I'm curious about the size of their COSTSHEETCACHE table. In production we're looking at ~475K rows and ~37GB. The values I provided in the opening post were from a test environment. TIA!

  • Verified answer
    dekaasboer Profile Picture
    1,530 on at

    Kbanh, if you go to production control -> setup -> routes -> cost groups.

    Simply select a record and save it. AX wil delete all records by calling this method. (per company)

    msdn.microsoft.com/.../costsheetfactory.clearcacheddata.aspx

  • bankk Profile Picture
    6,609 on at

    Hello Rik,

    I've tried your suggestion in a test environment with a COSTSHEETCACHE table size of about 30GB. The Cost group form is non-responsive so I left it running for about 3 hours with no identifiable change in the record count on COSTSHEETCACHE. 30GB of data is a lot to clear but it just appears to be stuck. Any ideas?

    Thanks.

  • André Arnaud de Calavon Profile Picture
    301,119 Super User 2025 Season 2 on at

    Hi KBanh,

    Rik deserves a Rookie of the week award for his answer. :) At least you can verify his answer.

    The next code is used to delete the cache:

    public void clearCachedData()
    {
        CostSheetCostGroupImpact    costSheetCostGroupImpact;
        CostSheetCache              costSheetCache;
    
        delete_from costSheetCostGroupImpact
            where costSheetCostGroupImpact.SheetId == sheetId;
    
        delete_from costSheetCache
            where costSheetCache.SheetId == sheetId;
    }


    There is one single statement to delete the cache records. This is why you don't see the progress until it is finished. The number of records is very large in your environments.

    You can check whether the cache table contains records for only one sheet ID or more. If it is one, you can eventually you can create a job like this to delete the records then. Probably this will be faster:

    static void DeleteCache(Args _args)
    
    {
        deleteTable('CostSheetCostGroupImpact');
        deleteTable('CostSheetCache'); }


  • bankk Profile Picture
    6,609 on at

    I appreciate the follow-up Andre. I need to look at this a little closer.

  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at

    We have a batch job that we run periodically to purge the CostSheetCache table in all companies.  It calls the CostSheetFactory.clearCachedData method directly.  Yes, it takes a while.  The other way to do this manually is to save the cost sheet itself.

  • bankk Profile Picture
    6,609 on at

    Brandon,

    Do you know approximately how large your COSTSHEETCACHE table gets before your purge job runs? And how long does it typically take to complete per company?

    Thanks in advance.

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