T-SQL Tuesday #159 – Optimizing for the Year

The T-SQL Tuesday #159 invitation comes from Deepthi Goguri who has not one, but two invitation topics. First, what is a favorite SQL Server 2022 or Azure feature? Second, how are we managing to stick with New Year Resolutions? To check out the full invitation, click the T-SQL Tuesday logo.

New SQL Server 2022 Feature

One SQL Server 2022 feature I’m interested in is optimized plan forcing.

For query plans where the compilation time breaks a certain threshold, a replay script for query optimization gets stored in Query Store which can then be used the next time the query runs. This cuts down on time that would otherwise be needed for query compilation.

Query Store must be enabled to take advantage of optimized plan forcing. Assuming it is enabled, optimized plan forcing is on by default for any databases created on SQL Server 2022. If you encounter a scenario where optimized plan forcing is off, the following script can be executed to turn it on:

ALTER DATABASE SCOPED CONFIGURATION 
SET OPTIMIZED_PLAN_FORCING = ON;
GO

If you want to disable OPTIMIZED_PLAN_FORCING, just change ON to OFF:

ALTER DATABASE SCOPED CONFIGURATION 
SET OPTIMIZED_PLAN_FORCING = OFF;
GO

If you’re already on SQL Server 2022, check for this setting as it might be an easy win to better performance. To read more, check out Microsoft’s documentation.

Sticking to Resolutions

I’m not big on New Year’s Resolutions but I do have some goals this quarter that I’m trying to meet when it comes to being more organized with reading. I’ve been pretty consistent when it comes to reading comics, books, or audiobooks. When it comes to technical books (databases, programming, etc.) I’ve had times where I’ve read a bunch and then times when I don’t read at all.

This quarter, I have a plan in place for a handful of technology books. I’m currently reading SQL Server 2022 Query Performance Tuning: Troubleshoot and Optimize Query Performance. My goal is one chapter a day and I have a rule in place that I’m not doing any of this reading on the weekend. I feel like the weekend break will give me time to absorb or review what I read and help against getting burned out.

On the topic of burning out, I’m trying to do this reading in the morning before work rather than in the evening after work. I think we’ve all had times where we’ve signed out for the day and our brains were mush. It’s easier to learn when you’re fresh in the morning and not mentally fatigued from a rough day.

One more tip: if you have trouble getting up early, buy any type of sunrise alarm clock that gradually lights before it’s time to get out of bed and place it across the room. Mine is set for 5:30am but will start lighting up around 5:00am. It was life changing for me and the light makes it much easier than waking up in total darkness.

Thanks for reading!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s