Problems displaying this newsletter? View online.
Database Weekly
The Complete Weekly Roundup of SQL Server News
Hand-picked content to sharpen your professional edge
Editorial
 

Controlling Intelligent Query Processing Features

I always look forward to new T-SQL features and optimizer enhancements with every new version of SQL Server. Starting in 2017, Microsoft came up with a set of features called Intelligent Query Processing (IQP). These features work to improve performance without changing any code. If you’d like to learn more about these features, take a look at Microsoft’s page on the topic. There are also several articles on Simple Talk by Greg Larsen on the features.

These features improve the performance of some typical patterns; for example, one feature is inlined scalar user-defined functions (UDFs) available in 2019. Depending on the situation, this can lead to a significant performance boost without changing any code. Say you have a function that accepts a couple of parameters and then runs a query to return a sum. As long as the function meets the criteria for inlining, SQL Server treats it as if you included your code in the query instead of using a function. Some folks don’t realize that the query using a UDF in the SELECT list calls the UDF once for every row. Just think about the impact if the query inside the UDF happens to do a scan on a large table!

Just like any new feature, you must do some testing to see if it helps or causes unanticipated problems. All the IQP features can be toggled off and on by changing the database compatibility level. If you turn it below 150 (SQL Server 2019), you disable all the 2019 IQP features. If you wish to disable just one of the features, set the compatibility to 150 and then flip the switch for the database for that particular feature. Here's the command to turn off UDF inlining:

ALTER DATABASE SCOPED CONFIGURATION SET TSQL_SCALAR_UDF_INLINING = OFF;

But what if you need this feature except that you have one UDF that causes issues when inlining is turned on? For example, UDFs use deferred resolution. That means that an object doesn’t have to exist at function creation time. In a case like this, inlining the UDF could cause an error.

Here’s a simple example:

CREATE OR ALTER FUNCTION dbo.SwitchTable()
RETURNS INT AS
BEGIN
    DECLARE @Count INT;
    IF OBJECT_ID('testTable','U') IS NOT NULL BEGIN
        SELECT @Count = COUNT(*)
        FROM testTable;
    END
    ELSE BEGIN
        SELECT @Count = COUNT(*)
        FROM Production.Product;
    END
    RETURN @Count;
END;
GO
SELECT ProductID, Name, dbo.switchTable() AS productCount
FROM Production.Product;

When you run the query with scalar UDF inlining enabled, you’ll see this error if testTable doesn’t exist:

Msg 208, Level 16, State 1, Procedure SwitchTable, Line 7 [Batch Start Line 21] Invalid object name 'testTable'.

To get around this while still allowing the feature to be used for other scalar UDFs, add this hint to the query:

SELECT ProductID, Name, dbo.switchTable() AS productCount
FROM Production.Product
OPTION (USE HINT('DISABLE_TSQL_SCALAR_UDF_INLINING'));

The team at Microsoft is doing some great things with SQL Server! If you use a lot of scalar UDFs, an upgrade to 2019 with scalar UDF inlining could solve some of your issues, and you have control over when to use it.

Kathi Kellenberger

Join the debate, and respond to the editorial on the forums

 
The Weekly News
All the headlines and interesting SQL Server information that we've collected over the past week, and sometimes even a few repeats if we think they fit.
Vendors/3rd Party Products

SQL Prompt Snippets to Drop Columns and Tables and Handle Associated Dependencies

Louis Davidson provides a pair of SQL Prompt snippets that will help you deal with dependencies, whenever you need to drop columns or tables.

Handling System-named Constraints in SQL Compare

If some of your database constraints have system-generated names, they can cause 'false positives' when comparing schemas and generating build scripts using SQL Compare or SQL Change Automation. Phil Factor explains the difficulties, and the Compare option you need to enable to avoid them.

Using SQL Source Control projects in Azure Data Studio

David Atkinson describes how developers who were previously writing and managing SQL source code in SSMS can make a smooth transition to Azure Data Studio.

Take our short readers’ survey and win a $50 Amazon voucher

