SlideShare a Scribd company logo
SQL Server Query Parameterization


Query Tuning

Ritesh Kumar
Skype: mfs_ritesh
Blog: http://exacthelp.blogspot.com/
INDEX


Adhoc Query



Predicates Order



Execution Plan



Query Optimizer



Parameter Sniffing



Indexes



Statistics



Database Engine Tuning Advisor
Adhoc Query
q

Any non-parameterized queries are called addhoc queries.
For example :

q

SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 100

q

In sql server if we execute a sql query it goes through two
steps just like any other programming languages:

q

Compilation

q

Execution
Properties Of Addhoc Queries
q

Case sensitive

q

Space sensitive

q

Parameter sensitive 

q

Sql server treats two same sql queries of different parameters
as a two different sql statements. For example:

q

SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 1

q

SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 2

Recommended for you

02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping

The document discusses various linear data structures like arrays, strings, stacks, queues, and linked lists. It provides details on representing single and multi-dimensional arrays, including addressing formulas. Operations on ordered lists like lists are defined. Linear lists using arrays are implemented with methods for adding, removing, and changing elements.

Algorithm & data structures lec4&5
Algorithm & data structures lec4&5Algorithm & data structures lec4&5
Algorithm & data structures lec4&5

The document summarizes different searching and sorting algorithms. It discusses linear search and binary search for searching algorithms. It explains that linear search has O(n) time complexity while binary search has O(log n) time complexity. For sorting algorithms, it describes bubble sort, selection sort, and insertion sort. It provides pseudocode to illustrate how each algorithm works to sort a list or array.

Data structures
Data structuresData structures
Data structures

This document provides an overview of different data structures and sorting algorithms. It begins with an introduction to data structures and describes linear data structures like arrays, stacks, queues, and linked lists as well as non-linear data structures like trees and graphs. It then provides more detailed descriptions of stacks, queues, linked lists, and common sorting algorithms like selection sort and bubble sort.

java
Effect Of Faulty C# Code


Sql server has took extra n * (Compilation time) ms to display
records



Extra time to insert records in cached plans.



Sql server has to frequently fire a job to delete the cached plan
since it will reach the max limit very soon.



It will not only decrease the performance of this sql query but all sql
queries of other applications since this faulty code will force to
delete cached query plans of other sql statements.
Predicates Order
q

Does order of predicates matters in WHERE clause?

q

WHERE vcLanguage = 'English' AND ntAge = 12

q

WHERE ntAge = 12 AND vcLanguage = 'English'
Execution Plan
Query Optimizer

Recommended for you

Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms

The document discusses several sorting algorithms including selection sort, insertion sort, bubble sort, merge sort, and quick sort. It provides details on how each algorithm works including pseudocode implementations and analyses of their time complexities. Selection sort, insertion sort and bubble sort have a worst-case time complexity of O(n^2) while merge sort divides the list into halves and merges in O(n log n) time, making it more efficient for large lists.

3.6 radix sort
3.6 radix sort3.6 radix sort
3.6 radix sort

Radix sort is a non-comparative sorting algorithm that sorts numeric keys by decomposing them into digits and sorting the digits individually. It works by representing keys as d-digit numbers in some base-k, then sorting the numbers by looking at one column of digits at a time from least to most significant. This requires d passes through the list, resulting in a time complexity of O(d(n+k)) where n is the number of keys and k is the maximum possible digit value, assuming d and k are constants. When d and k are O(n), the overall time complexity is O(n).

data structure-radix sort
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures

Presentation is on Various Data Structures And Operations Related to it. Brief Description Of Operations Using Examples.

data structures
Query Optimizer
The query optimizer in SQL Server is cost-based. It includes:
q

Cost for using different resources (CPU and IO)

q

Total execution time

 
It determines the cost by using:


Cardinality: The total number of rows processed at each level of a
query plan with the help of histograms , predicates and constraint



Cost model of the algorithm: To perform various operations like
sorting, searching, comparisons etc.
Parameter Sniffing


Sql server generates execution paln according to the first
parameter



This execution plan may bad for other parameters.

 
Solution:


Create multiples stored procedures.



Use optimizer for query hints.
What Is An Index ?
q

Index is a way to organize data to make searching, sorting
and grouping faster.

q

we need indexing when :

q

WHERE, ON, HAVING clause (Searching)

q

ORDER BY clause (Sorting)

q

GROUP BY clause (Grouping) etc.
Table Scan
SELECT * FROM Student WHERE RollNo = 111

Time complexity of table scan is : O(n)
RollNo

Name

Country

Age

101

Greg

UK

23

102

Sachin

India

21

103

Akaram

Pakistan

22

107

Miyabi

China

18

108

Marry

Russia

27

109

Scott

USA

31

110

Benazir

Banglades

17

111

Miyabi

Japan

24

112

Rahul

India

27

113

Nicolus

France

19

Recommended for you

Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms

The document discusses different types of searching algorithms. It describes sequential search which searches an unsorted list sequentially until the target item is found or the entire list is searched. The average runtime is O(n) as the item could be anywhere in the list. Binary search is described as more efficient for sorted lists, repeatedly dividing the search space in half and comparing the target to the middle element. Indexes are also summarized, including clustered vs unclustered indexes and different approaches to storing data entries.

Array 2
Array 2Array 2
Array 2

The document discusses arrays and their representation in memory. It contains 3 main points: 1) It introduces linear arrays and how they are represented in memory with sequential and contiguous locations. It also discusses multidimensional arrays. 2) It provides algorithms for common linear array operations like traversing, inserting, deleting and searching using binary search. It explains how each algorithm works through examples. 3) It discusses how 2D arrays are represented in memory and visualized, using an example of storing student exam marks in a 2D array.

Array ADT(Abstract Data Type)|Data Structure
Array ADT(Abstract Data Type)|Data StructureArray ADT(Abstract Data Type)|Data Structure
Array ADT(Abstract Data Type)|Data Structure

The document discusses abstract data types (ADTs) and describes an array ADT. It lists common array operations like display, add, insert, delete, search, get, set, max, min, reverse, shift, and provides pseudocode implementations. Operations like insert and delete are O(n) linear time due to array element shifting. Search operations can be improved to O(1) constant time using techniques like transposition and move to front. Binary search provides O(logn) time complexity for sorted arrays. The document also discusses sorting an array, checking if an array is sorted, arranging negative numbers to the left, and merging two sorted arrays.

data structurearray adtoperation on array
Types Of Index
q

Table without any index is called Heap

q

There are two type of index:

q

Clustered index

q

Non-Clustered index
Clustered Index


When we create a clustered index on any table physical
organization of table is changed.



Now data of table is stored as a balanced tree(B tree).

CREATE UNIQUE [CLUSTERED] INDEX <Name>
ON <ObjectName>(
<ColumnName>  [ASC | DESC ] [ ,...n ]
)
Sql Server Query Parameterization
Types Of Scanning


Table scan: It is very slow can and it is used only if table has
not any clustered index.



Index scan: It is also slow scan. It is used when table has
clustered index and either in WHERE clause non-key columns
are present or query has not been covered (will discuss later)
or both.



Index Seek: It is very fast. Our goal is to achieve this.

Recommended for you

Query hierarchical data the easy way, with CTEs
Query hierarchical data the easy way, with CTEsQuery hierarchical data the easy way, with CTEs
Query hierarchical data the easy way, with CTEs

With common table expressions (CTEs), it’s easy to write recursive queries and query hierarchical data such as graphs – a lot easier than using a specialized graph database or writing complex client-side code. In this session, you’ll learn about the surprising number of places where graph data appears in modern applications and how to efficiently store and query it using MariaDB and common table expressions.

List Data Structure
List Data StructureList Data Structure
List Data Structure

A list is a sequential data structure that allows additions and removals at any position, unlike stacks and queues. Common list operations include adding and removing nodes, updating node contents, checking if the list is empty/full, and initializing/destroying the list. Lists can be implemented using arrays (for static storage) or linked nodes (for dynamic storage). Array lists allow constant-time access but linear-time insertion/removal. Linked lists have linear-time access but constant-time insertion/removal. Both use probes and previous references to traverse the list during operations.

Counting Sort Lowerbound
Counting Sort LowerboundCounting Sort Lowerbound
Counting Sort Lowerbound

1. The document discusses lower bounds for sorting algorithms and proves that all comparison sorts require at least Ω(n lg n) time. 2. It then introduces counting sort, which runs in linear O(n) time by counting elements rather than comparing them, but requires the elements to be drawn from a small known range. 3. Radix sort is then described, which sorts integers digit-by-digit using counting sort, achieving linear time for integers by treating them as d-digit numbers in a base k system. This allows sorting large integers faster than comparison-based sorts.

lowerboundcount sort
Clustered Index


If we create table with primary key, sql server automatically
creates clustered index on that table



A table can have only one clustered index .



Physical order of rows of table is same as logical order of key
columns of clustered index.
Terms Of Execution Plan


Predicate: It is condition in WHERE clause which is either nonkey column or column which has not been covered.



Object: It is name of source from where it getting the data. It
can be name of table, Clustered index or non-clustered index



Output list: It is name of the columns which is getting from
object.



Seek Predicate: It is condition in WHERE clause which is either
key column or fully covered.
Non-Clustered Index


It is logical organization of data of table. A non-clustered index can
be of two types.

q

Heap

q

Based on clustered index.



If table has clustered index then leaf node of non-clustered index
keeps the key columns of clustered index.



If the table has not any clustered index then leaf node of nonclustered index keeps RID which unique of each row of table.
Based On Clustered Index

Recommended for you

Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue

The document discusses priority queues and quicksort. It defines a priority queue as a data structure that maintains a set of elements with associated keys. Heaps can be used to implement priority queues. There are two types: max-priority queues and min-priority queues. Priority queues have applications in job scheduling and event-driven simulation. Quicksort works by partitioning an array around a pivot element and recursively sorting the sub-arrays.

stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public

This document discusses stacks and queues as data structures. It begins by defining a stack as a linear collection where elements are added and removed from the top in a last-in, first-out (LIFO) manner. Common stack operations like push, pop, and peek are described. It then discusses applications of stacks like undo sequences and method calls. The document also defines queues as collections where elements are added to the rear and removed from the front in a first-in, first-out (FIFO) manner. Common queue operations and applications like waiting lists and printer access are also covered. Finally, it discusses implementations of stacks and queues using arrays and how to handle overflow and underflow cases.

stacksqueues
SQL Issue
SQL IssueSQL Issue
SQL Issue

An update was run on a table without a WHERE clause, updating all records in the table. This can have immediate impact on any transactions relying on primary keys. To avoid this, the ROWCOUNT option can be used to limit the number of rows updated. It is recommended to contact Aderant support or consultants instead of directly updating tables with SQL, as data integrity is critical. The contract with Aderant should also be reviewed before calling support regarding data issues caused by SQL updates.

Based On Heap
Covering Of Queries




We can specify maximum 16 column names.
Sum of size of the columns cannot be more than 900 bytes.



All columns must belong to same table.



Data type of columns cannot be ntext, text,
varchar (max), nvarchar (max), varbinary (max), xml, or image



It cannot be non-deterministic computed column.
Statistics Analysis


The query optimizer uses statistics to create query plans that
improve query performance



A correct statistics will lead to high-quality query plan.



The query optimizer determines when statistics might be out-ofdate by counting the number of data modifications since the
last statistics update and comparing the number of
modifications to a threshold.
Auto Create Statistics


Default setting of auto create statistics is ON.



It creates when:



Clustered and non clustered Index is created



Select query is executed.



Auto create and updates applies strictly to singlecolumn statistics.

Recommended for you

Radix Sort
Radix SortRadix Sort
Radix Sort

The document describes Radix sort, a sorting algorithm that sorts numbers by their individual digits by making multiple passes through the data. It works by first sorting the numbers based on the units place value, then the tens place, and so on. This is more efficient than other general-purpose sorting algorithms for large data sets with uniformly distributed values. Radix sort runs in O(d(n+k)) time, where d is the number of digits, n is the number of elements, and k is the maximum value of a digit.

15 unionfind
15 unionfind15 unionfind
15 unionfind

The document describes algorithms for solving the union-find problem, which involves maintaining disjoint sets under union and find operations. It introduces the quick-find, quick-union, and weighted quick-union algorithms. Quick-find is too slow for union operations, which can require quadratic time. Quick-union improves on this but find operations can be slow. Weighted quick-union balances trees during union to keep depths logarithmic, improving performance of both operations.

MS SQL Server 2008, Implementation and Maintenance
MS SQL Server 2008, Implementation and MaintenanceMS SQL Server 2008, Implementation and Maintenance
MS SQL Server 2008, Implementation and Maintenance

The document provides an agenda and details for a training course on MS SQL Server 2008 implementation and maintenance. It includes introductions, an overview of the instructor's background, a schedule of topics such as installing and configuring SQL Server, database configuration and maintenance, and practice questions. Database topics include files and filegroups, transaction logs, FILESTREAM data, tempdb database, and database recovery models.

Why Query 2 Is Performing Better
q

If we perform following operations on field of any table in
query predicate:

q

Using any system function or user defined function

q

Scalar operation like addition, multiplication etc.

q

Type casting

q

In this situation sql server query optimizer is not able to
estimate correct cardinality using statistics.
To Improve Cardinality


If possible, simplify expressions with constants in them.



If possible, don't perform any operation on the any field of a table
in WHERE Clause, ON Clause, HAVING Clause



Don't use local variables in WHERE Clause, ON Clause, HAVING
Clause. 



If there is any cross relationship among fields or there is a complex
expression in a field in a query predicates, it is better to create a
computed column and then create a non-clustered index on it.
To Improve Cardinality


If possible, don't update the value of parameters of a function or
stored procedure before using in sql statement



Use OPTIMIZE FOR clause when you want to optimize a sql query on
the basis of specific parameter value.



If you want to update the value parameter of a stored procedure or
a function create a similar procedure or function and execute it form
base procedure or function by passing the updated value as a
parameter. 



Create user defined multi column statistics if query predicates have
more than one fields of a table.
SQL Server Tools


Sql query profiler



Database Tuning Advisor



Client Statistics



Resource Governor



Data Collections

Recommended for you

Sigir12 tutorial: Query Perfromance Prediction for IR
Sigir12 tutorial: Query Perfromance Prediction for IRSigir12 tutorial: Query Perfromance Prediction for IR
Sigir12 tutorial: Query Perfromance Prediction for IR

