Azure SQL Database Column Statistics - sql-server

I am having trouble finding documentation regarding column statistics on a Microsoft Azure SQL Server database. I noticed recently that query plans had warnings in SSMS due to missing column statistics. Further investigation revealed that 'Auto Create Statistics' and 'Auto Update Statistics' were turned off for our database.
I understand that with our local SQL databases statistics are important to performance in that they let the query analyzer make educated guesses about the cardinality of results. Are statistics still important in an Azure SQL database? Is there any documentation about best practices here? Are there cases where automatic statistics should be turned off?

There is no difference between statistics in SQL Server and Azure SQL Database. Azure SQL Database is just a manged, and automatically-updated flavor of SQL Server. Here's the doc page: Statistics
Are there cases where automatic statistics should be turned off?
Rare cases. The vast majority of SQL Server databases rely on automatic creation and updates of statistic, perhaps augmented by scheduled index maintence.
Automatic statistics are created when needed, and will be created before the query that needs them can be optimized. Sometimes this can cause an unacceptable delay, so you would set them to create asynchronously, and let the query proceed without them, or rely on a manual process review and create needed indexes and statistics.

Related

Could SSMS shows actual execution plan in Azure Synapse?

I'm studying of Azure Synapse.
In dedicated SQL pool database, 'actual execution plan' of SSMS was disabled.
In serverless pool database, SSMS says 'set statistics is not supported.' in SQL execution.
I forgot of take screenshot. Image of 'disable of actual execution plan' is '4. Run the query by selecting Execute or use the following shortcut: F5.' of this page.
I understood SSMS could only shows plan of SQL, and not shows actual plan and live statistics.
But I still mysterious thing is how Synapse experts make faster SQL in Synapse?
In synapse, they don't use complex SQL(ex. much of outer join SQL)?
If my question is completely misunderstood of Azure Synapse system, please point out me.
Later versions of SQL Server Management Studio (SSMS), v18.x plus do support estimated execution plans for Azure Synapse Analytics dedicated SQL pools so the first thing you should do is check your version and update to the latest one. Here is an example plan from SSMS against a dedicated SQL pool, you can see it's got a Round Robin operator:
In terms of performance, you should generally look to hash partition your large fact tables on a key that gives good distribution and replicate your small dimensions. Use round robin distribution as a starting point or where you find it's appropriate for performance with your workloads. Use EXPLAIN to view text-based estimated execution plans. Visual Actual Execution Plans are not supported for but you can review the performance DMVs like sys.dm_pdw_request_steps:
SELECT *
FROM sys.dm_pdw_request_steps
WHERE request_id = 'QID####'
ORDER BY step_index;
Further details on this listed here.

How to measure the performance of the Azure SQL DB?

I need to measure the SQL Azure DB performance using DTA, is it possible or not, if not what is the workaround to consume a workload file (.trc)??
Database Engine Tuning Advisor does not support Azure SQL Database. It is also not possible to create a trace file from an Azure SQL Database using SQL Server Profiler.
SQL Azure automates the creation of indexes that may improve performance of your workload with a feature named automatic tuning. Automatic Tuning on Azure SQL also drops redundant indexes and uses the best execution plan for queries
Alberto is correct - there are features within SQL Azure which help watch and improve the performance of your database queries automatically in some cases. Profiler trace + DTA are not currently supported in SQL Azure. The DTA (Database Tuning Advisor) feature in SQL Server is very good for taking traces and trying to replay them on a different server to simulate possible index and partitioning changes which could improve your performance. The automatic tuning feature does that for you without having to use DTA today yourself.
https://learn.microsoft.com/en-us/azure/sql-database/sql-database-automatic-tuning
If all you want to do is explore the performance of your database, then you can use the query store in SQL Azure (and SQL Server 2016+) to do this kind of analysis.
https://azure.microsoft.com/en-us/blog/query-store-a-flight-data-recorder-for-your-database/
https://learn.microsoft.com/en-us/sql/relational-databases/performance/monitoring-performance-by-using-the-query-store?view=sql-server-2017
If you have not tried this using a recent release of SQL Server Management Studio(SSMS), then I highly suggest you download this and try it. You can see top N queries by different metrics, plan changes over time, and other metrics which give you faster insight into the performance profile of your database + application.
There is no way to take a .trc file today and examine it in the query store, but you can enable query store in an on-premises SQL Server (2016+) and then record your production workload for awhile to see how it is behaving. Please understand there is an overhead to running with the query store on - usually it is modest, but for highly ad hoc OLTP query workloads you may see larger overhead. There are some knobs to tune this, so please just go through normal due diligence before modifying a production system. If you have problems, turn it back off and re-examine until you have the right settings to help capture the relevant data from your workload to help make tuning decisions.
Hope that helps!
Sincerely,
Conor Cunningham
Architect, SQL