Could you spare 3 minutes to help us out at SQL Server Central? Take this short survey, tell us about who you are and why you come to SQL Server Central, and you could win a $50 Amazon voucher.

.NET Related Articles

How to Create a Settings Menu in Unity

Video game enthusiasts expect that they can make changes to the game’s environment and that the setting changes will be saved. In this article, Lance Talbert shows how it can be done in Unity.

Administration

Processing partitions \ tables in parallel

One thing that has come up several times in the last few weeks is a misconception that you cannot process multiple partitions on the same table or tables in parallel as it would cause a lock.

Updated First Responder Kit and Consultant Toolkit for July 2020

This month, 15 community folks contributed code – I think that’s an all-time high for a single month’s release! Good work, y’all. Thanks for payin’ it forward. The bad...

SQL Server Assessment Using SSMS and SSRS

Over the years I have been asked to complete asses...

Extended Events Capturing the T-SQL of Prepared Statements

I asked this question myself: Is there a way to use Extended Events to capture the T-SQL of a prepared statement? Why would I be concerned with prepared statements?...

Creating Maintenance Plans in SQL Server

Total: 2 Average: 5Maintenance plans in SQL Server give us an easy way to organize, configure, and schedule tasks that ensure that the database engine and the databases that...

Azure CosmosDB

Migrating from CosmosDB to SQL Server

Let’s be honest here, Microsoft doesn’t want you to read this.

Backup and Recovery

Backup On-Premise SQL Server to Azure BLOB Storage

SQL Server has given us the option to backup our databases directly to Azure BLOB storage for a while now but it’s not something that I’ve had all that... The...

Career Growth and Certifications

Azure Data Engineer Associate

You can read about all the new role based qualifications from Microsoft

Computing in the Cloud (Azure, Google, AWS)

Running SQL Server in Google Cloud Platform

