MAKE YOUR QUERIES FASTER

Slides:



Advertisements
Similar presentations
Understanding SQL Server Query Execution Plans
Advertisements

Introduction to SQL Tuning Brown Bag Three essential concepts.
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
© Bharati Vidyapeeths Institute of Computer Applications and Management, New Delhi © Bharati Vidyapeeths Institute of Computer Applications and.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Joins and Sub-queries in SQL.
ACS-4902 Ron McFadyen Chapter 15 Algorithms for Query Processing and Optimization.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
AN INTRODUCTION TO EXECUTION PLAN OF QUERIES These slides have been adapted from a presentation originally made by ORACLE. The full set of original slides.
CS 345: Topics in Data Warehousing Tuesday, October 19, 2004.
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Index tuning Performance Tuning. Overview Index An index is a data structure that supports efficient access to data Set of Records index Condition on.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
11-1 Improve response time of interactive programs. Improve batch throughput. To ensure scalability of applications load vs. performance. Reduce system.
October 31,  The RDBMS steps in executing SQL query:  Checks query syntax  Validates query-checks data dictionary; verifies objects referred.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Programming in R SQL in R. Running SQL in R In this session I will show you how to: Run basic SQL commands within R.
Oracle tuning: a tutorial Saikat Chakraborty. Introduction In this session we will try to learn how to write optimized SQL statements in Oracle 8i We.
Indexes and Views Unit 7.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
1 Chapter 13 Parallel SQL. 2 Understanding Parallel SQL Enables a SQL statement to be: – Split into multiple threads – Each thread processed simultaneously.
Chapter 5 Index and Clustering
PeopleSoft Financials Advanced Query Training Financial Information Systems and Reporting Controller’s Division
Dynamicpartnerconnections.com Development for performance Oleksandr Katrusha, Program manager
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Execution Plans Detail From Zero to Hero İsmail Adar.
Module 6: Creating and Maintaining Indexes. Overview Creating Indexes Understanding Index Creation Options Maintaining Indexes Introducing Statistics.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
Introduction to Partitioning in SQL Server
Tuning Transact-SQL Queries
Cleveland SQL Saturday Catch-All or Sometimes Queries
Query Optimization Techniques
Indexes By Adrienne Watt.
CS 540 Database Management Systems
Physical Changes That Don’t Change the Logical Design
Advanced Error Tracking Get to the root issue immediately!
UFC #1433 In-Memory tables 2014 vs 2016
Data Virtualization Tutorial… Semijoin Optimization
SQL INJECTION ATTACKS.
Choosing Access Path The basic methods.
Database Performance Tuning and Query Optimization
Reading Execution Plans Successfully
Purpose, Pitfalls and Performance Implications
Introduction to Execution Plans
Power BI Performance …Tips and Techniques.
Using the Set Operators
5 WAYS TO BYPASS *OR ENSURE* SQL SERVER SECURITY MATT MARTIN
Query Optimization Techniques
Purpose, Pitfalls and Performance Implications
Lecture 12 Lecture 12: Indexing.
Top Tips for Better TSQL Stored Procedures
Execution Plans Demystified
Stop Wasting Time & Resources: Performance Tune Your Jobs
Statistics: What are they and How do I use them
Selected Topics: External Sorting, Join Algorithms, …
SQL Server Query Plans Journeyman and Beyond
Introduction to Execution Plans
Overview of Query Evaluation
Chapter 11 Database Performance Tuning and Query Optimization
Power Query & Database Tuning
Execution plans Eugene
Diving into Query Execution Plans
Introduction to Execution Plans
Query Optimization Techniques
Introduction to Execution Plans
Why should I care about SQL, if I have ORM?
All about Indexes Gail Shaw.
Developing Microsoft SQL Server Databases
Presentation transcript:

MAKE YOUR QUERIES FASTER Optimization Optimization MAKE YOUR QUERIES FASTER MATT MARTIN SQL Saturday Atlanta June 2017

About Enjoy Big Data projects and query tuning 9 years experience MATT MARTIN | CHIEF TECHNOLOGY OFFICER | SQLETL Twitter: @sqletl_matt Website: www.sqletl.com Email: matt@sqletl.com 9 years experience SQL Server, SSIS, EDIS, and Big Data Enjoy Big Data projects and query tuning

Agenda Mega Chainsaws Corp. Cool Stuff this course will teach you Company Sales Database Overview Tables involved in Sales Query Identify bottlenecks Restructure query to run faster Q & A Cool Stuff this course will teach you How to generate random data of any size/type How to size all tables in a database How to read an execution plan and identify opportunities for performance gains

1. Mega Chainsaws Corp Time to Generate some data USE MEGA_CHAINSAWS GO exec USP_LOAD_DUMMY_DATA_TO_DB

1. Mega Chainsaws Corp Tip 1: Know your data size USE MEGA_CHAINSAWS Table Name Data Description CUST_ID Customer information (names) DPT Departments INVC_DTL Invoice line detail INVC_HDR Invoice header INVC_STAT_CD Invoice status PO_DTL Purchase order detail PO_HDR Purchase order header PO_STAT_CD PO status code PO_SUB_STAT_CD PO sub status code SKU Product sku/description/retail SKU_STAT_CD SKU status (active/clearance/inactive) SLS_REP_ID Sales Rep name SLS_REP_STAT_CD Employee Status Code (Active/Term) Tip 1: Know your data size USE MEGA_CHAINSAWS GO exec usp_get_tbl_sizes

2. Examine Slow Query Over a dozen table joins Clustered Indexes on larger tables do not align (PO_DTL and INVC_DTL) LIKE statement in the WHERE clause multiple times, combined with OR

2. Bottlenecks to look for SELECTS in the WHERE clause Range Joins Like Operators Non-covering indexes Clustered Indexes not aligning and forcing a hash join on large tables AND IHDR.INVC_DT = (SELECT MAX(INVC_DT) FROM INVC_HDR WHERE INVC_ID = IHDR.INVC_ID) AND IHDR.INVC_DT BETWEEN POH.ORD_DT AND DATEADD(DAY,90, POH.ORD_DT) OR lower(C.CUST_NM) LIKE '%alvarez%'

3. Current Execution Plan Biggest Performance Killers Hash Matches Full Table Scans (no index)

3. Optimize this Query Break your query into smaller chunks Leverage SELECT INTO statements (They are fast) Use temp tables to pre-process data

Walk through new Stored Proc 3. Optimize this Query Walk through new Stored Proc

4. Take-aways Do not fall in the trap of optimization to death. Is it really worth an extra 3-4 hours of work to shave off another 5 seconds on a query? Know your data size. Small tables are not worth your time to optimize queries against. Odds are it will run a full table scan anyways due to diminished returns on optimization Check your clustered indexes for header/detail relational tables. If you can leverage an Identity seed as the clustered index for the header and detail, almost always do it. Why? - The optimizer has to compare 1 column to merge the two tables against and its an integer so it will be fast

Optimization Optimization MATT MARTIN CTO | SQLETL Twitter: @sqletl_matt Website: www.sqletl.com Email: matt@sqletl.com