SlideShare a Scribd company logo
8
Most read
10
Most read
QUERY EVALUATION AND
OPTIMIZATION
Presented by,
R.RAMADEVI
MSc(CS&IT)
Nadar Saraswathi college of arts & science
vadapudupatti ,Theni.
QUERY PROCESSING
• Query processing refers to the range of activities involved in
extracting the data from a database
• These activities include translation of queries expressed in
high-level database languages into expressions that can be
implemented at the physical level of the file system, a variety
of query-optimizing transformations and actual evaluation of
queries.
Selection operation
• The file scan is the lowest level operator to access
data .
• File scans are search algorithm that locate and
retrieve records that fulfill a selection condition.
• Algorithm A1 (linear search). Scan each file block and test all records to
see whether they satisfy the selection condition.
– Cost estimate = br block transfers + 1 seek
• br denotes number of blocks containing records from relation r
– If selection is on a key attribute, can stop on finding record
• cost = (br /2) block transfers + 1 seek
– Linear search can be applied regardless of
• selection condition or
• ordering of records in the file, or
• availability of indices
Selections Using Indices
• Index scan – search algorithms that use an index
– selection condition must be on search-key of index.
• A2 (primary index, equality on key). Retrieve a single
record that satisfies the corresponding equality condition
– Cost = (hi + 1) * (tT + tS)
• A3 (primary index, equality on nonkey) Retrieve multiple
records.
– Records will be on consecutive blocks
• Let b = number of blocks containing matching records
– Cost = hi * (tT + tS) + tS + tT * b
Selections Using Indices
• A4 (secondary index, equality on nonkey).
– Retrieve a single record if the search-key is a candidate key
• Cost = (hi + 1) * (tT + tS)
– Retrieve multiple records if search-key is not a candidate
key
• each of n matching records may be on a different block
• Cost = (hi + n) * (tT + tS)
– Can be very expensive!
Selections Involving Comparisons
• Can implement selections of the form AV (r) or A  V(r) by
using
– a linear file scan,
– or by using indices in the following ways:
• A5 (primary index, comparison). (Relation is sorted on A)
• For A  V(r) use index to find first tuple  v and scan
relation sequentially from there
• For AV (r) just scan relation sequentially till first tuple
> v; do not use index
• A6 (secondary index, comparison).
• In either case, retrieve records that are pointed to
– requires an I/O for each record
– Linear file scan may be cheaper
Implementation of Complex Selections
• Conjunction:
• A7 (conjunctive selection using one index).
– Select a combination of i and algorithms A1 through A7 that results in
the least cost for i (r).
– Test other conditions on tuple after fetching it into memory buffer.
• A8 (conjunctive selection using composite index).
– Use appropriate composite (multiple-key) index if available.
• A9 (conjunctive selection by intersection of identifiers).
– Requires indices with record pointers.
– Use corresponding index for each condition, and take intersection of all
the obtained sets of record pointers.
Sorting
• We may build an index on the relation, and then use the index
to read the relation in sorted order. May lead to one disk block
access for each tuple .
• For relations that fit in memory, techniques like quick sort can
be used. For relations that don’t fit in memory, external
sort-merge is a good choice.
Join Operation
• Several different algorithms to implement joins
– Nested-loop join
– Block nested-loop join
– Indexed nested-loop join
– Merge-join
– Hash-join
• Choice based on cost estimate
• Examples use the following information
– Number of records of student: 5,000 takes: 10,000
– Number of blocks of student: 100 takes: 400
Evaluation of Expressions
• Alternatives for evaluating an entire expression tree
– Materialization: generate results of an expression whose
inputs are relations or are already computed, materialize
(store) it on disk. Repeat.
– Pipelining: pass on tuples to parent operations even as an
operation is being executed
Query Optimization
• Alternative ways of evaluating a given query
– Equivalent expressions
– Different algorithms for each operation
An evaluation plan defines exactly what algorithm is used for
each operation, and how the execution of the operations is
coordinated.
THANK YOU

More Related Content

PPTX
Distributed database management system
PPT
13. Query Processing in DBMS
PPTX
Object relational database management system
PPTX
SQL, Embedded SQL, Dynamic SQL and SQLJ
PPTX
joins in database
PPTX
Object oriented database concepts
PDF
Query optimization in SQL
PPT
11 Database Concepts
Distributed database management system
13. Query Processing in DBMS
Object relational database management system
SQL, Embedded SQL, Dynamic SQL and SQLJ
joins in database
Object oriented database concepts
Query optimization in SQL
11 Database Concepts

