SlideShare a Scribd company logo
Performance Impacts of
User Defined Functions
Introduction
Jason                     e: jstrate@pragmaticworks.com
Strate
                          e: jasonstrate@gmail.com
                          b: www.jasonstrate.com
                          t: StrateSQL
Resources                 jasonstrate.com/go/Waits




 MAKING BUSINESS INTELLIGENT
                                                      www.pragmaticworks.com
Functions




            http://www.flickr.com/photos/protocol/3244887521/
What Functions?
    To use functions or not to use
• User Defined Functions
       functions, that’s today’s
              question.
  – Scalar
  – Inline
     • Aka Table-Valued
  – Multi-statement
     • Aka Table-Valued

          CLR Functions
          Out of Scope

                                     http://www.flickr.com/photos/mshades/3154733910/
Goals
1. Identify purposes for creating User-Defined
   Functions
2. Discuss the types of User-Defined Functions
3. Demonstrate performance impact in selecting
   different types of functions
Session Warranty
• Not a deep dive
  – Inform those that don’t know
  – Arm those that do know


• Not included
  – Secret sauce
  – Pixie dust
  – Bacon

                                   http://www.flickr.com/photos/shawnzam/31302636/
A Function is a Function
• Benefits
  – Consolidation
  – Modularization
  – Maintenance
  – Reuse


• Performance
  – Looking at impact versus gain

                                    http://www.flickr.com/photos/vincentsl/3543888150/
A Function is a Function

               Scalar




              Functions


    Multi-
  statement               Inline
A Function is a Function

               Scalar




              Functions


    Multi-
  statement               Inline
Scalar Functions


                      Body
Parameter(s)                      Value
                   Statement(s)
Scalar Functions
• Function
  – Single or multiple statement(s)
  – Returns single value
• Usage
  – SELECT, WHERE, ORDER BY
  – CHECK Constraints
  – Computed columns
Scalar Functions
• Cursor like behavior
  – Linear performance effect
• Data Access
• Executes on
  – SELECT
  – WHERE
  – ORDER BY


                                http://www.flickr.com/photos/blockpartypress/2625954377/
Scalar Demo



Demo 001 – Scalar Functions
Scalar Performance
         Basic Function -                  Basic Function - CPU             Basic Function –
            Duration               9,000                                           IO
12,000                                                             10,000
                                   8,000
                                                                    9,000

10,000                             7,000
                                                                    8,000

                                   6,000                            7,000
 8,000

                                   5,000                            6,000


 6,000                                                              5,000
                                   4,000

                                                                    4,000
                                   3,000
 4,000
                                                                    3,000

                                   2,000
                                                                    2,000
 2,000
                                   1,000
                                                                    1,000


    -                                 -                                -




             Native   Scalar                     Native   Scalar                Native   Scalar
Scalar Performance
          Data Access -                               Data Access-                                  Data Access -
            Duration                                      CPU                                            IO
300                                         250                                         40000



                                                                                        35000
250
                                            200
                                                                                        30000

200
                                                                                        25000
                                            150


150                                                                                     20000


                                            100
                                                                                        15000
100

                                                                                        10000
                                            50
50
                                                                                         5000



 0                                           0                                              0
      1    10        100     1000   10000         1    10        100     1000   10000           1     10       100      1000   10000

            Native         Scalar                       Native         Scalar                         Native         Scalar
A Function is a Function

               Scalar




              Functions


    Multi-
  statement               Inline
Inline Functions



                     Body -
Parameter(s)                      Table
                   Statement
Inline Functions
• Returns table parameter
  – Columns defined in RETURN statement
• Parameterized View
• DML Operations allowed
  – INSERT
  – UPDATE
  – DELETE
• Query-able results
Inline Functions
• Limitations
  – Simple operations
  – Duplication of access
Joining Functions
• APPLY
  – CROSS = INNER
  – OUTER = LEFT OUTER
• Pass in columns as parameters
  – Replaces ON clause
Inline Demo



Demo 002 – Inline Functions
Inline Performance
        Basic Function - Duration               Basic Function –                    Basic Function –
12,000                                                CPU                                  IO
                                        9,000                              10,000


10,000                                  8,000                               9,000


                                                                            8,000
                                        7,000

 8,000                                                                      7,000
                                        6,000

                                                                            6,000
                                        5,000
 6,000
                                                                            5,000
                                        4,000
                                                                            4,000
 4,000
                                        3,000
                                                                            3,000

                                        2,000
                                                                            2,000
 2,000

                                        1,000                               1,000


    -                                      -                                   -




             Native   Scalar   Inline           Native   Scalar   Inline            Native   Scalar   Inline
Inline Performance
           Data Access -                              Data Access-                                 Data Access -
             Duration                                     CPU                                           IO
300                                        250                                        40000



                                                                                      35000
250
                                           200
                                                                                      30000

200
                                                                                      25000
                                           150


150                                                                                   20000


                                           100
                                                                                      15000
100

                                                                                      10000
                                           50
50
                                                                                       5000



 0                                          0                                             0
      1       10   100      1000   10000         1       10   100      1000   10000           1            10    100     1000    10000

          Native   Scalar      Inline                Native   Scalar      Inline                  Native        Scalar      Inline
A Function is a Function

               Scalar




              Functions


    Multi-
  statement               Inline
Multi-Statement Performance



Parameter(s)   Function           Table



                     Didn’t we
                    already see
                       this?!?
Multi-Statement Performance
• Returns table parameter
   – Columns defined in DDL
• Flexibility of Scalar function
• Flexibility of Inline function
• Query-able results
Multi-Statement Demo



Demo 003 – Multi-Statement Functions
Multi-Statement Performance
             Basic Function -                       Basic Function - CPU                            Basic Function –
                Duration                    9,000                                                          IO
12,000                                                                                 10,000
                                            8,000
                                                                                        9,000

10,000                                      7,000
                                                                                        8,000

                                            6,000                                       7,000
 8,000

                                            5,000                                       6,000


 6,000                                                                                  5,000
                                            4,000

                                                                                        4,000
                                            3,000
 4,000
                                                                                        3,000

                                            2,000
                                                                                        2,000
 2,000
                                            1,000
                                                                                        1,000


    -                                          -                                           -




         Native   Scalar   Inline   Multi           Native   Scalar   Inline   Multi            Native   Scalar   Inline   Multi
Multi-Statement Performance
                Data Access -                                       Data Access-                                         Data Access -
                  Duration                                              CPU                                                   IO
1200                                                1000                                               140000

                                                     900
                                                                                                       120000
1000
                                                     800

                                                     700                                               100000
800

                                                     600
                                                                                                       80000

600                                                  500

                                                                                                       60000
                                                     400
400
                                                     300                                               40000

                                                     200
200
                                                                                                       20000
                                                     100

  0                                                    0                                                    0
         1        10        100      1000   10000            1       10        100      1000   10000                1      10        100       1000   10000

       Native      Scalar         Inline    Multi          Native     Scalar         Inline    Multi            Native      Scalar         Inline     Multi
Summary
• Performance is important
  – Other factors can be just as important
• Know the limitations
• Functions have a place
Resources
• http://msdn.microsoft.com/en-us/library/ms189294.aspx
• http://www.sqlteam.com/article/intro-to-user-defined-
  functions-updated
• http://www.amazon.com/Transact-SQL-User-Defined-
  Functions/dp/1556220790/ref=sr_1_1?ie=UTF8&s=books&qi
  d=1268026139&sr=8-1
For more information…
                                          Name: Jason Strate

                                          Email: jstrate@pragmaticworks.com

                                          Blog: www.jasonstrate.com

                                          Resource: jasonstrate.com/go/functions




          Products                                   Services                                 Foundation
BI products to covert to a Microsoft BI    Speed development through training, and   Helping those who do not have the
platform and simplify development on       rapid development services from           means to get into information technology
the platform.                              Pragmatic Works.                          achieve their dreams.

More Related Content

Viewers also liked (18)

PPTX
Presentacion indefinida
kishito01
 
PPTX
Relaciones interpersonales
Maria Angelica Diaz Acosta
 
PDF
5 Amazing Reasons DBAs Need to Love Extended Events
Jason Strate
 
PPS
Leillusiondi octavioocampo
Mohd Javed
 