On a few occasions I’ve referred to GCP (Google ...

More ADLS Gen2 enhancements

On the heels of More Azure Blob Storage enhancemen...

The Myth of “The Cloud is Cheaper”

Click to learn more about author Chris Lynch. As we have all experienced recently, change is the only constant that continues to be true, decade in and decade out....

Conferences, Classes, Events, and Webinars

Database DevOps for Managed Service Providers

In this webinar discover how Database DevOps and Octopus Deploy enable your organization to increase efficiency, reduce errors and get the most from your customer infrastructures. Date and time: Wednesday July 15 & Friday July 17. Can't join us live? register to receive the recording.

Database Design, Theory and Development

When to allow NULLs

Some years ago I did a post on NULLs where I detailed some of the issues you can get with them.

DevOps and Continuous Delivery (CI/CD)

Getting Started with GitFlow

In this article, Diogo Souza explains GitFlow, a branching model for Git. He demonstrates how to work with GitFlow to create and deploy a feature and a hotfix to GitHub.

The Manager’s Guide to Git Training for Database Administrators

Teams implementing DevOps often encounter a significant obstacle: database folks are not all used to working with Version Control Systems (VCS). It’s important to overcome this obstacle because a...

What’s the difference between blue/green and red/black deployments?

When deploying new versions of a centralized application like a web service, there’s a strategy you can use to direct production traffic to the new version only after it...

ETL/SSIS/Azure Data Factory/Biml

Nesting ForEach Activities in Azure Data Factory

Near the end of June 2020, I delivered a free Enterprise Data & Analytics Summer o’ ADF webinar titled Using the Azure Data Factory ForEach Activity. My friend Meagan...

HA/DR/Always On/Clustering

Configure Kerberos for Availability Groups

When you start learning about SQL Server security, the first thing you read is that SQL Server (on Windows) can use either SQL Server Authentication

Performance Tuning SQL Server

What is MaxDOP controlling?

Max Degree of Parallelism, or MAXDOP, is one of the most known settings in the SQL Database Engine.

How MAXDOP Really Works

A few days ago I ran a Twitter poll:

The 201 Buckets Problem, Part 1: Why You Still Don’t Get Accurate Estimates

I’ll start with the smallest Stack Overflow 2010...

Fundamentals of table expressions, Part 4 – Derived tables, optimization considerations, continued

Continuing his series on table expressions in SQL Server, Itzik Ben-Gan discusses more considerations for performance and efficiency. The post Fundamentals of table expressions, Part 4 – Derived tables, optimization...

PowerPivot/PowerQuery/PowerBI

Why Is Power BI Running My SQL Query Twice?

When you import data from a relational database like SQL Server in Power BI you have the option of entering your own SQL query to use as a starting...

Power BI community posts… (Roundup | July 6, 2020)

Thanks for watching this week's Power BI news roun...

Professional Development

New Training for Your Team on Redgate University: Learn DevOps and SQL Server for Free

I’m excited to give you a run down of fresh new online training, open to all on Redgate University. We’ve got a great mix of courses on how to...

The Ironic DBA—My First Year as a DBA [Part 2]

Welcome to part 2 of my series reviewing my first year as a DBA. If you missed the first post, you can read it here. Moar Training! Reflecting back...

Don’t be afraid of No

How many times have you been afraid to hear “No”? We have all been there because we have been trained over the years to perceive “No” as a rejection,... The...

Python

How to delay a Python loop

In this blog post, I will run through 3 different ways to execute a delayed Python loop. In these examples, we will aim to run the loop once every...

Reporting Services

SSRS: Action setting To a URL or Report

Over the years I have created a number of SQL Serv...

SQL Server Security and Auditing

Encrypting Stored Procedures Doesn’t Make Me Avoid Looking at Your Code

Dear Vendors that encrypt stored procedures in SQL Server, Stop It! We were having a discussion on Twitter about vendors encrypting stored procedures recently, and this justification came up...

The Fundamentals of Data Anonymization and Protection

Click to learn more about author David Balaban. Data anonymization is a process aimed at eliminating personally identifiable clues so that it’s impracticable, or at least very challenging, to...

T-SQL

Dropping temporary tables

Local temporary tables – tables with names that begin with a single # character – are dropped automatically by SQL Server when they are no longer in scope.

Fundamentals of table expressions, Part 4 – Derived tables, optimization considerations, continued

This article is the fourth part in a series on table expressions. In Part 1 and Part 2 I covered the conceptual treatment of derived tables.

Tracking use of Deprecated SQL Server Features

Phil Factor explains how to use SQL Prompt, or SQL Change Automation, to detect use of deprecated SQL Server syntax, during development, and Dynamic Management Views and Extended Events...

Fun with VALUES

There’s more to the VALUES clause in T-SQL than meets the eye.

Ambiguous column name error when only using one Table

Every once in a while I see something in SQL Serve...

Three Ways to Create a Temp Table

Taking it back to SQL 101 today because I recently...

Fun with VALUES

There’s more to the VALUES clause in T-SQL than meets the eye. We’ve all used the most basic INSERT syntax: But did you know that you can create multiple...

More Local Variable Nonsense: TOP

Number One In case you missed it for some reason, check out this post of mine about local variables. Though it’s hard to imagine how you missed it, since it’s...

Getting the Proc Code–#SQLNewBlogger

Another post for me that is simple and hopefully s...

SQL Server JSON Diff. Checking for differences between JSON documents.

If you are working on any module or routine such as a procedure, function or batch that produces a result, then you will want to compare it with something...

Virtualization and Containers/Kubernetes

Using Docker Volumes for SQL Server in Linux

No, not that kind of volume! Over the past couple ...

 
RSS FeedTwitter
This email has been sent to {email}. To be removed from this list, please click here. If you have any problems leaving the list, please contact the webmaster@sqlservercentral.com. This newsletter was sent to you because you signed up at SQLServerCentral.com. Note: This is not the SQLServerCentral.com daily newsletter list, and unsubscribing to this newsletter will not stop you receiving the SQL Server Central daily newsletters. If you want to be removed from that list, you can follow the instructions on the daily newsletter.
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
webmaster@sqlservercentral.com

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -