SlideShare a Scribd company logo
SQLSERVER PERFORMANCE
TUNING
Presenter: Trịnh Hồng Chương
AGENDA
About my company – ANS-ASIA, and me
About SQL Performance
Indexing
Rewrite query
SQLServer tools to improve performance.
ABOUT
100% subsidiary of ANS Japan
Address : 10F CMC Tower, Duy Tan Street
Foudation : November 2012
Employees : 30
Business function :Business function :
Software development
Enterprise system (100% Japanese customer up to now)
(Sales management system, Enterprise system for transportation
industry, Tuition management system for university...)
IT consulting
ABOUT ME
Name: Trinh Hong Chuong
Skill: 6 years experience in software development
(.Net (VB.Net, C#), T-SQL, PL-SQL, VBA)
Beginner in PHP, PostgreSQL
Interesting in: Reading book, listening music,
walking alone, travelling, ….walking alone, travelling, ….
SQL PERFORMANCE
Assess the problem and establish numeric values
that categorize acceptable behavior.
Measure the performance of the system before
modification.
Identify the part of the system that is critical for
improving the performance. This is called
the bottleneck.
improving the performance. This is called
the bottleneck.
Modify that part of the system to remove the
bottleneck.
Measure the performance of the system after
modification.
If the modification makes the performance better,
adopt it. If the modification makes the
performance worse, put it back the way it was.
WHAT’S INDEXING
Index is shortcuts to real data
Data type structure: B-Tree
Types of indexes: Clustered, Non-Clustered, XML
index, Fulltext index
WHY’S INDEXING
An index is used to speed up searching in the
database.
Indexes can be helpful for a variety of queries
that contain SELECT, UPDATE, DELETE, or
MERGE statements.
Less items in primary keyLess items in primary key
CLUSTERED INDEX
Clustered indexes sort and store the data rows in
the table or view based on their key values.
root
Id(from 1 to 4) Id(from 5 to 7)Id(from 1 to 4) Id(from 5 to 7)
Id 1
Name Bill
Dept Dev
Id 2
Name Jobs
Dept HR
Id 7
Name Gate
Dept R&D
NON-CLUSTERED INDEX
A nonclustered index contains the nonclustered
index key values and each key value entry has a
pointer to the data row that contains the key
value.
root
Name(from A to F)
Name Bill
Id 1
Name Gate
Id 7
Name Jobs
Id 2
Name(from G to M) Name(from N to Z)
IMPROVE INDEX
Create Highly-Selective Indexes
Indexing on columns used in the WHERE clause of
your critical queries frequently improves
performance.
Selectivity is the ratio of qualifying rows to total
rows. If the ratio is low, the index is highly selective.
Create Multiple-Column IndexesCreate Multiple-Column Indexes
REWRITE QUERY
Use a search argument (SARG)
SARG operators include =, >, <, >=, <=, IN,
BETWEEN, and sometimes LIKE (in cases of prefix
matching, such as LIKE ‘Bill%')
Non-SARG operators include NOT, <>, NOT EXISTS,
NOT IN, NOT LIKE, and intrinsic functions
REWRITE QUERY
Rewrite sub-query into JOIN
Bad sample Good sample
SELECT "Order ID" SELECT DISTINCT O."Order ID"
FROM Orders O
WHERE EXISTS (SELECT "Order ID"
FROM "Order Details"
OD
WHERE O."Order ID" =
OD."Order ID"
AND Discount >= 0.25)
FROM Orders O
INNER JOIN "Order Details" OD
ON
O."Order ID" = OD."Order ID"
WHERE Discount >= 0.25
REWRITE QUERY
Don’t use intrinsic functions, type conversion on index column
Bad sample Good sample
DECLARE @limitId = 10
SELECT Name FROM
Employees
DECLARE @limitId = 10
SELECT Name FROM
EmployeesEmployees
WHERE Id - 1 = @limitId
Employees
WHERE Id = @limitId + 1
REWRITE QUERY
Use parameterizied queries
Query only you must
About Performance, cursor less than base-query
REWRITE QUERY
Index the ORDER-BY / GROUP-BY
CREATE INDEX Emp_Name ON Employees ("Last Name" ASC, "First Name" ASC)
Can help optimize Will not help optimize
... ORDER BY / GROUP BY "Last
Name" ...
... ORDER BY / GROUP BY
"First Name" ...Name" ...
... ORDER BY / GROUP BY "Last
Name", "First Name" ...
"First Name" ...
... ORDER BY / GROUP BY
"First Name", "Last Name" ...
REWRITE QUERY
Index the DISTINCT
CREATE INDEX Emp_Name ON Employees ("Last Name" ASC, "First Name" ASC)
Can help optimize Will not help optimize
... DISTINCT "Last Name", "First
Name" ...
... DISTINCT "First Name" ...
... DISTINCT "Last Name" ...Name" ...
... DISTINCT "First Name", "Last
Name" ...
... DISTINCT "Last Name" ...
SQLServer tools to improve performance.
Execution plan
CREATE TABLE Employees
(
Id BIGINT NOT NULL,
Name VARCHAR(20) NOT NULL,
Dept VARCHAR(10),
CONSTRAINT [PK_Employee] PRIMARY KEY
CLUSTERED
(Id ASC)
)
CREATE TABLE Employees_Mid
(
Id BIGINT NOT NULL,
Name VARCHAR(20) NOT NULL,
Dept VARCHAR(10),
CONSTRAINT [PK_Employee_Mid] PRIMARY KEY
CLUSTERED
(Id ASC)
)
Query 01
INSERT INTO Employees(Id, Name, Dept)
SELECT Id, Name, Dept FROM Employees_Mid
WHERE Employees_Mid.Id = 1000
Query 02
INSERT INTO Employees(Id, Name, Dept)
SELECT Id, Name, Dept FROM Employees_Mid
WHERE Employees_Mid.Name = ‘A00001’
EXECUTION PLAN – QUERY 01
EXECUTION PLAN – QUERY 02
SQLServer tools to improve performance.
SQL Profiler
REFERENCE
http://technet.microsoft.com
http://www.sqlviet.com
SQA server performance tuning

More Related Content

What's hot (15)

PDF
Dare to build vertical design with relational data (Entity-Attribute-Value)
Ivo Andreev
 
PDF
Extensible Data Modeling
Karwin Software Solutions LLC
 
PPT
SQL select statement and functions
Vikas Gupta
 
PPT
Advanced Sql Training
bixxman
 
PDF
Ch04
cs19club
 
PDF
Lesson01 学会使用基本的SQL语句
renguzi
 
PDF
Ch05
cs19club
 
DOC
Module 3
cs19club
 
PPT
Les09 (using ddl statements to create and manage tables)
Achmad Solichin
 
PPT
Aggregate Functions,Final
mukesh24pandey
 
PPT
Sql server select queries ppt 18
Vibrant Technologies & Computers
 
PDF
Consultas con agrupaci¾n de datos
Caleb Gutiérrez
 
PPT
SQL- Introduction to MySQL
Vibrant Technologies & Computers
 
PPT
Les01
Akmal Rony
 
Dare to build vertical design with relational data (Entity-Attribute-Value)
Ivo Andreev
 
Extensible Data Modeling
Karwin Software Solutions LLC
 
SQL select statement and functions
Vikas Gupta
 
Advanced Sql Training
bixxman
 
Ch04
cs19club
 
Lesson01 学会使用基本的SQL语句
renguzi
 
Ch05
cs19club
 
Module 3
cs19club
 
Les09 (using ddl statements to create and manage tables)
Achmad Solichin
 
Aggregate Functions,Final
mukesh24pandey
 
Sql server select queries ppt 18
Vibrant Technologies & Computers
 
Consultas con agrupaci¾n de datos
Caleb Gutiérrez
 
SQL- Introduction to MySQL
Vibrant Technologies & Computers
 
Les01
Akmal Rony
 

Viewers also liked (7)

PPT
Performance Sql Server
jarlei
 
PPTX
SQL Server – Performance e Tunning
pt_programar
 
PPTX
SQL Saturday 329 - Novo Cardinality Estimator do SQL Server 2014
Vitor Fava
 
PDF
Find and fix SQL Server performance problems faster
SolarWinds
 
PDF
SQL Server Performance Tuning Baseline
► Supreme Mandal ◄
 
PPT
Sql server performance tuning
ngupt28
 
PPSX
Database Performance Tuning Introduction
MyOnlineITCourses
 
Performance Sql Server
jarlei
 
SQL Server – Performance e Tunning
pt_programar
 
SQL Saturday 329 - Novo Cardinality Estimator do SQL Server 2014
Vitor Fava
 
Find and fix SQL Server performance problems faster
SolarWinds
 
SQL Server Performance Tuning Baseline
► Supreme Mandal ◄
 
Sql server performance tuning
ngupt28
 
Database Performance Tuning Introduction
MyOnlineITCourses
 
Ad

Similar to SQA server performance tuning (20)

PDF
SQL Database Performance Tuning for Developers
BRIJESH KUMAR
 
PPTX
Sql performance tuning
Leo Mark Villar
 
PPTX
Sql server ___________session_17(indexes)
Ehtisham Ali
 
PPT
SQL Server 2000 Research Series - Performance Tuning
Jerry Yang
 
PPTX
Query Optimization in SQL Server
Rajesh Gunasundaram
 
PPTX
02 database oprimization - improving sql performance - ent-db
uncleRhyme
 
PPTX
Database Performance Tuning
Arno Huetter
 
PDF
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
Polish SQL Server User Group
 
PPTX
dotnetMALAGA - Sql query tuning guidelines
Javier García Magna
 
PPT
Myth busters - performance tuning 101 2007
paulguerin
 
PPT
Filtered Indexes In Sql 2008
wharrislv
 
PPT
Module08
guest5c8fba1
 
PPT
Module08
Sridhar P
 
PDF
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
Andriy Krayniy
 
DOCX
Indexes in ms sql server
Rahul Yerrabelli
 
PPTX
SQL Server Index and Partition Strategy
Hamid J. Fard
 
PPTX
We Don't Need Roads: A Developers Look Into SQL Server Indexes
Richie Rump
 
PPTX
Introduction of sql server indexing
Mahabubur Rahaman
 
PPS
07 qmds2005 session10
Niit Care
 
SQL Database Performance Tuning for Developers
BRIJESH KUMAR
 
Sql performance tuning
Leo Mark Villar
 
Sql server ___________session_17(indexes)
Ehtisham Ali
 
SQL Server 2000 Research Series - Performance Tuning
Jerry Yang
 
Query Optimization in SQL Server
Rajesh Gunasundaram
 
02 database oprimization - improving sql performance - ent-db
uncleRhyme
 
Database Performance Tuning
Arno Huetter
 
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
Polish SQL Server User Group
 
dotnetMALAGA - Sql query tuning guidelines
Javier García Magna
 
Myth busters - performance tuning 101 2007
paulguerin
 
Filtered Indexes In Sql 2008
wharrislv
 
Module08
guest5c8fba1
 
Module08
Sridhar P
 
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
Andriy Krayniy
 
Indexes in ms sql server
Rahul Yerrabelli
 
SQL Server Index and Partition Strategy
Hamid J. Fard
 
We Don't Need Roads: A Developers Look Into SQL Server Indexes
Richie Rump
 
Introduction of sql server indexing
Mahabubur Rahaman
 
07 qmds2005 session10
Niit Care
 
Ad

More from Duy Tan Geek (20)

PDF
Amazon Elastic Load Balancing
Duy Tan Geek
 
PDF
Cloud - FOSS & Challenge
Duy Tan Geek
 
PDF
AWS, is it interesting?
Duy Tan Geek
 
PDF
Cloud DC Transforming
Duy Tan Geek
 
PDF
Becoming a better programmer - unit testing
Duy Tan Geek
 
PDF
Practical TDD in Septeni Technology
Duy Tan Geek
 
PDF
Build Quality In with TDD
Duy Tan Geek
 
PDF
Sharing bridge SE working experience of myself
Duy Tan Geek
 
PDF
Game development with Cocos2d-x Engine
Duy Tan Geek
 
PDF
HTML5 mobile games
Duy Tan Geek
 
PDF
Game engine introduction and approach
Duy Tan Geek
 
PDF
10 things you need to know about doing business with Japanese
Duy Tan Geek
 
PDF
Enjoy Japanese work style
Duy Tan Geek
 
PDF
A cup of coffee worth 10 dollars is what we are going to sell!
Duy Tan Geek
 
PDF
Leader ship value
Duy Tan Geek
 
PDF
Introduction to pmp
Duy Tan Geek
 
PDF
Beyond project management
Duy Tan Geek
 
PDF
The way to set automation testing
Duy Tan Geek
 
PDF
Quality Management Introduction
Duy Tan Geek
 
PDF
Techniques in black box testing
Duy Tan Geek
 
Amazon Elastic Load Balancing
Duy Tan Geek
 
Cloud - FOSS & Challenge
Duy Tan Geek
 
AWS, is it interesting?
Duy Tan Geek
 
Cloud DC Transforming
Duy Tan Geek
 
Becoming a better programmer - unit testing
Duy Tan Geek
 
Practical TDD in Septeni Technology
Duy Tan Geek
 
Build Quality In with TDD
Duy Tan Geek
 
Sharing bridge SE working experience of myself
Duy Tan Geek
 
Game development with Cocos2d-x Engine
Duy Tan Geek
 
HTML5 mobile games
Duy Tan Geek
 
Game engine introduction and approach
Duy Tan Geek
 
10 things you need to know about doing business with Japanese
Duy Tan Geek
 
Enjoy Japanese work style
Duy Tan Geek
 
A cup of coffee worth 10 dollars is what we are going to sell!
Duy Tan Geek
 
Leader ship value
Duy Tan Geek
 
Introduction to pmp
Duy Tan Geek
 
Beyond project management
Duy Tan Geek
 
The way to set automation testing
Duy Tan Geek
 
Quality Management Introduction
Duy Tan Geek
 
Techniques in black box testing
Duy Tan Geek
 

Recently uploaded (20)

PDF
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
PDF
Technical-Report-GPS_GIS_RS-for-MSF-finalv2.pdf
KPycho
 
PPTX
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
PPTX
Feb 2021 Ransomware Recovery presentation.pptx
enginsayin1
 
PDF
apidays Singapore 2025 - Surviving an interconnected world with API governanc...
apidays
 
PPTX
apidays Singapore 2025 - Generative AI Landscape Building a Modern Data Strat...
apidays
 
PPTX
SlideEgg_501298-Agentic AI.pptx agentic ai
530BYManoj
 
PDF
A GraphRAG approach for Energy Efficiency Q&A
Marco Brambilla
 
PPTX
SHREYAS25 INTERN-I,II,III PPT (1).pptx pre
swapnilherage
 
PDF
Development and validation of the Japanese version of the Organizational Matt...
Yoga Tokuyoshi
 
PDF
apidays Singapore 2025 - Building a Federated Future, Alex Szomora (GSMA)
apidays
 
PPT
Growth of Public Expendituuure_55423.ppt
NavyaDeora
 
PPTX
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
PDF
1750162332_Snapshot-of-Indias-oil-Gas-data-May-2025.pdf
sandeep718278
 
PDF
The Best NVIDIA GPUs for LLM Inference in 2025.pdf
Tamanna36
 
PDF
Business implication of Artificial Intelligence.pdf
VishalChugh12
 
PDF
InformaticsPractices-MS - Google Docs.pdf
seshuashwin0829
 
PPTX
04_Tamás Marton_Intuitech .pptx_AI_Barometer_2025
FinTech Belgium
 
PPTX
BinarySearchTree in datastructures in detail
kichokuttu
 
PPTX
Powerful Uses of Data Analytics You Should Know
subhashenia
 
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
Technical-Report-GPS_GIS_RS-for-MSF-finalv2.pdf
KPycho
 
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
Feb 2021 Ransomware Recovery presentation.pptx
enginsayin1
 
apidays Singapore 2025 - Surviving an interconnected world with API governanc...
apidays
 
apidays Singapore 2025 - Generative AI Landscape Building a Modern Data Strat...
apidays
 
SlideEgg_501298-Agentic AI.pptx agentic ai
530BYManoj
 
A GraphRAG approach for Energy Efficiency Q&A
Marco Brambilla
 
SHREYAS25 INTERN-I,II,III PPT (1).pptx pre
swapnilherage
 
Development and validation of the Japanese version of the Organizational Matt...
Yoga Tokuyoshi
 
apidays Singapore 2025 - Building a Federated Future, Alex Szomora (GSMA)
apidays
 
Growth of Public Expendituuure_55423.ppt
NavyaDeora
 
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
1750162332_Snapshot-of-Indias-oil-Gas-data-May-2025.pdf
sandeep718278
 
The Best NVIDIA GPUs for LLM Inference in 2025.pdf
Tamanna36
 
Business implication of Artificial Intelligence.pdf
VishalChugh12
 
InformaticsPractices-MS - Google Docs.pdf
seshuashwin0829
 
04_Tamás Marton_Intuitech .pptx_AI_Barometer_2025
FinTech Belgium
 
BinarySearchTree in datastructures in detail
kichokuttu
 
Powerful Uses of Data Analytics You Should Know
subhashenia
 

SQA server performance tuning

  • 2. AGENDA About my company – ANS-ASIA, and me About SQL Performance Indexing Rewrite query SQLServer tools to improve performance.
  • 3. ABOUT 100% subsidiary of ANS Japan Address : 10F CMC Tower, Duy Tan Street Foudation : November 2012 Employees : 30 Business function :Business function : Software development Enterprise system (100% Japanese customer up to now) (Sales management system, Enterprise system for transportation industry, Tuition management system for university...) IT consulting
  • 4. ABOUT ME Name: Trinh Hong Chuong Skill: 6 years experience in software development (.Net (VB.Net, C#), T-SQL, PL-SQL, VBA) Beginner in PHP, PostgreSQL Interesting in: Reading book, listening music, walking alone, travelling, ….walking alone, travelling, ….
  • 5. SQL PERFORMANCE Assess the problem and establish numeric values that categorize acceptable behavior. Measure the performance of the system before modification. Identify the part of the system that is critical for improving the performance. This is called the bottleneck. improving the performance. This is called the bottleneck. Modify that part of the system to remove the bottleneck. Measure the performance of the system after modification. If the modification makes the performance better, adopt it. If the modification makes the performance worse, put it back the way it was.
  • 6. WHAT’S INDEXING Index is shortcuts to real data Data type structure: B-Tree Types of indexes: Clustered, Non-Clustered, XML index, Fulltext index
  • 7. WHY’S INDEXING An index is used to speed up searching in the database. Indexes can be helpful for a variety of queries that contain SELECT, UPDATE, DELETE, or MERGE statements. Less items in primary keyLess items in primary key
  • 8. CLUSTERED INDEX Clustered indexes sort and store the data rows in the table or view based on their key values. root Id(from 1 to 4) Id(from 5 to 7)Id(from 1 to 4) Id(from 5 to 7) Id 1 Name Bill Dept Dev Id 2 Name Jobs Dept HR Id 7 Name Gate Dept R&D
  • 9. NON-CLUSTERED INDEX A nonclustered index contains the nonclustered index key values and each key value entry has a pointer to the data row that contains the key value. root Name(from A to F) Name Bill Id 1 Name Gate Id 7 Name Jobs Id 2 Name(from G to M) Name(from N to Z)
  • 10. IMPROVE INDEX Create Highly-Selective Indexes Indexing on columns used in the WHERE clause of your critical queries frequently improves performance. Selectivity is the ratio of qualifying rows to total rows. If the ratio is low, the index is highly selective. Create Multiple-Column IndexesCreate Multiple-Column Indexes
  • 11. REWRITE QUERY Use a search argument (SARG) SARG operators include =, >, <, >=, <=, IN, BETWEEN, and sometimes LIKE (in cases of prefix matching, such as LIKE ‘Bill%') Non-SARG operators include NOT, <>, NOT EXISTS, NOT IN, NOT LIKE, and intrinsic functions
  • 12. REWRITE QUERY Rewrite sub-query into JOIN Bad sample Good sample SELECT "Order ID" SELECT DISTINCT O."Order ID" FROM Orders O WHERE EXISTS (SELECT "Order ID" FROM "Order Details" OD WHERE O."Order ID" = OD."Order ID" AND Discount >= 0.25) FROM Orders O INNER JOIN "Order Details" OD ON O."Order ID" = OD."Order ID" WHERE Discount >= 0.25
  • 13. REWRITE QUERY Don’t use intrinsic functions, type conversion on index column Bad sample Good sample DECLARE @limitId = 10 SELECT Name FROM Employees DECLARE @limitId = 10 SELECT Name FROM EmployeesEmployees WHERE Id - 1 = @limitId Employees WHERE Id = @limitId + 1
  • 14. REWRITE QUERY Use parameterizied queries Query only you must About Performance, cursor less than base-query
  • 15. REWRITE QUERY Index the ORDER-BY / GROUP-BY CREATE INDEX Emp_Name ON Employees ("Last Name" ASC, "First Name" ASC) Can help optimize Will not help optimize ... ORDER BY / GROUP BY "Last Name" ... ... ORDER BY / GROUP BY "First Name" ...Name" ... ... ORDER BY / GROUP BY "Last Name", "First Name" ... "First Name" ... ... ORDER BY / GROUP BY "First Name", "Last Name" ...
  • 16. REWRITE QUERY Index the DISTINCT CREATE INDEX Emp_Name ON Employees ("Last Name" ASC, "First Name" ASC) Can help optimize Will not help optimize ... DISTINCT "Last Name", "First Name" ... ... DISTINCT "First Name" ... ... DISTINCT "Last Name" ...Name" ... ... DISTINCT "First Name", "Last Name" ... ... DISTINCT "Last Name" ...
  • 17. SQLServer tools to improve performance. Execution plan CREATE TABLE Employees ( Id BIGINT NOT NULL, Name VARCHAR(20) NOT NULL, Dept VARCHAR(10), CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED (Id ASC) ) CREATE TABLE Employees_Mid ( Id BIGINT NOT NULL, Name VARCHAR(20) NOT NULL, Dept VARCHAR(10), CONSTRAINT [PK_Employee_Mid] PRIMARY KEY CLUSTERED (Id ASC) ) Query 01 INSERT INTO Employees(Id, Name, Dept) SELECT Id, Name, Dept FROM Employees_Mid WHERE Employees_Mid.Id = 1000 Query 02 INSERT INTO Employees(Id, Name, Dept) SELECT Id, Name, Dept FROM Employees_Mid WHERE Employees_Mid.Name = ‘A00001’
  • 18. EXECUTION PLAN – QUERY 01
  • 19. EXECUTION PLAN – QUERY 02
  • 20. SQLServer tools to improve performance. SQL Profiler