SlideShare a Scribd company logo
1 of 22
Download to read offline
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

SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
Vikas Gupta
 

What's hot (15)

Dare to build vertical design with relational data (Entity-Attribute-Value)
Dare to build vertical design with relational data (Entity-Attribute-Value)Dare to build vertical design with relational data (Entity-Attribute-Value)
Dare to build vertical design with relational data (Entity-Attribute-Value)
 
Extensible Data Modeling
Extensible Data ModelingExtensible Data Modeling
Extensible Data Modeling
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
Ch04
Ch04Ch04
Ch04
 
Lesson01 学会使用基本的SQL语句
Lesson01 学会使用基本的SQL语句Lesson01 学会使用基本的SQL语句
Lesson01 学会使用基本的SQL语句
 
Ch05
Ch05Ch05
Ch05
 
Module 3
Module 3Module 3
Module 3
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Final
 
Les02
Les02Les02
Les02
 
Sql server select queries ppt 18
Sql server select queries ppt 18Sql server select queries ppt 18
Sql server select queries ppt 18
 
Consultas con agrupaci¾n de datos
Consultas con agrupaci¾n de datosConsultas con agrupaci¾n de datos
Consultas con agrupaci¾n de datos
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
 
Les01
Les01Les01
Les01
 

Viewers also liked

Viewers also liked (7)

Performance Sql Server
Performance Sql ServerPerformance Sql Server
Performance Sql Server
 
SQL Server – Performance e Tunning
SQL Server – Performance e TunningSQL Server – Performance e Tunning
SQL Server – Performance e Tunning
 
SQL Saturday 329 - Novo Cardinality Estimator do SQL Server 2014
SQL Saturday 329 - Novo Cardinality Estimator do SQL Server 2014SQL Saturday 329 - Novo Cardinality Estimator do SQL Server 2014
SQL Saturday 329 - Novo Cardinality Estimator do SQL Server 2014
 
Find and fix SQL Server performance problems faster
Find and fix SQL Server performance problems fasterFind and fix SQL Server performance problems faster
Find and fix SQL Server performance problems faster
 
SQL Server Performance Tuning Baseline
SQL Server Performance Tuning BaselineSQL Server Performance Tuning Baseline
SQL Server Performance Tuning Baseline
 
Sql server performance tuning
Sql server performance tuningSql server performance tuning
Sql server performance tuning
 
Database Performance Tuning Introduction
Database  Performance Tuning IntroductionDatabase  Performance Tuning Introduction
Database Performance Tuning Introduction
 

Similar to SQA server performance tuning

SQL Server 2000 Research Series - Performance Tuning
SQL Server 2000 Research Series - Performance TuningSQL Server 2000 Research Series - Performance Tuning
SQL Server 2000 Research Series - Performance Tuning
Jerry Yang
 
SQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLSQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQL
Jerry Yang
 
Sql Patterns
Sql PatternsSql Patterns
Sql Patterns
phanleson
 
MDI Training DB2 Course
MDI Training DB2 CourseMDI Training DB2 Course
MDI Training DB2 Course
Marcus Davage
 

Similar to SQA server performance tuning (20)

Veri Ambarları için Oracle'ın Analitik SQL Desteği
Veri Ambarları için Oracle'ın Analitik SQL DesteğiVeri Ambarları için Oracle'ın Analitik SQL Desteği
Veri Ambarları için Oracle'ın Analitik SQL Desteği
 
MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
MySQL Performance Optimization
MySQL Performance OptimizationMySQL Performance Optimization
MySQL Performance Optimization
 
SQL Server 2000 Research Series - Performance Tuning
SQL Server 2000 Research Series - Performance TuningSQL Server 2000 Research Series - Performance Tuning
SQL Server 2000 Research Series - Performance Tuning
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
The Key to Keys - Database Design
The Key to Keys - Database DesignThe Key to Keys - Database Design
The Key to Keys - Database Design
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Advanced SQL For Data Scientists
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data Scientists
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
MIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresMIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome Measures
 
SQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLSQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQL
 
Sql Patterns
Sql PatternsSql Patterns
Sql Patterns
 
Database queries
Database queriesDatabase queries
Database queries
 
MDI Training DB2 Course
MDI Training DB2 CourseMDI Training DB2 Course
MDI Training DB2 Course
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R lang
 
San diegophp
San diegophpSan diegophp
San diegophp
 
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
 

More from Duy Tan Geek

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

More from Duy Tan Geek (20)

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

Recently uploaded

Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
AroojKhan71
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
amitlee9823
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
amitlee9823
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
MarinCaroMartnezBerg
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
amitlee9823
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 

Recently uploaded (20)

VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 

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