Automatic database indexing

I have a database which is used by a multi-tenant application. In this database workloads are dynamic and change continuously. Therefore I have to allocate a DA to continuously manage the database. But I thought to use an automated service for this task such as Azure SQL Database Advisor - Automatic index management (platform is not important - I am OK with using MS sql server or oracle or other RDBMS).
I want to know how these automated indexes are actually working.Can I replace database administrator with these automatic indexers. I read that whenever a query execution plan is generated it will find out all the useful indexes to execute that query. Then it uses the indexes which really exist and cache some data about indexes which don't exist. If an index data is cached again and again the sql adviser will show that as a recommended index. But I want to know can we relay on this, what about update and insert queries? If I have a table where records are frequently updated, these automated indexing systems will consider that?
Note that Index Advisor is only available in SQL Database (Azure).
In the background Index Advisor is a machine learning algorithm, a relatively simple and quite effective one. It will analyze your workload, see if you would benefit from indexes. If he thinks you would it will show you as a recommendation - if you turn automatic index creation/dropping on it will actually create the index. To understand better how it works take a look at Channel 9. Note that before you apply a recommendation you can have an estimated impact.
Now the algorithm can make mistakes, right? So once the recommendation is applied it can automatically be reverted based on its performance.
Also note that next to Index Advisor you can check the Query Performance Insights that will show the performance of you queries. So this can help your DBA diagnose other, non-index related problems.
But note that Index Advisor will not drop and create for you new indexes every hour, it takes for him a day or two. So if your database's workload is changing very fast then I am not sure any automatic management tool or DBA will react quickly enough for your workload.

Azure Database Query Optimizer using View Indices

SQL Server Enterprise Edition's query optimizer will use indices from a view to increase performance of a query even if the view is not explicitly referenced in the query, if applicable. Question: does Azure Database do the same thing? I know SQL Server Express does not do this, for example. I want to ensure I can still get the performance I need from the query optimizer when doing a sort on a joined table with a few million users (works great on enterprise edition but takes several seconds on express - bottle neck at the sort).
Sometime last year (2012) Microsoft announced that the engine was the same between SQL Server and SQL Azure (now called Windows Azure SQL Database :/). So you will likely get the same behavior. Same performance may be another question. Windows Azure SQL Database is also keeping replicas in place in the event of hardware failure. You get the benefit of the secondary coming online in a fashion that is seamless to you. But, This does have a bit of a performance cost. Also, the SQL running in Windows Azure is running in a shared environment. It is pretty well documented that the performance is not the same as a local dedicated multi-processor machine with fast storage. It is a bit of an unfair comparison multi-user, multi-instance vs. dedicated. For many applications this is fast enough, but not all.

Single User: Turn off locking for Microsoft SQL Server

I'm running an upgrade script against a database hosted in Microsoft SQL Server. It's taking a while. Some of the queries are not worth optimising any further, for various reasons.
I'm the only person using this database: Is there a way that I can tell SQL Server to not bother with transactions/locking?
For instance, on a DELETE ... WHERE, does SQL need to get exclusive locks on the rows it's about to delete? If so, can I tell it not to bother, since this is the only running query?
See SQL Query Performance - Do you feel dirty? (Dirty Reads).
Edit: This is just speculation, but if you are the only connection to the SQL Server, you could get exclusive lock at the table level using WITH (TABLOCKX). You are sacrificing concurrency, but it could get faster.
Turn off Autocommit (aka implicit transactions); you'll need to do a commit() at the end. The log file will grow correspondingly large, be sure you've got enough disk space.
Is tempdb on the same disk?

Resources