Skip to content

Commit 156a078

Browse files
Merge pull request #309829 from silasmendes-ms/synapse-serverless-missing-stats-error-19731
Queries on external tables may not complete due to missing stats
2 parents 13822a2 + 45c1c9f commit 156a078

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

articles/synapse-analytics/known-issues.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ To learn more about Azure Synapse Analytics, see the [Azure Synapse Analytics Ov
3030
|Azure Synapse dedicated SQL pool|[Queries failing with Data Exfiltration Error](#queries-failing-with-data-exfiltration-error)|Has workaround|
3131
|Azure Synapse dedicated SQL pool|[UPDATE STATISTICS statement fails with error: "The provided statistics stream is corrupt."](#update-statistics-failure)|Has workaround|
3232
|Azure Synapse dedicated SQL pool|[Enable TDE gateway timeouts in ARM deployment](#enable-tde-gateway-timeouts-in-arm-deployment)|Has workaround|
33+
|Azure Synapse dedicated SQL pool|[Proxied connections can be affected by Gateway, resulting in connection failures](#proxied-connections-may-result-in-failure-due-to-gateway)|No workaround|
3334
|Azure Synapse serverless SQL pool|[Query failures from serverless SQL pool to Azure Cosmos DB analytical store](#query-failures-from-serverless-sql-pool-to-azure-cosmos-db-analytical-store)|Has workaround|
3435
|Azure Synapse serverless SQL pool|[Azure Cosmos DB analytical store view propagates wrong attributes in the column](#azure-cosmos-db-analytical-store-view-propagates-wrong-attributes-in-the-column)|Has workaround|
3536
|Azure Synapse serverless SQL pool|[Query failures in serverless SQL pools](#query-failures-in-serverless-sql-pools)|Has workaround|
3637
|Azure Synapse serverless SQL pool|[Storage access issues due to authorization header being too long](#storage-access-issues-due-to-authorization-header-being-too-long)|Has workaround|
3738
|Azure Synapse serverless SQL pool|[Querying a view shows unexpected results](#querying-a-view-shows-unexpected-results)|Has workaround|
3839
|Azure Synapse serverless SQL pool|[Queries longer than 7,500 characters may not appear in Log Analytics](#queries-longer-than-7500-characters-may-not-appear-in-log-analytics)|Has workaround|
39-
|Azure Synapse serverless SQL pool|[Proxied connections can be affected by Gateway, resulting in connection failures](#proxied-connections-may-result-in-failure-due-to-gateway)|No workaround|
40+
| Azure Synapse serverless SQL pool | [Queries on external tables may take longer or not complete due to missing statistics](#queries-on-external-tables-may-take-longer-or-not-complete-due-to-missing-statistics) | Has workaround |
4041
|Azure Synapse Workspace|[Blob storage linked service with User Assigned Managed Identity (UAMI) isn't getting listed](#blob-storage-linked-service-with-user-assigned-managed-identity-uami-is-not-getting-listed)|Has workaround|
4142
|Azure Synapse Workspace|[Failed to delete Synapse workspace & Unable to delete virtual network](#failed-to-delete-synapse-workspace--unable-to-delete-virtual-network)|Has workaround|
4243
|Azure Synapse Workspace|[REST API PUT operations or ARM/Bicep templates to update network settings fail](#rest-api-put-operations-or-armbicep-templates-to-update-network-settings-fail)|Has workaround|
@@ -273,6 +274,44 @@ Suggested workarounds are:
273274
- Use the `sys.dm_exec_requests_history` view in your Synapse Serverless SQL pool to access historical query execution details.
274275
- Refactor the query to reduce its length below 7,500 characters, if feasible.
275276

277+
### Queries on external tables may take longer or not complete due to missing statistics
278+
279+
Serverless SQL pool automatically creates statistics for external tables. However, a known issue can prevent statistics from being created for certain columns, which may result in suboptimal query plans and degraded query performance.
280+
281+
**Workaround**
282+
283+
The recommended workaround is the following:
284+
285+
- Run the following diagnostic query in the database hosting the external table to identify columns where `stats_name` or `stats_date` is NULL.
286+
- If statistics are missing, copy the text from the `cmd_create_stats` column and run it in a new session to create the statistics.
287+
- Make sure all relevant tables and columns have statistics and that the statistics are recent. If statistics are outdated, drop and recreate them to help the SQL optimizer generate more efficient query plans.
288+
- Consider implementing an automation to periodically drop and recreate statistics to help maintain consistent query performance.
289+
290+
```sql
291+
SELECT
292+
schema_name(o.schema_id) AS [schema_name],
293+
object_name(o.object_id) AS [table_name],
294+
o.create_date AS [table_date_create],
295+
c.name AS [column_name],
296+
s.name as [stats_name],
297+
STATS_DATE(s.object_id, s.stats_id) AS [stats_date],
298+
'CREATE STATISTICS [' + 'Stats_' + c.name + '] ON [' + schema_name(o.schema_id) + '].[' + object_name(o.object_id) + '] ([' + c.name + ']) WITH FULLSCAN;' AS cmd_create_stats,
299+
'DROP STATISTICS [' + schema_name(o.schema_id) + '].[' + object_name(o.object_id) + '].[' + 'Stats_' + c.name + '];' AS cmd_drop_stats,
300+
'DROP STATISTICS [' + schema_name(o.schema_id) + '].[' + object_name(s.object_id) + '].[' + s.name + '];' AS cmd_drop_existing_stats
301+
FROM sys.objects AS o
302+
INNER JOIN sys.columns AS c
303+
ON o.object_id = c.object_id
304+
LEFT JOIN sys.stats_columns AS sc
305+
ON sc.object_id = c.object_id AND sc.column_id = c.column_id
306+
LEFT JOIN sys.stats AS s
307+
ON s.object_id = sc.object_id AND s.stats_id = sc.stats_id
308+
WHERE o.type = 'U'
309+
ORDER BY [schema_name], [table_name], [column_name];
310+
```
311+
312+
In addition to mitigating this issue, maintaining fresh statistics can improve overall query performance.
313+
314+
276315
## Azure Synapse Apache Spark pool active known issues summary
277316

278317
### Starting a Spark session (with custom python libraries) is taking longer than usual

0 commit comments

Comments
 (0)