{"title":"Troubleshooting: Long Running SQL Queries Involving FlowFields by Disabling SmartSQL","url":"https://jonas-paprotka.de/docs/dev-itpro/administration/troubleshooting-queries-involving-flowfields-by-disabling-smartsql/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/troubleshooting-queries-involving-flowfields-by-disabling-smartsql, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/troubleshooting-queries-involving-flowfields-by-disabling-smartsql","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Learn how to fix long running SQL queries involving FlowFields by disabling SmartSQL.","date":"2021-04-01","meta":{"topic":"troubleshooting"},"outline":[{"level":1,"title":"Troubleshooting: Long Running SQL Queries Involving FlowFields by Disabling SmartSQL","slug":"troubleshooting-long-running-sql-queries-involving-flowfields-by-disabling-smartsql","at":0,"chars":5362},{"level":2,"title":"What is SmartSQL","slug":"what-is-smartsql","at":362,"chars":239},{"level":2,"title":"How SmartSQL works","slug":"how-smartsql-works","at":601,"chars":3408},{"level":2,"title":"How to isolate and test FlowField queries","slug":"how-to-isolate-and-test-flowfield-queries","at":4009,"chars":981},{"level":2,"title":"Related information","slug":"related-information","at":4990,"chars":372}],"text":"# Troubleshooting: Long Running SQL Queries Involving FlowFields by Disabling SmartSQL\nIf the performance of loading a page that contains FlowFields in Microsoft Dynamics NAV 2013 or later is bad, you might want to try isolating and testing FlowField queries separately. This article describes how to troubleshoot this scenario, and hopefully solve the problem.\n## What is SmartSQL\nIntroduced in Microsoft Dynamics NAV 2013, SmartSQL optimization does all calculations of FlowFields on a page by using a single SQL query. This reduces the number of network roundtrips from the server to the database.\n## How SmartSQL works\nTo understand how SmartSQL optimization works, consider this example from the CRONUS demonstration database. The database includes page 22 Customer List, which has the following FlowFields:\n Balance (LCY)\n Balance Due (LCY)\n Sales (LCY)\nNow, to see the SQL statement that is generated by the Dynamics NAV platform, start an SQL Server Profiler with the following events selected:\n Stored procedures - SP:StmtCompleted\n Performance - ShowplanXML\nThen, run the page in the Dynamics NAV client.\nHere is the resulting SQL query that is found in an SQL trace (modified to be more readable):\n```\nSELECT TOP (50)\n       ISNULL(\"Customer\".\"timestamp\",@0) AS \"timestamp\"\n     , ISNULL(\"Customer\".\"No_\",@1) AS \"No_\"\n     , ISNULL(\"Customer\".\"Name\",@2) AS \"Name\"\n       /* many more columns from the table dbo.\"MSFT$Customer\" */\n     , ISNULL(\"Customer\".\"OIOUBL Profile Code Required\",@6) AS \"OIOUBL Profile Code Required\"\n       -- SIFT columns start here\n     , ISNULL(\"SUB$Balance (LCY)\".\"Balance (LCY)$Detailed Cust_ Ledg_ Entry$SUM$Amount (LCY)\",@3) AS \"Balance (LCY)\"\n     , ISNULL(\"SUB$Balance Due (LCY)\".\"Balance Due (LCY)$Detailed Cust_ Ledg_ Entry$SUM$Amount (LCY)\",@3) AS \"Balance Due (LCY)\"\n     , ISNULL(\"SUB$Sales (LCY)\".\"Sales (LCY)$Cust_ Ledger Entry$SUM$Sales (LCY)\",@3) AS \"Sales (LCY)\"\n  FROM dbo.\"MSFT$Customer\" AS \"Customer\"\n\n -- SIFT calculations start here\nOUTER APPLY (\nSELECT TOP (1)\n       ISNULL(SUM(\"Balance (LCY)$Detailed Cust_ Ledg_ Entry\".\"SUM$Amount (LCY)\"),@3) AS \"Balance (LCY)$Detailed Cust_ Ledg_ Entry$SUM$Amount (LCY)\"\nFROM dbo.\"MSFT$Detailed Cust_ Ledg_ Entry$VSIFT$5\" AS \"Balance (LCY)$Detailed Cust_ Ledg_ Entry\"\nWHERE (\"Balance (LCY)$Detailed Cust_ Ledg_ Entry\".\"Customer No_\"=\"Customer\".\"No_\"\nAND ISNULL(\"Balance (LCY)$Detailed Cust_ Ledg_ Entry\".\"Posting Date\",@8)>=@12\nAND ISNULL(\"Balance (LCY)$Detailed Cust_ Ledg_ Entry\".\"Posting Date\",@8)<=@13)\n) AS \"SUB$Balance (LCY)\"\n\nOUTER APPLY (\nSELECT TOP (1)\n       ISNULL(SUM(\"Balance Due (LCY)$Detailed Cust_ Ledg_ Entry\".\"SUM$Amount (LCY)\"),@3) AS \"Balance Due (LCY)$Detailed Cust_ Ledg_ Entry$SUM$Amount (LCY)\"\nFROM dbo.\"MSFT$Detailed Cust_ Ledg_ Entry$VSIFT$5\" AS \"Balance Due (LCY)$Detailed Cust_ Ledg_ Entry\"\nWHERE (\"Balance Due (LCY)$Detailed Cust_ Ledg_ Entry\".\"Customer No_\"=\"Customer\".\"No_\"\nAND ISNULL(\"Balance Due (LCY)$Detailed Cust_ Ledg_ Entry\".\"Posting Date\",@8)<=@14\nAND ISNULL(\"Balance Due (LCY)$Detailed Cust_ Ledg_ Entry\".\"Initial Entry Due Date\",@8)>=@15\nAND ISNULL(\"Balance Due (LCY)$Detailed Cust_ Ledg_ Entry\".\"Initial Entry Due Date\",@8)<=@16)\n) AS \"SUB$Balance Due (LCY)\"\n\nOUTER APPLY (\nSELECT TOP (1)\n       ISNULL(SUM(\"Sales (LCY)$Cust_ Ledger Entry\".\"SUM$Sales (LCY)\"),@3) AS \"Sales (LCY)$Cust_ Ledger Entry$SUM$Sales (LCY)\"\nFROM dbo.\"MSFT$Cust_ Ledger Entry$VSIFT$1\" AS \"Sales (LCY)$Cust_ Ledger Entry\"\nWHERE (\"Sales (LCY)$Cust_ Ledger Entry\".\"Customer No_\"=\"Customer\".\"No_\"\nAND ISNULL(\"Sales (LCY)$Cust_ Ledger Entry\".\"Posting Date\",@8)>=@17\nAND ISNULL(\"Sales (LCY)$Cust_ Ledger Entry\".\"Posting Date\",@8)<=@18)\n) AS \"SUB$Sales (LCY)\"\n\n WHERE (ISNULL(\"Customer\".\"No_\",@1)>@19)\n ORDER BY \"No_\" ASC\n```\nIn the SQL query, each section that starts with the keyword OUTER APPLY is responsible for a FlowField calculation, and the SmartSQL optimization adds this to the SQL query as an outer join. For each FlowField in the table, an OUTER APPLY clause is added to the SQL statement.\n## How to isolate and test FlowField queries\nIf you want to see the cost of each of these subqueries, you can disable the SmartSQL optimization. To do this, run the Business Central Server Administration tool, and select the Disable SmartSQL check box in the Database section.\nNow, when loading the page, each FlowField calculation is performed as a separate SQL statement, which can be found either in an SQL trace or by using the Query Store feature in SQL Server 2016 (or later).\nOnce the slow subquery has been identified, you can create an index to improve its performance (or enable the MaintainSIFTIndex property of the key, if it is disabled).\nAs you can see, poor performance might not be caused by the SmartSQL optimization. However, the fact that SmartSQL queries are not cached will only amplify the issue. It won't help to customize the page or change the visibility of the field either. If a FlowField is contained in the metadata of the page, it will be calculated.\n## Related information\nBusiness Central Server Administration Tool<administration-tool>\nhttps://learn.microsoft.com/sql/tools/sql-server-profiler/sql-server-profiler\nTroubleshooting: Using Query Store to Monitor Query Performance in Business Central<troubleshoot-query-performance-using-query-store>\nhttps://learn.microsoft.com/sql/relational-databases/sql-trace/sql-trace"}