SlideShare una empresa de Scribd logo
1 de 11
SQL Query Performance Analysis

            Level 1
Addhoc Queries
Any non-Parameterized queries are called addhoc queries. For
example :

SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 100

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

• 1. Compilation
• 2. Execution
Properties of addhoc query
• Case sensitive
• Space sensitive
• Parameter sensitive

Sql severs treats two same sql query but of different parameters
as different sql statements. For example:

• SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 1
• SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 2
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 application since this faulty code will
  force to delete cached query plans of other sql statement.
Prepared queries
Example:

(@Msgid int)SELECT MsgID, Severity FROM SqlMessage WHERE
  MsgID = @Msgid

• It is not case, space and parameter sensitive and it is our goal.
Query Processing
• Non-Procedural: . SELECT, DELETE, UPDATE
  statements etc.
• a. Analyze the query.
• b. Get execution plan.
• b. Process the query.


• Procedural: Stored procedure, sql functions
  etc.
Query Optimizer
Query Optimizer
The query optimizer in SQL Server is cost-based. It includes:

1. Cost for using different resources (CPU and IO)
2. 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.
Execution Plan and Caching
• Query Plan
• Execution Context

• Database Engine uses a cost-based approach
  to determine which execution plans to remove
  from the procedure cache.
Assignments
• 1. Give any example in which join performs better
  than sub query.
• 2. Give me any example in which order matters in
  WHERE clause.
• 3. Give me any three examples which query
  returns same output but have different execution
  plan
http://msdn.microsoft.com/en-
  us/library/ms175913(v=sql.105).aspx
THANK YOU

Más contenido relacionado

La actualidad más candente

Exciting Features for SQL Devs in SQL 2012
Exciting Features for SQL Devs in SQL 2012Exciting Features for SQL Devs in SQL 2012
Exciting Features for SQL Devs in SQL 2012Brij Mishra
 
U-SQL Does SQL (SQLBits 2016)
U-SQL Does SQL (SQLBits 2016)U-SQL Does SQL (SQLBits 2016)
U-SQL Does SQL (SQLBits 2016)Michael Rys
 
Presentation on Data Structure
Presentation on Data StructurePresentation on Data Structure
Presentation on Data StructureMuntasirMuhit
 
Operations guide29
Operations guide29Operations guide29
Operations guide29Vcoi Vit
 
Tuning Up Apache Phoenix. Secondary Indexes
Tuning Up Apache Phoenix. Secondary IndexesTuning Up Apache Phoenix. Secondary Indexes
Tuning Up Apache Phoenix. Secondary IndexesVlad Krava
 
Map reduce presentation
Map reduce presentationMap reduce presentation
Map reduce presentationAhmad El Tawil
 
MySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesMySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesIsaac Mosquera
 
Cluster computing
Cluster computingCluster computing
Cluster computingbrainbix
 
Analysis of mysql and postgresql
Analysis of mysql and postgresqlAnalysis of mysql and postgresql
Analysis of mysql and postgresqlAsif Anik
 
Repartition join in mapreduce
Repartition join in mapreduceRepartition join in mapreduce
Repartition join in mapreduceUday Vakalapudi
 
Operations guide34
Operations guide34Operations guide34
Operations guide34Vcoi Vit
 
Did you mean 'Galene'?
Did you mean 'Galene'?Did you mean 'Galene'?
Did you mean 'Galene'?Azeem Mohammad
 
Mapreduce script
Mapreduce scriptMapreduce script
Mapreduce scriptHaripritha
 
Horizontal Aggregations in SQL to Prepare Data Sets for Data Mining Analysis
Horizontal Aggregations in SQL to Prepare Data Sets for Data  Mining AnalysisHorizontal Aggregations in SQL to Prepare Data Sets for Data  Mining Analysis
Horizontal Aggregations in SQL to Prepare Data Sets for Data Mining AnalysisIOSR Journals
 

La actualidad más candente (20)

Exciting Features for SQL Devs in SQL 2012
Exciting Features for SQL Devs in SQL 2012Exciting Features for SQL Devs in SQL 2012
Exciting Features for SQL Devs in SQL 2012
 