This document summarizes a tutorial on query performance prediction given by Dr. David Carmel and Dr. Oren Kurland. It discusses the challenge of estimating query difficulty for information retrieval systems. Estimating query difficulty can provide benefits such as feedback to users, search engines, and system administrators. The tutorial covers basic concepts, query performance prediction methods, applications, and open challenges. It aims to help IR systems reduce variability in performance and better satisfy users' information needs.

Find and be Found: Information Retrieval at LinkedIn
Find and be Found: Information Retrieval at LinkedInFind and be Found: Information Retrieval at LinkedIn
Find and be Found: Information Retrieval at LinkedIn

Shakti Sinha and Daniel Tunkelang discuss how LinkedIn's search functionality works. They explain that LinkedIn search is personalized based on a user's profile and network. Query understanding involves tagging queries to determine entity types like people, companies, or skills. Ranking is also personalized using machine learning models trained on search logs to determine relevance for a specific user's query. The system aims to provide both globally and personally relevant results, as about two-thirds of clicks come from out of a user's network.

Password based door locksystem
Password  based door locksystemPassword  based door locksystem
Password based door locksystem

This system creates a password protected door lock using a microcontroller. It takes a password input from the user via a keypad, compares it to the programmed password, and only opens the door motor if they match by setting a port. Otherwise, it displays a "wrong password" message on an LCD screen.

password based door locksystem
THANK YOU

More Related Content

What's hot

Quicksort Algorithm..simply defined through animations..!!
Quicksort Algorithm..simply defined through animations..!!Quicksort Algorithm..simply defined through animations..!!
Quicksort Algorithm..simply defined through animations..!!
Mahesh Tibrewal
 
Radix sort
Radix sortRadix sort
Radix sort
zahraa F.Muhsen
 
Unit 3 stack
Unit 3   stackUnit 3   stack
Unit 3 stack
kalyanineve
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
Qundeel
 
Algorithm & data structures lec4&5
Algorithm & data structures lec4&5Algorithm & data structures lec4&5
Algorithm & data structures lec4&5
Abdul Khan
 
Data structures
Data structuresData structures
Data structures
Sneha Chopra
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Maher Alshammari
 
3.6 radix sort
3.6 radix sort3.6 radix sort
3.6 radix sort
Krish_ver2
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
Kuber Chandra
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
Trupti Agrawal
 
Array 2
Array 2Array 2
Array 2
Abbott
 
Array ADT(Abstract Data Type)|Data Structure
Array ADT(Abstract Data Type)|Data StructureArray ADT(Abstract Data Type)|Data Structure
Array ADT(Abstract Data Type)|Data Structure
Akash Gaur
 
Query hierarchical data the easy way, with CTEs
Query hierarchical data the easy way, with CTEsQuery hierarchical data the easy way, with CTEs
Query hierarchical data the easy way, with CTEs
MariaDB plc
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
Zidny Nafan
 
Counting Sort Lowerbound
Counting Sort LowerboundCounting Sort Lowerbound
Counting Sort Lowerbound
despicable me
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
Tareq Hasan
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
iqbalphy1
 
SQL Issue
SQL IssueSQL Issue
SQL Issue
Mary Clemons
 
Radix Sort
Radix SortRadix Sort
Radix Sort
Faiza Saleem
 
15 unionfind
15 unionfind15 unionfind
15 unionfind
Carlos andré dantas
 

What's hot (20)

Quicksort Algorithm..simply defined through animations..!!
Quicksort Algorithm..simply defined through animations..!!Quicksort Algorithm..simply defined through animations..!!
Quicksort Algorithm..simply defined through animations..!!
 
Radix sort
Radix sortRadix sort
Radix sort
 
Unit 3 stack
Unit 3   stackUnit 3   stack
Unit 3 stack
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
 
Algorithm & data structures lec4&5
Algorithm & data structures lec4&5Algorithm & data structures lec4&5
Algorithm & data structures lec4&5
 
Data structures
Data structuresData structures
Data structures
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
3.6 radix sort
3.6 radix sort3.6 radix sort
3.6 radix sort
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Array 2
Array 2Array 2
Array 2
 
Array ADT(Abstract Data Type)|Data Structure
Array ADT(Abstract Data Type)|Data StructureArray ADT(Abstract Data Type)|Data Structure
Array ADT(Abstract Data Type)|Data Structure
 
Query hierarchical data the easy way, with CTEs
Query hierarchical data the easy way, with CTEsQuery hierarchical data the easy way, with CTEs
Query hierarchical data the easy way, with CTEs
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
 
Counting Sort Lowerbound
Counting Sort LowerboundCounting Sort Lowerbound
Counting Sort Lowerbound
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
SQL Issue
SQL IssueSQL Issue
SQL Issue
 
Radix Sort
Radix SortRadix Sort
Radix Sort
 
15 unionfind
15 unionfind15 unionfind
15 unionfind
 

Viewers also liked