PDF
What are you waiting for? (#SQLSat211)
Jason Strate
 
PDF
Discovering the plan cache (sql sat175)
Jason Strate
 
PDF
Introduction to Clustered Indexes and Heaps
Jason Strate
 
PDF
5 ways to improve performance through indexing
Jason Strate
 
PDF
Leveraging Cloud for the Modern SQL Developer
Jason Strate
 
PPTX
Materiales electricos
kishito01
 
PDF
BuildingSecurity Audits with Extended Events
Jason Strate
 
PDF
Introduction to SQL Server Security
Jason Strate
 
PDF
The Flavors of Non-Clustered Indexes
Jason Strate
 
PPTX
Language learning strategies
812100
 
PDF
Strategies for SQL Server Index Analysis
Jason Strate
 
PDF
Introduction to Columnstore Indexes
Jason Strate
 
PPT
Visualising solid shapes!!!
Saleema Rocx
 
PPTX
Accelerating Business Intelligence Solutions with Microsoft Azure pass
Jason Strate
 
Presentacion indefinida
kishito01
 
Relaciones interpersonales
Maria Angelica Diaz Acosta
 
5 Amazing Reasons DBAs Need to Love Extended Events
Jason Strate
 
Leillusiondi octavioocampo
Mohd Javed
 
What are you waiting for? (#SQLSat211)
Jason Strate
 
Discovering the plan cache (sql sat175)
Jason Strate
 
Introduction to Clustered Indexes and Heaps
Jason Strate
 
5 ways to improve performance through indexing
Jason Strate
 
Leveraging Cloud for the Modern SQL Developer
Jason Strate
 
Materiales electricos
kishito01
 
BuildingSecurity Audits with Extended Events
Jason Strate
 
Introduction to SQL Server Security
Jason Strate
 
The Flavors of Non-Clustered Indexes
Jason Strate
 
Language learning strategies
812100
 
Strategies for SQL Server Index Analysis
Jason Strate
 
Introduction to Columnstore Indexes
Jason Strate
 
Visualising solid shapes!!!
Saleema Rocx
 
Accelerating Business Intelligence Solutions with Microsoft Azure pass
Jason Strate
 

Similar to A Function by Any Other Name is a Function (20)

PPSX
Analisis time series
XYZ Williams
 
PDF
TransCanada Corporation - Annual Report - 2012
TransCanada Corporation
 
PPTX
Top Application Performance Landmines
Andreas Grabner
 
PDF
Apstartup crowdfunding ver1
AP DealFlow
 
PDF
CAD integrated automatic DFM analysis
bhaskars
 
PDF
Spot Count Differences
ikoppandi
 
PDF
Key Marketing Metrics Dashboard
Demand Metric
 
PDF
Utah Adult Education Report Card (2008-2009)
State of Utah, Salt Lake City
 
PDF
Payu Pitch Deck
ammarjiwaji
 
KEY
slide
koh-t
 
PPT
Walking through a library remotely. Digital Humanities seminar April 12, 2013...
Andrea Scharnhorst
 
XLSX
Cases and places 2
guevarra_2000
 
XLSX
Cases and places 2
guevarra_2000
 
XLSX
Cases and places 2
guevarra_2000
 
PDF
Quepasa Corporation (NYSE Amex: QPSA) Q1 2012 Financial Results
MeetMe, Inc
 
PDF
모바일Bm 대한상공회의소 Mac
Kim jeehyun
 
PPT
Millionaire Chapter 1 OMaM
James Chubb
 
PPTX
ASP.NET Best Practices
Harish Ranganathan
 
Analisis time series
XYZ Williams
 
TransCanada Corporation - Annual Report - 2012
TransCanada Corporation
 
Top Application Performance Landmines
Andreas Grabner
 
Apstartup crowdfunding ver1
AP DealFlow
 
CAD integrated automatic DFM analysis
bhaskars
 
Spot Count Differences
ikoppandi
 
Key Marketing Metrics Dashboard
Demand Metric
 
Utah Adult Education Report Card (2008-2009)
State of Utah, Salt Lake City
 
Payu Pitch Deck
ammarjiwaji
 
slide
koh-t
 
Walking through a library remotely. Digital Humanities seminar April 12, 2013...
Andrea Scharnhorst
 
Cases and places 2
guevarra_2000
 
Cases and places 2
guevarra_2000
 
Cases and places 2
guevarra_2000
 
Quepasa Corporation (NYSE Amex: QPSA) Q1 2012 Financial Results
MeetMe, Inc
 
모바일Bm 대한상공회의소 Mac
Kim jeehyun
 
Millionaire Chapter 1 OMaM
James Chubb
 
ASP.NET Best Practices
Harish Ranganathan
 
Ad

More from Jason Strate (10)

PPTX
The Plan Cache Whisperer - Performance Tuning SQL Server
Jason Strate
 
PDF
Getting Started with Windows Azure and SQL Databases
Jason Strate
 
PDF
5 SQL Server Indexing Myths
Jason Strate
 
PDF
Necessary Evils, Building Optimized CRUD Procedures
Jason Strate
 
PDF
How Do Non-Clustered Indexes Improve Performance?
Jason Strate
 
PDF
Choosing Your Clustered Index
Jason Strate
 
PPTX
The Side Effect of NOLOCK
Jason Strate
 
PDF
Discovering the plan cache (#SQLSat211)
Jason Strate
 
PDF
Discovering the Plan Cache (#SQLSat 206)
Jason Strate
 
PDF
What are you waiting for
Jason Strate
 
The Plan Cache Whisperer - Performance Tuning SQL Server
Jason Strate
 
Getting Started with Windows Azure and SQL Databases
Jason Strate
 
5 SQL Server Indexing Myths
Jason Strate
 
Necessary Evils, Building Optimized CRUD Procedures
Jason Strate
 
How Do Non-Clustered Indexes Improve Performance?
Jason Strate
 
Choosing Your Clustered Index
Jason Strate
 
The Side Effect of NOLOCK
Jason Strate
 
Discovering the plan cache (#SQLSat211)
Jason Strate
 
Discovering the Plan Cache (#SQLSat 206)
Jason Strate
 
What are you waiting for
Jason Strate
 
Ad

Recently uploaded (20)

PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PPTX
Simplifying End-to-End Apache CloudStack Deployment with a Web-Based Automati...
ShapeBlue
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PDF
How Current Advanced Cyber Threats Transform Business Operation
Eryk Budi Pratama
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Upgrading to z_OS V2R4 Part 01 of 02.pdf
Flavio787771
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Are there government-backed agri-software initiatives in Limerick.pdf
giselawagner2
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
Upskill to Agentic Automation 2025 - Kickoff Meeting
DianaGray10
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Simplifying End-to-End Apache CloudStack Deployment with a Web-Based Automati...
ShapeBlue
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
How Current Advanced Cyber Threats Transform Business Operation
Eryk Budi Pratama
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Upgrading to z_OS V2R4 Part 01 of 02.pdf
Flavio787771
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Are there government-backed agri-software initiatives in Limerick.pdf
giselawagner2
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Upskill to Agentic Automation 2025 - Kickoff Meeting
DianaGray10
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 

A Function by Any Other Name is a Function

  • 1. Performance Impacts of User Defined Functions
  • 2. Introduction Jason e: [email protected] Strate e: [email protected] b: www.jasonstrate.com t: StrateSQL Resources jasonstrate.com/go/Waits MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  • 3. Functions http://www.flickr.com/photos/protocol/3244887521/
  • 4. What Functions? To use functions or not to use • User Defined Functions functions, that’s today’s question. – Scalar – Inline • Aka Table-Valued – Multi-statement • Aka Table-Valued CLR Functions Out of Scope http://www.flickr.com/photos/mshades/3154733910/
  • 5. Goals 1. Identify purposes for creating User-Defined Functions 2. Discuss the types of User-Defined Functions 3. Demonstrate performance impact in selecting different types of functions
  • 6. Session Warranty • Not a deep dive – Inform those that don’t know – Arm those that do know • Not included – Secret sauce – Pixie dust – Bacon http://www.flickr.com/photos/shawnzam/31302636/
  • 7. A Function is a Function • Benefits – Consolidation – Modularization – Maintenance – Reuse • Performance – Looking at impact versus gain http://www.flickr.com/photos/vincentsl/3543888150/
  • 8. A Function is a Function Scalar Functions Multi- statement Inline
  • 9. A Function is a Function Scalar Functions Multi- statement Inline
  • 10. Scalar Functions Body Parameter(s) Value Statement(s)
  • 11. Scalar Functions • Function – Single or multiple statement(s) – Returns single value • Usage – SELECT, WHERE, ORDER BY – CHECK Constraints – Computed columns
  • 12. Scalar Functions • Cursor like behavior – Linear performance effect • Data Access • Executes on – SELECT – WHERE – ORDER BY http://www.flickr.com/photos/blockpartypress/2625954377/
  • 13. Scalar Demo Demo 001 – Scalar Functions
  • 14. Scalar Performance Basic Function - Basic Function - CPU Basic Function – Duration 9,000 IO 12,000 10,000 8,000 9,000 10,000 7,000 8,000 6,000 7,000 8,000 5,000 6,000 6,000 5,000 4,000 4,000 3,000 4,000 3,000 2,000 2,000 2,000 1,000 1,000 - - - Native Scalar Native Scalar Native Scalar
  • 15. Scalar Performance Data Access - Data Access- Data Access - Duration CPU IO 300 250 40000 35000 250 200 30000 200 25000 150 150 20000 100 15000 100 10000 50 50 5000 0 0 0 1 10 100 1000 10000 1 10 100 1000 10000 1 10 100 1000 10000 Native Scalar Native Scalar Native Scalar
  • 16. A Function is a Function Scalar Functions Multi- statement Inline
  • 17. Inline Functions Body - Parameter(s) Table Statement
  • 18. Inline Functions • Returns table parameter – Columns defined in RETURN statement • Parameterized View • DML Operations allowed – INSERT – UPDATE – DELETE • Query-able results
  • 19. Inline Functions • Limitations – Simple operations – Duplication of access
  • 20. Joining Functions • APPLY – CROSS = INNER – OUTER = LEFT OUTER • Pass in columns as parameters – Replaces ON clause
  • 21. Inline Demo Demo 002 – Inline Functions
  • 22. Inline Performance Basic Function - Duration Basic Function – Basic Function – 12,000 CPU IO 9,000 10,000 10,000 8,000 9,000 8,000 7,000 8,000 7,000 6,000 6,000 5,000 6,000 5,000 4,000 4,000 4,000 3,000 3,000 2,000 2,000 2,000 1,000 1,000 - - - Native Scalar Inline Native Scalar Inline Native Scalar Inline
  • 23. Inline Performance Data Access - Data Access- Data Access - Duration CPU IO 300 250 40000 35000 250 200 30000 200 25000 150 150 20000 100 15000 100 10000 50 50 5000 0 0 0 1 10 100 1000 10000 1 10 100 1000 10000 1 10 100 1000 10000 Native Scalar Inline Native Scalar Inline Native Scalar Inline
  • 24. A Function is a Function Scalar Functions Multi- statement Inline
  • 25. Multi-Statement Performance Parameter(s) Function Table Didn’t we already see this?!?
  • 26. Multi-Statement Performance • Returns table parameter – Columns defined in DDL • Flexibility of Scalar function • Flexibility of Inline function • Query-able results
  • 27. Multi-Statement Demo Demo 003 – Multi-Statement Functions
  • 28. Multi-Statement Performance Basic Function - Basic Function - CPU Basic Function – Duration 9,000 IO 12,000 10,000 8,000 9,000 10,000 7,000 8,000 6,000 7,000 8,000 5,000 6,000 6,000 5,000 4,000 4,000 3,000 4,000 3,000 2,000 2,000 2,000 1,000 1,000 - - - Native Scalar Inline Multi Native Scalar Inline Multi Native Scalar Inline Multi
  • 29. Multi-Statement Performance Data Access - Data Access- Data Access - Duration CPU IO 1200 1000 140000 900 120000 1000 800 700 100000 800 600 80000 600 500 60000 400 400 300 40000 200 200 20000 100 0 0 0 1 10 100 1000 10000 1 10 100 1000 10000 1 10 100 1000 10000 Native Scalar Inline Multi Native Scalar Inline Multi Native Scalar Inline Multi
  • 30. Summary • Performance is important – Other factors can be just as important • Know the limitations • Functions have a place
  • 31. Resources • http://msdn.microsoft.com/en-us/library/ms189294.aspx • http://www.sqlteam.com/article/intro-to-user-defined- functions-updated • http://www.amazon.com/Transact-SQL-User-Defined- Functions/dp/1556220790/ref=sr_1_1?ie=UTF8&s=books&qi d=1268026139&sr=8-1
  • 32. For more information… Name: Jason Strate Email: [email protected] Blog: www.jasonstrate.com Resource: jasonstrate.com/go/functions Products Services Foundation BI products to covert to a Microsoft BI Speed development through training, and Helping those who do not have the platform and simplify development on rapid development services from means to get into information technology the platform. Pragmatic Works. achieve their dreams.