What's hot (20)

PPTX
Transaction management DBMS
PPTX
Distributed database
PPTX
Data mining: Classification and prediction
PPTX
Object Relational Database Management System(ORDBMS)
PPTX
Structure of dbms
PPTX
Adbms 17 object query language
PPTX
Dbms Introduction and Basics
PPTX
Query optimization
PPT
PPTX
OLAP & DATA WAREHOUSE
PDF
Ddb 1.6-design issues
PPTX
Nested queries in database
ODP
Ms sql-server
PPTX
Database System Architectures
PPTX
Multidimensional data models
PPTX
Client server architecture
PPTX
distributed Computing system model
PPTX
SQL - Structured query language introduction
PPTX
Data Modeling PPT
Transaction management DBMS
Distributed database
Data mining: Classification and prediction
Object Relational Database Management System(ORDBMS)
Structure of dbms
Adbms 17 object query language
Dbms Introduction and Basics
Query optimization
OLAP & DATA WAREHOUSE
Ddb 1.6-design issues
Nested queries in database
Ms sql-server
Database System Architectures
Multidimensional data models
Client server architecture
distributed Computing system model
SQL - Structured query language introduction
Data Modeling PPT
Ad

Similar to Query evaluation and optimization (20)

PPTX
PDF
01Query Processing and Optimization-SUM25.pdf
PPTX
unit-2 Query processing and optimization,Query equivalence, Join strategies.pptx
PPTX
Query-porcessing-& Query optimization
PDF
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
PPT
Algorithm ch13.ppt
PPTX
RDBMS
PPT
Chapter2.ppt Algorithms Query processing and Optimization
PDF
CH5_Query Processing and Optimization.pdf
PPTX
Advanced Database Management System in Mtech
PDF
Chapter 2.pdf WND FWKJFW KSD;KFLWHFB ASNK
PPTX
Adbms 38 algorithms for select and join operations
PDF
8 query processing and optimization
PPTX
Korth_Query_processing.pptx
PPT
ch12.ppt
PPT
Query processing-and-optimization
PPTX
Lecture 5.pptx
01Query Processing and Optimization-SUM25.pdf
unit-2 Query processing and optimization,Query equivalence, Join strategies.pptx
Query-porcessing-& Query optimization
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Algorithm ch13.ppt
RDBMS
Chapter2.ppt Algorithms Query processing and Optimization
CH5_Query Processing and Optimization.pdf
Advanced Database Management System in Mtech
Chapter 2.pdf WND FWKJFW KSD;KFLWHFB ASNK
Adbms 38 algorithms for select and join operations
8 query processing and optimization
Korth_Query_processing.pptx
ch12.ppt
Query processing-and-optimization
Lecture 5.pptx
Ad

More from lavanya marichamy (17)

PPTX
Digital video
PPTX
Network design consideration
PPTX
Java servlets and CGI
PPTX
Data structure - traveling sales person and mesh algorithm
PPTX
Fundamentals and image compression models
PPTX
Software requirements specification
PPTX
Data mining primitives
PPTX
Memory Management
PPTX
Basic Computer Organisation And Design
PPTX
Register Transfer Language,Bus and Memory Transfer
PPTX
Arithmetic micro operations
PPTX
Recovery with concurrent transaction
PPTX
Pointer in c
PPTX
Dynamic memory allocation in c
PPTX
microcomputer architecture-Instruction formats
PPTX
IEEE STANDARED 802.5 LAN
PPTX
Broadband isdn and atm
Digital video
Network design consideration
Java servlets and CGI
Data structure - traveling sales person and mesh algorithm
Fundamentals and image compression models
Software requirements specification
Data mining primitives
Memory Management
Basic Computer Organisation And Design
Register Transfer Language,Bus and Memory Transfer
Arithmetic micro operations
Recovery with concurrent transaction
Pointer in c
Dynamic memory allocation in c
microcomputer architecture-Instruction formats
IEEE STANDARED 802.5 LAN
Broadband isdn and atm

Recently uploaded (20)