MS SQL Server 2008, Implementation and Maintenance
MS SQL Server 2008, Implementation and MaintenanceMS SQL Server 2008, Implementation and Maintenance
MS SQL Server 2008, Implementation and Maintenance
Vitaliy Fursov
 
Sigir12 tutorial: Query Perfromance Prediction for IR
Sigir12 tutorial: Query Perfromance Prediction for IRSigir12 tutorial: Query Perfromance Prediction for IR
Sigir12 tutorial: Query Perfromance Prediction for IR
David Carmel
 
Find and be Found: Information Retrieval at LinkedIn
Find and be Found: Information Retrieval at LinkedInFind and be Found: Information Retrieval at LinkedIn
Find and be Found: Information Retrieval at LinkedIn
Daniel Tunkelang
 
Password based door locksystem
Password  based door locksystemPassword  based door locksystem
Password based door locksystem
UVSofts Technologies
 
Fast, Lenient, and Accurate – Building Personalized Instant Search Experience...
Fast, Lenient, and Accurate – Building Personalized Instant Search Experience...Fast, Lenient, and Accurate – Building Personalized Instant Search Experience...
Fast, Lenient, and Accurate – Building Personalized Instant Search Experience...
Abhimanyu Lad
 
Er diagram practical examples
Er diagram practical examplesEr diagram practical examples
Er diagram practical examples
Rahul Khanwani
 
Erd examples
Erd examplesErd examples
Erd examples
Pramod Redekar
 
Password based door locking system
Password based door locking systemPassword based door locking system
Password based door locking system
Arjun Singh
 
Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)
Mudasir Qazi
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
Shakila Mahjabin
 
How to Draw an Effective ER diagram
How to Draw an Effective ER diagramHow to Draw an Effective ER diagram
How to Draw an Effective ER diagram
Tech_MX
 
Data encryption, Description, DES
Data encryption, Description, DESData encryption, Description, DES
Data encryption, Description, DES
Huawei Technologies
 
Cryptography
CryptographyCryptography
Cryptography
Sidharth Mohapatra
 
Cryptography
CryptographyCryptography
Cryptography
Shivanand Arur
 
Exploiting Wikipedia for Information Retrieval Tasks, SIGIR Tutorial
Exploiting Wikipedia for Information Retrieval Tasks, SIGIR TutorialExploiting Wikipedia for Information Retrieval Tasks, SIGIR Tutorial
Exploiting Wikipedia for Information Retrieval Tasks, SIGIR Tutorial
Victor Makarenkov
 
Erd practice exercises
Erd practice exercisesErd practice exercises
Erd practice exercises
Jennifer Polack
 
Data mining
Data miningData mining
Data mining
Akannsha Totewar
 
Encryption presentation final
Encryption presentation finalEncryption presentation final
Encryption presentation final
adrigee12
 
Project ppt
Project pptProject ppt
Project ppt
Rahul Yadav
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)
tameemyousaf
 

Viewers also liked (20)

MS SQL Server 2008, Implementation and Maintenance
MS SQL Server 2008, Implementation and MaintenanceMS SQL Server 2008, Implementation and Maintenance
MS SQL Server 2008, Implementation and Maintenance
 
Sigir12 tutorial: Query Perfromance Prediction for IR
Sigir12 tutorial: Query Perfromance Prediction for IRSigir12 tutorial: Query Perfromance Prediction for IR
Sigir12 tutorial: Query Perfromance Prediction for IR
 
Find and be Found: Information Retrieval at LinkedIn
Find and be Found: Information Retrieval at LinkedInFind and be Found: Information Retrieval at LinkedIn
Find and be Found: Information Retrieval at LinkedIn
 
Password based door locksystem
Password  based door locksystemPassword  based door locksystem
Password based door locksystem
 
Fast, Lenient, and Accurate – Building Personalized Instant Search Experience...
Fast, Lenient, and Accurate – Building Personalized Instant Search Experience...Fast, Lenient, and Accurate – Building Personalized Instant Search Experience...
Fast, Lenient, and Accurate – Building Personalized Instant Search Experience...
 
Er diagram practical examples
Er diagram practical examplesEr diagram practical examples
Er diagram practical examples
 
Erd examples
Erd examplesErd examples
Erd examples
 
Password based door locking system
Password based door locking systemPassword based door locking system
Password based door locking system
 
Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
How to Draw an Effective ER diagram
How to Draw an Effective ER diagramHow to Draw an Effective ER diagram
How to Draw an Effective ER diagram
 
Data encryption, Description, DES
Data encryption, Description, DESData encryption, Description, DES
Data encryption, Description, DES
 
Cryptography
CryptographyCryptography
Cryptography
 
Cryptography
CryptographyCryptography
Cryptography
 
Exploiting Wikipedia for Information Retrieval Tasks, SIGIR Tutorial
Exploiting Wikipedia for Information Retrieval Tasks, SIGIR TutorialExploiting Wikipedia for Information Retrieval Tasks, SIGIR Tutorial
Exploiting Wikipedia for Information Retrieval Tasks, SIGIR Tutorial
 
