High Performance Functions SQLBits VI. Going backwards is faster than going forwards.

Slides:



Advertisements
Similar presentations
Understanding SQL Server Query Execution Plans
Advertisements

Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
SQL Server performance tuning basics
SQL Performance 2011/12 Joe Chang, SolidQ
10 Things Not To Do With SQL SQLBits 7. Some things you shouldn’t do.
Module 7 Designing Queries for Optimal Performance.
The Essentials: DMV’s and T-SQL for the DBA Rocky Mountain Tech Tri-Fecta.
Executing Explain Plans and Explaining Execution Plans Craig Martin 01/20/2011.
Module 8 Improving Performance through Nonclustered Indexes.
T-SQL : Bad Habits to Kick Aaron Bertrand SQL Sentry, Inc.
Module 12: Optimizing Query Performance. Overview Introducing the Query Optimizer Tuning Performance Using SQL Utilities Using an Index to Cover a Query.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Query optimization in relational DBs Leveraging the mathematical formal underpinnings of the relational model.
5/24/01 Leveraging SQL Server 2000 in ColdFusion Applications December 9, 2003 Chris Lomvardias SRA International
Reactive Database Access in Scala with Slick 3
Star Transformations Tony Hasler, UKOUG Birmingham 2012 Tony Hasler, Anvil Computer Services Ltd.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Slide 1 of 19Session 13 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 In this session, you will learn to: Implement stored procedures Implement.
Advanced Tips And Tricks For Power Query
Query Optimization CMPE 226 Database Systems By, Arjun Gangisetty
Meta Data Cardinality Explored CSSQLUG User Group - June 2009.
SQL Triggers, Functions & Stored Procedures Programming Operations.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Execution Plans Detail From Zero to Hero İsmail Adar.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Sponsored by: Professional Association for SQL Server Advanced Reporting Services Slicers.
Session Name Pelin ATICI SQL Premier Field Engineer.
 Independent consultant  Performance Troubleshooting  In-house workshops  Cost-Based Optimizer  Performance By Design  Oracle ACE Director  Member.
IFS180 Intro. to Data Management Chapter 10 - Unions.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
SQL Server Statistics and its relationship with Query Optimizer
Joe Sack, Principal Program Manager, Microsoft
Query Optimization Techniques
MySQL Subquery Source: Dev.MySql.com
SQL Server Query and Index Tuning
Query Tuning without Production Data
UFC #1433 In-Memory tables 2014 vs 2016
T-SQL Coding Techniques Are you playing with fire?
Query Tuning without Production Data
Query Tuning without Production Data
20761A 10: Using Subqueries Module 10   Using Subqueries.
The Key to the Database Engine
SQL Server 2017 has more cool features than just running on Linux
Now where does THAT estimate come from?
Cardinality Estimator 2014/2016
Query Optimization Techniques
Top Tips for Better TSQL Stored Procedures
Steve Hood SimpleSQLServer.com
When query plans go wrong
Hugo Kornelis Now where does THAT estimate come from? The nuts and bolts of cardinality estimation.
The 5 Hidden Performance Gems
Targeting Wait Statistics with Extended Events
SQL Server 2008 for developers
Parameter Sniffing: the Good, the Bad, and the Ugly
Parameter Sniffing: the Good,the Bad, and the Ugly
Parameter Sniffing: the Good, the Bad, and the Ugly
Query Tuning Fundamentals
Diving into Query Execution Plans
Introduction to Execution Plans
From adaptive to intelligent: query processing in SQL Server 2019
Query Optimization Techniques
Performance Tuning for SQL Developers through Execution Plans
Performance Tuning for SQL Developers through Execution Plans
All about Indexes Gail Shaw.
Improving the Performance of Functions
Performance Tuning for SQL Developers through Execution Plans
Performance Tuning for SQL Developers through Execution Plans
Performance Tuning for SQL Developers through Execution Plans
From adaptive to intelligent:
Performance Tuning for SQL Developers through Execution Plans
Presentation transcript:

High Performance Functions SQLBits VI

Going backwards is faster than going forwards

Simon Sabin Independent SQL Server Consultant and Trainer Independent SQL Server Consultant and Trainer Database design and development, Business Intelligence, Performance tuning and troubleshooting Database design and development, Business Intelligence, Performance tuning and troubleshooting SQL Server since 6.5 SQL Server since Blog: Blog: Twitter: simon_sabin Twitter: simon_sabin

Overview TSQL Functions what are they TSQL Functions what are they Why they are evil Why they are evil Solving by going backwards Solving by going backwards Considerations for data access Considerations for data access Is CLR an option Is CLR an option

TSQL Functions Logical solution to ensure code reuse Logical solution to ensure code reuse Introduced in SQL 2000 Introduced in SQL 2000 Three different flavours Three different flavours – Scalar Function – Inline Table Valued Function – Multi Statement Table Value function

Scalar Functions Not visible in execution plans Not visible in execution plans All too visible in profiler All too visible in profiler Issues with Estimates and Statistics Issues with Estimates and Statistics – Results in nested loop joins Performance Performance – The code is interpreted each call Parallelism not possible Parallelism not possible

Solutions Don’t use them in the first place Don’t use them in the first place If you have to then If you have to then Profiler Profiler – Filter by object type UDF Bad estimates Bad estimates – Use query hints HASH / MERGE

Inline Table Valued Functions What are they? What are they? A function that returns a query A function that returns a query A bit like a parameterised view A bit like a parameterised view Query is consumed into the main query Query is consumed into the main query Resolved down to the base functions Resolved down to the base functions

How to? Write a function that returns a TABLE Write a function that returns a TABLE Use whatever parameters you want Use whatever parameters you want Specify you query as the return statement Specify you query as the return statement Using the parameters as required Using the parameters as required In your calling query use a subquery or In your calling query use a subquery or CROSS APPLY/OUTER APPLY CROSS APPLY/OUTER APPLY

Whats great IO included in SET STATISTICS IO IO included in SET STATISTICS IO Additional predicates handled Additional predicates handled Performance near to system functions Performance near to system functions No noise in Profiler No noise in Profiler Parallelism capable Parallelism capable Can return multiple values Can return multiple values

What about CLR Compiled code Compiled code Can be very simple Can be very simple Even simple solutions are quick Even simple solutions are quick Can be complex Can be complex Complex solutions are generally quicker Complex solutions are generally quicker Don’t be afraid Don’t be afraid

Summary Don’t use scalar functions Don’t use scalar functions Convert to inline table valued functions Convert to inline table valued functions Consider using CLR Consider using CLR

Then you’ll be happy

Q&A Now Now – Just ask Later Later –