U-SQL Does SQL (SQLBits 2016)
U-SQL Does SQL (SQLBits 2016)U-SQL Does SQL (SQLBits 2016)
U-SQL Does SQL (SQLBits 2016)
 
Presentation on Data Structure
Presentation on Data StructurePresentation on Data Structure
Presentation on Data Structure
 
Operations guide29
Operations guide29Operations guide29
Operations guide29
 
Remus_3_0
Remus_3_0Remus_3_0
Remus_3_0
 
Tuning Up Apache Phoenix. Secondary Indexes
Tuning Up Apache Phoenix. Secondary IndexesTuning Up Apache Phoenix. Secondary Indexes
Tuning Up Apache Phoenix. Secondary Indexes
 
Map reduce presentation
Map reduce presentationMap reduce presentation
Map reduce presentation
 
SQLDay2013_MarcinSzeliga_StoredProcedures
SQLDay2013_MarcinSzeliga_StoredProceduresSQLDay2013_MarcinSzeliga_StoredProcedures
SQLDay2013_MarcinSzeliga_StoredProcedures
 
Java spring batch
Java spring batchJava spring batch
Java spring batch
 
MySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesMySQL Performance Tips & Best Practices
MySQL Performance Tips & Best Practices
 
Cluster computing
Cluster computingCluster computing
Cluster computing
 
Analysis of mysql and postgresql
Analysis of mysql and postgresqlAnalysis of mysql and postgresql
Analysis of mysql and postgresql
 
Repartition join in mapreduce
Repartition join in mapreduceRepartition join in mapreduce
Repartition join in mapreduce
 
Operations guide34
Operations guide34Operations guide34
Operations guide34
 
Did you mean 'Galene'?
Did you mean 'Galene'?Did you mean 'Galene'?
Did you mean 'Galene'?
 
Mapreduce script
Mapreduce scriptMapreduce script
Mapreduce script
 
Spring batch in action
Spring batch in actionSpring batch in action
Spring batch in action
 
Hadoop map reduce v2
Hadoop map reduce v2Hadoop map reduce v2
Hadoop map reduce v2
 
Horizontal Aggregations in SQL to Prepare Data Sets for Data Mining Analysis
Horizontal Aggregations in SQL to Prepare Data Sets for Data  Mining AnalysisHorizontal Aggregations in SQL to Prepare Data Sets for Data  Mining Analysis
Horizontal Aggregations in SQL to Prepare Data Sets for Data Mining Analysis
 
Cloudant
CloudantCloudant
Cloudant
 

Similar a Addhoc query

Adapting and adopting spm v04
Adapting and adopting spm v04Adapting and adopting spm v04
Adapting and adopting spm v04Carlos Sierra
 
Sql parametrized queries
Sql parametrized queriesSql parametrized queries
Sql parametrized queriesHadi Fadlallah
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1sqlserver.co.il
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptxKareemBullard1
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysisRiteshkiit
 
An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1Navneet Upneja
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysisRiteshkiit
 
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse SupportOracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse Supportnkarag
 
Migration strategies 4
Migration strategies 4Migration strategies 4
Migration strategies 4Wenhua Wang
 
World2016_T5_S5_SQLServerFunctionalOverview
World2016_T5_S5_SQLServerFunctionalOverviewWorld2016_T5_S5_SQLServerFunctionalOverview
World2016_T5_S5_SQLServerFunctionalOverviewFarah Omer
 
Predicting Flights with Azure Databricks
Predicting Flights with Azure DatabricksPredicting Flights with Azure Databricks
Predicting Flights with Azure DatabricksSarah Dutkiewicz
 
Enabling Model Testing of Cyber Physical Systems
Enabling Model Testing of Cyber Physical SystemsEnabling Model Testing of Cyber Physical Systems
Enabling Model Testing of Cyber Physical SystemsLionel Briand
 
261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part i261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part iNaviSoft
 
Benchmarking Solr Performance at Scale
Benchmarking Solr Performance at ScaleBenchmarking Solr Performance at Scale
Benchmarking Solr Performance at Scalethelabdude
 
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"Fwdays
 
Improving Batch-Process Testing Techniques with a Domain-Specific Language
Improving Batch-Process Testing Techniques with a Domain-Specific LanguageImproving Batch-Process Testing Techniques with a Domain-Specific Language
Improving Batch-Process Testing Techniques with a Domain-Specific LanguageDr. Spock
 