Erd practice exercises
Erd practice exercisesErd practice exercises
Erd practice exercises
 
Data mining
Data miningData mining
Data mining
 
Encryption presentation final
Encryption presentation finalEncryption presentation final
Encryption presentation final
 
Project ppt
Project pptProject ppt
Project ppt
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)
 

Similar to Sql Server Query Parameterization

Query parameterization
Query parameterizationQuery parameterization
Query parameterization
Riteshkiit
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
Riteshkiit
 
Presentation interpreting execution plans for sql statements
Presentation    interpreting execution plans for sql statementsPresentation    interpreting execution plans for sql statements
Presentation interpreting execution plans for sql statements
xKinAnx
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
Riteshkiit
 
Oracle SQL Advanced
Oracle SQL AdvancedOracle SQL Advanced
Oracle SQL Advanced
Dhananjay Goel
 
MySQL Performance Optimization
MySQL Performance OptimizationMySQL Performance Optimization
MySQL Performance Optimization
Mindfire Solutions
 
MySQL performance tuning
MySQL performance tuningMySQL performance tuning
MySQL performance tuning
Anurag Srivastava
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
uncleRhyme
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
paulguerin
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guideline
Sidney Chen
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluation
avniS
 
Statistics
StatisticsStatistics
Statistics
Riteshkiit
 
K-Means Algorithm Implementation In python
K-Means Algorithm Implementation In pythonK-Means Algorithm Implementation In python
K-Means Algorithm Implementation In python
Afzal Ahmad
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the Server
devObjective
 
Sql killedserver
Sql killedserverSql killedserver
Sql killedserver
ColdFusionConference
 
Chapter15
Chapter15Chapter15
Chapter15
gourab87
 
Introduction to Databases - query optimizations for MySQL
Introduction to Databases - query optimizations for MySQLIntroduction to Databases - query optimizations for MySQL
Introduction to Databases - query optimizations for MySQL
Márton Kodok
 
Part3 Explain the Explain Plan
Part3 Explain the Explain PlanPart3 Explain the Explain Plan
Part3 Explain the Explain Plan
Maria Colgan
 
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
Edgar Alejandro Villegas
 
Pandas csv
Pandas csvPandas csv
Pandas csv
Devashish Kumar
 

Similar to Sql Server Query Parameterization (20)

Query parameterization
Query parameterizationQuery parameterization
Query parameterization
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
Presentation interpreting execution plans for sql statements
Presentation    interpreting execution plans for sql statementsPresentation    interpreting execution plans for sql statements
Presentation interpreting execution plans for sql statements
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
Oracle SQL Advanced
Oracle SQL AdvancedOracle SQL Advanced
Oracle SQL Advanced
 
MySQL Performance Optimization
MySQL Performance OptimizationMySQL Performance Optimization
MySQL Performance Optimization
 
MySQL performance tuning
MySQL performance tuningMySQL performance tuning
MySQL performance tuning
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guideline
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluation
 
Statistics
StatisticsStatistics
Statistics
 
K-Means Algorithm Implementation In python
K-Means Algorithm Implementation In pythonK-Means Algorithm Implementation In python
K-Means Algorithm Implementation In python
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the Server
 
Sql killedserver
Sql killedserverSql killedserver
Sql killedserver
 
Chapter15
Chapter15Chapter15
Chapter15
 
Introduction to Databases - query optimizations for MySQL
Introduction to Databases - query optimizations for MySQLIntroduction to Databases - query optimizations for MySQL
Introduction to Databases - query optimizations for MySQL
 
Part3 Explain the Explain Plan
Part3 Explain the Explain PlanPart3 Explain the Explain Plan
Part3 Explain the Explain Plan
 
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
 
Pandas csv
Pandas csvPandas csv
Pandas csv
 

More from Mindfire Solutions

Physician Search and Review
Physician Search and ReviewPhysician Search and Review
Physician Search and Review
Mindfire Solutions
 
diet management app
diet management appdiet management app
diet management app
Mindfire Solutions
 
Business Technology Solution
Business Technology SolutionBusiness Technology Solution
Business Technology Solution
Mindfire Solutions
 
Remote Health Monitoring
Remote Health MonitoringRemote Health Monitoring
Remote Health Monitoring
Mindfire Solutions
 
Influencer Marketing Solution
Influencer Marketing SolutionInfluencer Marketing Solution
Influencer Marketing Solution
Mindfire Solutions
 
ELMAH
ELMAHELMAH
High Availability of Azure Applications
High Availability of Azure ApplicationsHigh Availability of Azure Applications
High Availability of Azure Applications
Mindfire Solutions
 
IOT Hands On
IOT Hands OnIOT Hands On
IOT Hands On
Mindfire Solutions
 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
Mindfire Solutions
 