PDF
TR - Agricultural Crops Production NC III.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
master seminar digital applications in india
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Cell Types and Its function , kingdom of life
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Computing-Curriculum for Schools in Ghana
TR - Agricultural Crops Production NC III.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Microbial diseases, their pathogenesis and prophylaxis
FourierSeries-QuestionsWithAnswers(Part-A).pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
master seminar digital applications in india
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPH.pptx obstetrics and gynecology in nursing
VCE English Exam - Section C Student Revision Booklet
Basic Mud Logging Guide for educational purpose
Cell Types and Its function , kingdom of life
O5-L3 Freight Transport Ops (International) V1.pdf
Classroom Observation Tools for Teachers
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
GDM (1) (1).pptx small presentation for students
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Computing-Curriculum for Schools in Ghana

Query evaluation and optimization

  • 1. QUERY EVALUATION AND OPTIMIZATION Presented by, R.RAMADEVI MSc(CS&IT) Nadar Saraswathi college of arts & science vadapudupatti ,Theni.
  • 2. QUERY PROCESSING • Query processing refers to the range of activities involved in extracting the data from a database • These activities include translation of queries expressed in high-level database languages into expressions that can be implemented at the physical level of the file system, a variety of query-optimizing transformations and actual evaluation of queries.
  • 3. Selection operation • The file scan is the lowest level operator to access data . • File scans are search algorithm that locate and retrieve records that fulfill a selection condition. • Algorithm A1 (linear search). Scan each file block and test all records to see whether they satisfy the selection condition. – Cost estimate = br block transfers + 1 seek • br denotes number of blocks containing records from relation r – If selection is on a key attribute, can stop on finding record • cost = (br /2) block transfers + 1 seek – Linear search can be applied regardless of • selection condition or • ordering of records in the file, or • availability of indices
  • 4. Selections Using Indices • Index scan – search algorithms that use an index – selection condition must be on search-key of index. • A2 (primary index, equality on key). Retrieve a single record that satisfies the corresponding equality condition – Cost = (hi + 1) * (tT + tS) • A3 (primary index, equality on nonkey) Retrieve multiple records. – Records will be on consecutive blocks • Let b = number of blocks containing matching records – Cost = hi * (tT + tS) + tS + tT * b
  • 5. Selections Using Indices • A4 (secondary index, equality on nonkey). – Retrieve a single record if the search-key is a candidate key • Cost = (hi + 1) * (tT + tS) – Retrieve multiple records if search-key is not a candidate key • each of n matching records may be on a different block • Cost = (hi + n) * (tT + tS) – Can be very expensive!
  • 6. Selections Involving Comparisons • Can implement selections of the form AV (r) or A  V(r) by using – a linear file scan, – or by using indices in the following ways: • A5 (primary index, comparison). (Relation is sorted on A) • For A  V(r) use index to find first tuple  v and scan relation sequentially from there • For AV (r) just scan relation sequentially till first tuple > v; do not use index • A6 (secondary index, comparison). • In either case, retrieve records that are pointed to – requires an I/O for each record – Linear file scan may be cheaper
  • 7. Implementation of Complex Selections • Conjunction: • A7 (conjunctive selection using one index). – Select a combination of i and algorithms A1 through A7 that results in the least cost for i (r). – Test other conditions on tuple after fetching it into memory buffer. • A8 (conjunctive selection using composite index). – Use appropriate composite (multiple-key) index if available. • A9 (conjunctive selection by intersection of identifiers). – Requires indices with record pointers. – Use corresponding index for each condition, and take intersection of all the obtained sets of record pointers.
  • 8. Sorting • We may build an index on the relation, and then use the index to read the relation in sorted order. May lead to one disk block access for each tuple . • For relations that fit in memory, techniques like quick sort can be used. For relations that don’t fit in memory, external sort-merge is a good choice.
  • 9. Join Operation • Several different algorithms to implement joins – Nested-loop join – Block nested-loop join – Indexed nested-loop join – Merge-join – Hash-join • Choice based on cost estimate • Examples use the following information – Number of records of student: 5,000 takes: 10,000 – Number of blocks of student: 100 takes: 400
  • 10. Evaluation of Expressions • Alternatives for evaluating an entire expression tree – Materialization: generate results of an expression whose inputs are relations or are already computed, materialize (store) it on disk. Repeat. – Pipelining: pass on tuples to parent operations even as an operation is being executed
  • 11. Query Optimization • Alternative ways of evaluating a given query – Equivalent expressions – Different algorithms for each operation
  • 12. An evaluation plan defines exactly what algorithm is used for each operation, and how the execution of the operations is coordinated.