Time-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy QueriesTime-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy QueriesChema Alonso
 

Similar a Addhoc query (20)

Adapting and adopting spm v04
Adapting and adopting spm v04Adapting and adopting spm v04
Adapting and adopting spm v04
 
Sql parametrized queries
Sql parametrized queriesSql parametrized queries
Sql parametrized queries
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
Distributed query deep dive conor cunningham
Distributed query deep dive   conor cunninghamDistributed query deep dive   conor cunningham
Distributed query deep dive conor cunningham
 
SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
CQRS
CQRSCQRS
CQRS
 
An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse SupportOracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
 
Migration strategies 4
Migration strategies 4Migration strategies 4
Migration strategies 4
 
World2016_T5_S5_SQLServerFunctionalOverview
World2016_T5_S5_SQLServerFunctionalOverviewWorld2016_T5_S5_SQLServerFunctionalOverview
World2016_T5_S5_SQLServerFunctionalOverview
 
Predicting Flights with Azure Databricks
Predicting Flights with Azure DatabricksPredicting Flights with Azure Databricks
Predicting Flights with Azure Databricks
 
Enabling Model Testing of Cyber Physical Systems
Enabling Model Testing of Cyber Physical SystemsEnabling Model Testing of Cyber Physical Systems
Enabling Model Testing of Cyber Physical Systems
 
261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part i261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part i
 
Benchmarking Solr Performance at Scale
Benchmarking Solr Performance at ScaleBenchmarking Solr Performance at Scale
Benchmarking Solr Performance at Scale
 
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
 
Improving Batch-Process Testing Techniques with a Domain-Specific Language
Improving Batch-Process Testing Techniques with a Domain-Specific LanguageImproving Batch-Process Testing Techniques with a Domain-Specific Language
Improving Batch-Process Testing Techniques with a Domain-Specific Language
 
Time-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy QueriesTime-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy Queries
 

Más de Riteshkiit

Más de Riteshkiit (10)

Backup and restore
Backup and restoreBackup and restore
Backup and restore
 
Database index
Database indexDatabase index
Database index
 
Query parameterization
Query parameterizationQuery parameterization
Query parameterization
 
Index_2
Index_2Index_2
Index_2
 
Order by and join
Order by and joinOrder by and join
Order by and join
 
Database design
Database designDatabase design
Database design
 
Index
IndexIndex
Index
 
Sql server JOIN
Sql server JOINSql server JOIN
Sql server JOIN
 
Sql server 2
Sql server 2Sql server 2
Sql server 2
 
Topics
TopicsTopics
Topics
 

Último

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Último (20)

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

Addhoc query

  • 1. SQL Query Performance Analysis Level 1
  • 2. Addhoc Queries Any non-Parameterized queries are called addhoc queries. For example : SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 100 In sql server if we execute a sql query it goes through two steps just like any other programming languages: • 1. Compilation • 2. Execution
  • 3. Properties of addhoc query • Case sensitive • Space sensitive • Parameter sensitive Sql severs treats two same sql query but of different parameters as different sql statements. For example: • SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 1 • SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 2
  • 4. 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 application since this faulty code will force to delete cached query plans of other sql statement.
  • 5. Prepared queries Example: (@Msgid int)SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = @Msgid • It is not case, space and parameter sensitive and it is our goal.
  • 6. Query Processing • Non-Procedural: . SELECT, DELETE, UPDATE statements etc. • a. Analyze the query. • b. Get execution plan. • b. Process the query. • Procedural: Stored procedure, sql functions etc.
  • 8. Query Optimizer The query optimizer in SQL Server is cost-based. It includes: 1. Cost for using different resources (CPU and IO) 2. 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.
  • 9. Execution Plan and Caching • Query Plan • Execution Context • Database Engine uses a cost-based approach to determine which execution plans to remove from the procedure cache.
  • 10. Assignments • 1. Give any example in which join performs better than sub query. • 2. Give me any example in which order matters in WHERE clause. • 3. Give me any three examples which query returns same output but have different execution plan http://msdn.microsoft.com/en- us/library/ms175913(v=sql.105).aspx