Oracle Sql Developer-Getting Started
Oracle Sql Developer-Getting StartedOracle Sql Developer-Getting Started
Oracle Sql Developer-Getting Started
Mindfire Solutions
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
Mindfire Solutions
 
Introduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/MacIntroduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/Mac
Mindfire Solutions
 
LINQPad - utility Tool
LINQPad - utility ToolLINQPad - utility Tool
LINQPad - utility Tool
Mindfire Solutions
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
Mindfire Solutions
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
Mindfire Solutions
 
Material Design in Android
Material Design in AndroidMaterial Design in Android
Material Design in Android
Mindfire Solutions
 
Introduction to OData
Introduction to ODataIntroduction to OData
Introduction to OData
Mindfire Solutions
 
Ext js Part 2- MVC
Ext js Part 2- MVCExt js Part 2- MVC
Ext js Part 2- MVC
Mindfire Solutions
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
Mindfire Solutions
 
Spring Security Introduction
Spring Security IntroductionSpring Security Introduction
Spring Security Introduction
Mindfire Solutions
 

More from Mindfire Solutions (20)

Physician Search and Review
Physician Search and ReviewPhysician Search and Review
Physician Search and Review
 
diet management app
diet management appdiet management app
diet management app
 
Business Technology Solution
Business Technology SolutionBusiness Technology Solution
Business Technology Solution
 
Remote Health Monitoring
Remote Health MonitoringRemote Health Monitoring
Remote Health Monitoring
 
Influencer Marketing Solution
Influencer Marketing SolutionInfluencer Marketing Solution
Influencer Marketing Solution
 
ELMAH
ELMAHELMAH
ELMAH
 
High Availability of Azure Applications
High Availability of Azure ApplicationsHigh Availability of Azure Applications
High Availability of Azure Applications
 
IOT Hands On
IOT Hands OnIOT Hands On
IOT Hands On
 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
 
Oracle Sql Developer-Getting Started
Oracle Sql Developer-Getting StartedOracle Sql Developer-Getting Started
Oracle Sql Developer-Getting Started
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
 
Introduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/MacIntroduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/Mac
 
LINQPad - utility Tool
LINQPad - utility ToolLINQPad - utility Tool
LINQPad - utility Tool
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Material Design in Android
Material Design in AndroidMaterial Design in Android
Material Design in Android
 
Introduction to OData
Introduction to ODataIntroduction to OData
Introduction to OData
 
Ext js Part 2- MVC
Ext js Part 2- MVCExt js Part 2- MVC
Ext js Part 2- MVC
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Spring Security Introduction
Spring Security IntroductionSpring Security Introduction
Spring Security Introduction
 

Recently uploaded

Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Erasmo Purificato
 
K2G - Insurtech Innovation EMEA Award 2024
K2G - Insurtech Innovation EMEA Award 2024K2G - Insurtech Innovation EMEA Award 2024
K2G - Insurtech Innovation EMEA Award 2024
The Digital Insurer
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
huseindihon
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
shanthidl1
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
Larry Smarr
 
What's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdfWhat's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdf
SeasiaInfotech2
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
BookNet Canada
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
FellyciaHikmahwarani
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
Aurora Consulting
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
SynapseIndia
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Chris Swan
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
Matthew Sinclair
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
Mark Billinghurst
 
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALLBLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
Liveplex
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
Enterprise Wired
 
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
Stephanie Beckett
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
Eric D. Schabell
 
Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024
The Digital Insurer
 

Recently uploaded (20)

Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
 
K2G - Insurtech Innovation EMEA Award 2024
K2G - Insurtech Innovation EMEA Award 2024K2G - Insurtech Innovation EMEA Award 2024
K2G - Insurtech Innovation EMEA Award 2024
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
 
What's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdfWhat's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdf
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
 
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALLBLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
 
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
 
Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024
 

