SQL Server 2022 Query Performance Tuning

SQL Server
If you're interested in getting a digital copy, my brand spanking new book is now available here. It's in the intro, but let me tell you a little bit about the new book. It's really new. Some of the older versions of the book were simply updated, a bunch of changes to most chapters, a couple of new chapters, fixes for old mistakes, ta-da, new book. Not this time. This time, I rewrote it all. From scratch. Now, some of the chapter titles are the same. Quite a few of the examples are the same (if code illustrates something successfully, I'm reusing it). However, overall, it's a brand new book. There's a lot of new material too. The last update was for SQL Server 2017. There has (almost) been two…
Read More

Validating Backups: PGSQL Phriday #002

PostgreSQL
It's time again for the another PGSQL Phriday, this time, the question has been asked: How do you do PostgreSQL backups? Honesty up front. I'm very much just beginning my journey of learning PostgreSQL. I've been documenting that learning over here at Simple-Talk (more on the way there), including backups. For this post, I'm not going to tell you about my "experience" maintaining a PostgreSQL backup routine because, well, there isn't any. Instead, I have something else to say about backups that I learned, the hard way I might add, while working in SQL Server, that is 100% applicable to PostgreSQL. Backups Do Not Matter You heard me. In a post that's supposed to be about how you do backups, I'm telling you backups don't matter, and yeah, I'm serious.…
Read More

Getting Help Online

Professional Development
I spend a lot of time in the forums on various web sites, trying to assist people with getting help online. It's shocking how hard they make it. Let's talk about it, just a little. Tell Me the Real Problem One thing you see a lot is that people, for whatever reason, will absolutely not simply state what the actual problem is. You'll get stuff like "What SQL Server internal behavior prevents dynamically naming local variables?" And you're left scratching your head, why on earth would someone want to dynamically name local variables? Only to find out, after lots of comment & discussion, they thought that you needed to rename variables when changing values. When you get stuck, take a moment to describe the problem, but aim for the root…
Read More

Monitor Cardinality Feedback in SQL Server 2022

SQL Server, You Can't Do That In Profiler
It's possible for you to see new technology at work if you use Extended Events to monitor cardinality feedback. To put it simply, cardinality, the number of rows being returned, is estimated by SQL Server. Sometimes, it gets these estimates right. Sometimes, it gets them wrong. New functionality within SQL Server 2022 uses Query Store to see how well those estimates are working. If they're off, the optimizer can actually change plans to get you different behaviors based on this feedback. There's even more than one way to monitor cardinality feedback. Let's talk about it. Extended Events First up, to really see the full set of behaviors in action, we can use Extended Events: CREATE EVENT SESSION [CardinalityFeedback] ON SERVER ADD EVENT sqlserver.query_ce_feedback_telemetry, ADD EVENT sqlserver.query_feedback_analysis, ADD EVENT sqlserver.query_feedback_validation, ADD…
Read More

Query Store at PASS Data Community Summit

SQL Server, T-SQL
While Query Store has been out for quite some time now, released in 2016, there's still quite a lot of missing understanding of what Query Store can do for you, and, how it does it. I've put together a new presentation on the Query Store, "Using Query Store to Understand and Control Query Performance", incorporating the latest stuff from 2022, but still showing you all the goods from 2016, for the PASS Data Community Summit. Why Query Store I've been in love with Query Store since it was released. If you look through my blog, I've been talking about Query Store a lot. I provided a little help to Tracy Boggiano on her book (yes, emphasis on hers, because it is, I just helped), Query Store for SQL Server 2019.…
Read More

Check Every Metric

SQL Server
Recently, a person asked about the costs differences in an execution plan, referencing them as if they were performance measures. The key to understanding performance is to check every metric. When it comes to execution plans, I'm sure I've said this before, so please allow me to repeat myself. The cost numbers shown in an execution plan, which, barring a recompile, will be the same for an execution plan or an execution plan with runtime metrics (aka, estimated and actual plans), are not measures of performance. They do not represent actual metrics. Instead, they are calculations of a theoretical actual performance measurement. So, you can't look at two plans, with two costs, and say, "this plan will perform better." Instead, you can say, "this plan has a lower estimated cost."…
Read More

PGSQL Phriday #001: Two Truths and a Lie

PostgreSQL
As a part of my own journey of learning within PostgreSQL, I've decided that I'm going to take part in PGSQL Phriday as often as I can, just as a way to continue to stretch my knowledge of this platform. Along the way, hopefully, I can help you learn a little too. The topic of this first post is Two Truths and a Lie about PostgreSQL. Now, the lie could easily be that I'm in any way qualified to talk about this topic, however, I can do a little better than that. Let's start off with simple, but important information, backups: Pg_dump can go to either a straight set of SQL, or, to a compressed digital formatPg_dumpall backups can be used to restore over existing databases with dataYou can use…
Read More

DevOps From Redgate

PASS
In a few weeks at the PASS Data Community Summit, I'll be joining several other Redgaters to put on an all-day precon where we take you on a database DevOps journey. Please let me tell you all about it. From Nothing The plan is simple. We're going to take you from a fully manual deployment process, to a fully automated process over the course of the day. We'll be deploying something about every 30 minutes. As the day progresses, those deployments will become more and more automatic. We'll be using a variety of tools, but the big driver will be Redgate's Flyway. The fact is, most people recognize the need for a DevOps-style approach to their database deployments. However, doing it just isn't easy. This all-day seminar is intended to…
Read More

Function Vs. Performance

SQL Server
Recently I was looking through DBA.StackExchange when I saw a pretty simple question that I decided to answer. I went off, set up a test database and some test tables and quickly wrote a query to answer the question. I got it all formatted pretty and was on my way to post it when I saw that another answer was already there. Yeah. Identical to mine. Almost line for line. Well, nuts. I know. I'll write a blog post. The Setup The original poster had two tables that, frankly, are badly designed. However, they share enough data that they are "related" if not relational. Here's the code: CREATE DATABASE Testing; GO USE Testing; GO CREATE TABLE Table_A ( ID INT IDENTITY(1, 1), Score INT ); CREATE TABLE Table_B ( FromPoint…
Read More