This is how TempDB tables implemented in MsDyn365FO
Paul Heisterkamp
Solution Architect at GWS mbH | former Microsoft MVP | FastTrack Recognized Solution Architect | DevOps Enthusiast | OneVersion and Evergreen ERP Advocate
I think almost every Microsoft Dynamics 365 for Finance and Operation developer knows how to create and use a TempDB tables via metadata or code. But I also think that only a few of them know how these tables implemented from a platform point of view. In this post I want to shade some light into this topic especially for environments running with Azure SQL.
My research and this post has been initiated by the following long running query which I found via LCS during one of our load tests: ALTER TABLE DBO.t9294BatchSASSB4AOS2246116_690AB03A15E646258EB6205137807460 ADD CONSTRAINT i9294_I_9294RECID_690AB03A15E646258EB6205137807460 PRIMARY KEY CLUSTERED (RECID)
What I was wondering after I found this query is: Why is this statement slow and why is this statement happening in the AxDB? The first question needs more analysis but the second question is an easy one. There is a setup in table SysGlobalConfiguration with name TEMPTABLEINAXDB which is set to 1 for environments using Azure SQL. This means all "temp tables" get created in the AxDB. And as far as I know there is no clean up routine for sandbox environments (but hopefully for production environments). As you can see in the banner of this post, you can also filter/find them using SQL Server Management Studio.
If you want to analyze the behavior on an one box (Tier1) environment you can simply insert a temp table via X++ code and try to find the created table in the tempdb. If you want the same behavior as in Azure SQL environments you can simply set the value for TEMPTABLEINAXDB to 1.
In case you found some if these tables and wonder how the naming works here is an example: t69329IISAXDEVHKA8016696528_8403528D2F314601966541DDA2BA3A8A
- t
- TableId: Id of the temp table which can be mapped to the right name via the table tableIdTable or view SysTableIdView
- IIS/Batch: IIS in case in IIS session has created the table or batch when batch created the table
- ServerId: The id/name of the server that crated the table
- Guid: Unique identifier
Now I′m interested in your comments because I was a bit shocked that all those temp tables get created in AxDB for environments using Azure SQL.
Solutions Architect at dots.365
2 年I have a comment regarding your statement in the original post "And as far as I know there is no clean up routine for sandbox environments (but hopefully for production environments)." Have you done any further investigation on this topic? I can share that in production environment (average sized cloud installation, 4AOSes, lots of mods, high user load during daytime ) our client runs, currently there are almost 15k t% tables, collected over a year. So apparently system isn't doing a successful cleanup. I can't believe they're still in use, therefore I'm about to create a support ticket.
Solutions Architect at dots.365
2 年Hi Paul Topic is bit old, but still might be relevant. DB administrator informed me, that database copies from production contain high number ( more than 10 thousand) of "temporary" tables in AXDB. Lot of them where empty, but not all. I might not recall exact dates and PUs, but per May 2022, there were even "temporary" tables, oldest created even back in August 2021. In our case it happened when PU43 was applied. I guess, there is some routine who drops these tables, but apparently it hadn't worked in our case. At least not all instances of tables were dropped. One possible reason for that - there happens AOS crashes couple times a week in our installation, but reason is not related to temp tables. May be after these crashes system isn't able to clean up those tables. I will check with DB admin now, to find out whether this issue is still a problem. Still - you topic was useful to understand what these table are, and to learn about existance of TEMPTABLEINAXDB. What I wanted to ask you - do you believe there are cases when system might run better when TEMPTABLEINAXDB = 0?
Technical Solutions Architect at Itineris
4 年Hi Paul, I came across your article when I was doing an investigation to a performance issue in which we were seeing high contention in the AxDB database on temp tables when running a multi-threaded batch (500+ bundles). We're experiencing a lot of waiting tasks, up to 60 seconds on just the creation, truncation or drop of temp tables. We're able to see this in a P15 database with only 5 AOS servers (16 threads each). After spending more than a week on this issue, I found out that by default, a TIER-2 environment stores its temp tables in the AxDB but that you can override this behavior by switching a setting in the database (see below). We have seen great performance improvements by enabling the setting, especially in processes that heavily rely on Temp tables such as posting free-text invoices (factor 3x more throughput). Temp tables are now being created in the tempdb. We're now being constrained by CPU database (to be expected), but at least it now scales properly again. In the mean time, Microsoft has confirmed that we should be using this setting to remove the bottleneck on the temp tables. UPDATE sysglobalconfiguration SET VALUE = 1, RECVERSION = 2 WHERE NAME = 'VOLATILE_ISGLOBALTEMPTABLEENABLED'? https://azure.microsoft.com/en-us/blog/database-scoped-global-temporary-tables-in-public-preview-for-azure-sql-db/ One issue: heavy use of temp tables is causing the Query Store to go in read-only mode. In our case, that happens already after a few minutes of batch processing. Apparently a known issue. We're working on that with Microsoft. Hope this helps!
Cloud Solution Architect @ Microsoft | Enterprise Solutions ?? #BizzApps | Data Analytics ?? | AI ??
4 年As usual in public SAAS cloud services, this is subject to change and is indeed different on different customers, both the implementation of temp tables and the naming of those. What is described is correct for some instances as of today, but not for all of them, and the configuration can and will change depending on the instance workload, future evolution of the platform, or changes on customer usage patterns. So, if you feel your tempdb is a problem please reach support or fast track for help :)