Sql Server Query Parameterization

  • 1. SQL Server Query Parameterization  Query Tuning Ritesh Kumar Skype: mfs_ritesh Blog: http://exacthelp.blogspot.com/
  • 2. INDEX  Adhoc Query  Predicates Order  Execution Plan  Query Optimizer  Parameter Sniffing  Indexes  Statistics  Database Engine Tuning Advisor
  • 3. Adhoc Query q Any non-parameterized queries are called addhoc queries. For example : q SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 100 q In sql server if we execute a sql query it goes through two steps just like any other programming languages: q Compilation q Execution
  • 4. Properties Of Addhoc Queries q Case sensitive q Space sensitive q Parameter sensitive  q Sql server treats two same sql queries of different parameters as a two different sql statements. For example: q SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 1 q SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 2
  • 5. Effect Of Faulty C# Code  Sql server has took extra n * (Compilation time) ms to display records  Extra time to insert records in cached plans.  Sql server has to frequently fire a job to delete the cached plan since it will reach the max limit very soon.  It will not only decrease the performance of this sql query but all sql queries of other applications since this faulty code will force to delete cached query plans of other sql statements.
  • 6. Predicates Order q Does order of predicates matters in WHERE clause? q WHERE vcLanguage = 'English' AND ntAge = 12 q WHERE ntAge = 12 AND vcLanguage = 'English'
  • 9. Query Optimizer The query optimizer in SQL Server is cost-based. It includes: q Cost for using different resources (CPU and IO) q Total execution time   It determines the cost by using:  Cardinality: The total number of rows processed at each level of a query plan with the help of histograms , predicates and constraint  Cost model of the algorithm: To perform various operations like sorting, searching, comparisons etc.
  • 10. Parameter Sniffing  Sql server generates execution paln according to the first parameter  This execution plan may bad for other parameters.   Solution:  Create multiples stored procedures.  Use optimizer for query hints.
  • 11. What Is An Index ? q Index is a way to organize data to make searching, sorting and grouping faster. q we need indexing when : q WHERE, ON, HAVING clause (Searching) q ORDER BY clause (Sorting) q GROUP BY clause (Grouping) etc.
  • 12. Table Scan SELECT * FROM Student WHERE RollNo = 111 Time complexity of table scan is : O(n) RollNo Name Country Age 101 Greg UK 23 102 Sachin India 21 103 Akaram Pakistan 22 107 Miyabi China 18 108 Marry Russia 27 109 Scott USA 31 110 Benazir Banglades 17 111 Miyabi Japan 24 112 Rahul India 27 113 Nicolus France 19
  • 13. Types Of Index q Table without any index is called Heap q There are two type of index: q Clustered index q Non-Clustered index
  • 14. Clustered Index  When we create a clustered index on any table physical organization of table is changed.  Now data of table is stored as a balanced tree(B tree). CREATE UNIQUE [CLUSTERED] INDEX <Name> ON <ObjectName>( <ColumnName>  [ASC | DESC ] [ ,...n ] )
  • 16. Types Of Scanning  Table scan: It is very slow can and it is used only if table has not any clustered index.  Index scan: It is also slow scan. It is used when table has clustered index and either in WHERE clause non-key columns are present or query has not been covered (will discuss later) or both.  Index Seek: It is very fast. Our goal is to achieve this.
  • 17. Clustered Index  If we create table with primary key, sql server automatically creates clustered index on that table  A table can have only one clustered index .  Physical order of rows of table is same as logical order of key columns of clustered index.
  • 18. Terms Of Execution Plan  Predicate: It is condition in WHERE clause which is either nonkey column or column which has not been covered.  Object: It is name of source from where it getting the data. It can be name of table, Clustered index or non-clustered index  Output list: It is name of the columns which is getting from object.  Seek Predicate: It is condition in WHERE clause which is either key column or fully covered.
  • 19. Non-Clustered Index  It is logical organization of data of table. A non-clustered index can be of two types. q Heap q Based on clustered index.  If table has clustered index then leaf node of non-clustered index keeps the key columns of clustered index.  If the table has not any clustered index then leaf node of nonclustered index keeps RID which unique of each row of table.
  • 22. Covering Of Queries   We can specify maximum 16 column names. Sum of size of the columns cannot be more than 900 bytes.  All columns must belong to same table.  Data type of columns cannot be ntext, text, varchar (max), nvarchar (max), varbinary (max), xml, or image  It cannot be non-deterministic computed column.
  • 23. Statistics Analysis  The query optimizer uses statistics to create query plans that improve query performance  A correct statistics will lead to high-quality query plan.  The query optimizer determines when statistics might be out-ofdate by counting the number of data modifications since the last statistics update and comparing the number of modifications to a threshold.
  • 24. Auto Create Statistics  Default setting of auto create statistics is ON.  It creates when:  Clustered and non clustered Index is created  Select query is executed.  Auto create and updates applies strictly to singlecolumn statistics.
  • 25. Why Query 2 Is Performing Better q If we perform following operations on field of any table in query predicate: q Using any system function or user defined function q Scalar operation like addition, multiplication etc. q Type casting q In this situation sql server query optimizer is not able to estimate correct cardinality using statistics.
  • 26. To Improve Cardinality  If possible, simplify expressions with constants in them.  If possible, don't perform any operation on the any field of a table in WHERE Clause, ON Clause, HAVING Clause  Don't use local variables in WHERE Clause, ON Clause, HAVING Clause.   If there is any cross relationship among fields or there is a complex expression in a field in a query predicates, it is better to create a computed column and then create a non-clustered index on it.
  • 27. To Improve Cardinality  If possible, don't update the value of parameters of a function or stored procedure before using in sql statement  Use OPTIMIZE FOR clause when you want to optimize a sql query on the basis of specific parameter value.  If you want to update the value parameter of a stored procedure or a function create a similar procedure or function and execute it form base procedure or function by passing the updated value as a parameter.   Create user defined multi column statistics if query predicates have more than one fields of a table.
  • 28. SQL Server Tools  Sql query profiler  Database Tuning Advisor  Client Statistics  Resource Governor  Data Collections