1. Trang chủ
  2. » Công Nghệ Thông Tin

slide cơ sở dữ liệu tiếng anh chương (21) query processing transparencies

112 687 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Chapter 21

  • Chapter 21 - Objectives

  • Slide 3

  • Slide 4

  • Introduction

  • Slide 6

  • Query Processing

  • Query Optimization

  • Example 21.1 - Different Strategies

  • Slide 10

  • Slide 11

  • Example 21.1 - Cost Comparison

  • Phases of Query Processing

  • Slide 14

  • Dynamic versus Static Optimization

  • Slide 16

  • Query Decomposition

  • Analysis

  • Analysis - Example

  • Slide 20

  • Example 21.1 - R.A.T.

  • Normalization

  • Semantic Analysis

  • Slide 24

  • Semantic Analysis - Normalized Attribute Connection Graph

  • Example 21.2 - Checking Semantic Correctness

  • Slide 27

  • Slide 28

  • Simplification

  • Transformation Rules for RA Operations

  • Slide 31

  • Slide 32

  • Slide 33

  • Slide 34

  • Slide 35

  • Slide 36

  • Slide 37

  • Slide 38

  • Slide 39

  • Slide 40

  • Slide 41

  • Slide 42

  • Slide 43

  • Slide 44

  • Slide 45

  • Example 21.3 Use of Transformation Rules

  • Slide 47

  • Slide 48

  • Slide 49

  • Heuristical Processing Strategies

  • Slide 51

  • Cost Estimation for RA Operations

  • Database Statistics

  • Typical Statistics for Relation R

  • Typical Statistics for Attribute A of Relation R

  • Statistics for Multilevel Index I on Attribute A

  • Selection Operation

  • Slide 58

  • Estimating Cardinality of Selection

  • Linear Search (Ordered File, No Index)

  • Binary Search (Ordered File, No Index)

  • Equality of Hash Key

  • Equality Condition on Primary Key

  • Inequality Condition on Primary Key

  • Equality Condition on Clustering Index

  • Equality Condition on Non-Clustering Index

  • Inequality Condition on a Secondary B+-Tree Index

  • Composite Predicates - Conjunction without Disjunction

  • Composite Predicates - Selections with Disjunction

  • Join Operation

  • Estimating Cardinality of Join

  • Slide 72

  • Block Nested Loop Join

  • Slide 74

  • Indexed Nested Loop Join

  • Sort-Merge Join

  • Slide 77

  • Hash Join

  • Projection Operation

  • Estimating Cardinality of Projection

  • Duplicate Elimination using Sorting

  • Duplicate Elimination using Hashing

  • Set Operations

  • Estimating Cardinality of Set Operations

  • Aggregate Operations

  • Slide 86

  • Enumeration of Alternative Strategies

  • Pipelining

  • Types of Trees

  • Slide 90

  • Physical Operators & Strategies

  • Slide 92

  • Reducing the Search Space

  • Dynamic Programming

  • Slide 95

  • Slide 96

  • Slide 97

  • Slide 98

  • Slide 99

  • Slide 100

  • Semantic Query Optimization

  • Slide 102

  • Query Optimization in Oracle

  • QO in Oracle – Rule-Based

  • QO in Oracle – Rule-based: Example

  • QO in Oracle – Cost-Based

  • QO in Oracle – Statistics

  • QO in Oracle – Histograms

  • Slide 109

  • Slide 110

  • Slide 111

  • QO in Oracle – Viewing Execution Plan

Nội dung

1 Chapter 21 Query Processing Transparencies © Pearson Education Limited 1995, 2005 2 Chapter 21 - Objectives  Objectives of query processing and optimization.  Static versus dynamic query optimization.  How a query is decomposed and semantically analyzed.  How to create a R.A.T. to represent a query.  Rules of equivalence for RA operations.  How to apply heuristic transformation rules to improve efficiency of a query. © Pearson Education Limited 1995, 2005 3 Chapter 21 - Objectives  Types of database statistics required to estimate cost of operations.  Different strategies for implementing selection.  How to evaluate cost and size of selection.  Different strategies for implementing join.  How to evaluate cost and size of join.  Different strategies for implementing projection.  How to evaluate cost and size of projection. © Pearson Education Limited 1995, 2005 4 Chapter 21 - Objectives  How to evaluate the cost and size of other RA operations.  How pipelining can be used to improve efficiency of queries.  Difference between materialization and pipelining.  Advantages of left-deep trees.  Approaches to finding optimal execution strategy.  How Oracle handles QO. © Pearson Education Limited 1995, 2005 5 Introduction  In network and hierarchical DBMSs, low-level procedural query language is generally embedded in high-level programming language.  Programmer’s responsibility to select most appropriate execution strategy.  With declarative languages such as SQL, user specifies what data is required rather than how it is to be retrieved.  Relieves user of knowing what constitutes good execution strategy. © Pearson Education Limited 1995, 2005 6 Introduction  Also gives DBMS more control over system performance.  Two main techniques for query optimization: – heuristic rules that order operations in a query; – comparing different strategies based on relative costs, and selecting one that minimizes resource usage.  Disk access tends to be dominant cost in query processing for centralized DBMS. © Pearson Education Limited 1995, 2005 7 Query Processing Activities involved in retrieving data from the database.  Aims of QP: – transform query written in high-level language (e.g. SQL), into correct and efficient execution strategy expressed in low-level language (implementing RA); – execute strategy to retrieve required data. © Pearson Education Limited 1995, 2005 8 Query Optimization Activity of choosing an efficient execution strategy for processing query.  As there are many equivalent transformations of same high-level query, aim of QO is to choose one that minimizes resource usage.  Generally, reduce total execution time of query.  May also reduce response time of query.  Problem computationally intractable with large number of relations, so strategy adopted is reduced to finding near optimum solution. © Pearson Education Limited 1995, 2005 9 Example 21.1 - Different Strategies Find all Managers who work at a London branch. SELECT * FROM Staff s, Branch b WHERE s.branchNo = b.branchNo AND (s.position = ‘Manager’ AND b.city = ‘London’); © Pearson Education Limited 1995, 2005 10 Example 21.1 - Different Strategies  Three equivalent RA queries are: (1) σ (position='Manager') ∧ (city='London') ∧ (Staff.branchNo=Branch.branchNo) (Staff X Branch) (2) σ (position='Manager') ∧ (city='London') ( Staff Staff.branchNo=Branch.branchNo Branch) (3) (σ position='Manager' (Staff)) Staff.branchNo=Branch.branchNo (σ city='London' (Branch)) © Pearson Education Limited 1995, 2005 [...]... strategy may no longer be optimal when query is run Could use a hybrid approach to overcome this © Pearson Education Limited 1995, 2005 16 Query Decomposition Aims are to transform high-level query into RA query and check that query is syntactically and semantically correct Typical stages are: – analysis, – normalization, – semantic analysis, – simplification, – query restructuring © Pearson Education... 12 Phases of Query Processing QP has four main phases: – decomposition (consisting of parsing and validation); – optimization; – code generation; – execution © Pearson Education Limited 1995, 2005 13 Phases of Query Processing 14 © Pearson Education Limited 1995, 2005 Dynamic versus Static Optimization Two times when first three phases of QP can be carried out: – dynamically every time query is run;... Pearson Education Limited 1995, 2005 19 Analysis Finally, query transformed into some internal representation more suitable for processing Some kind of query tree is typically chosen, constructed as follows: – Leaf node created for each base relation – Non-leaf node created for each intermediate relation produced by RA operation – Root of tree represents query result – Sequence is directed from leaves to... restructuring © Pearson Education Limited 1995, 2005 17 Analysis Analyze query lexically and syntactically using compiler techniques Verify relations and attributes exist Verify operations are appropriate for object type © Pearson Education Limited 1995, 2005 18 Analysis - Example SELECT staff_no FROM Staff WHERE position > 10; This query would be rejected on two grounds: – staff_no is not defined for... Static Optimization Two times when first three phases of QP can be carried out: – dynamically every time query is run; – statically when query is first submitted Advantages of dynamic QO arise from fact that information is up to date Disadvantages are that performance of query is affected, time may limit finding optimum strategy © Pearson Education Limited 1995, 2005 15 Dynamic versus Static Optimization... ∧ branchNo = 'B003') © Pearson Education Limited 1995, 2005 22 Semantic Analysis Rejects normalized queries that are incorrectly formulated or contradictory Query is incorrectly formulated if components do not contribute to generation of result Query is contradictory if its predicate cannot be satisfied by any tuple Algorithms to determine correctness exist only for queries that do not contain disjunction... for which valuation sum is negative, query is contradictory © Pearson Education Limited 1995, 2005 25 Example 21.2 - Checking Semantic Correctness SELECT p.propertyNo, p.street FROM Client c, Viewing v, PropertyForRent p WHERE c.clientNo = v.clientNo AND c.maxRent >= 500 AND c.prefType = ‘Flat’ AND p.ownerNo = ‘CO93’; Relation connection graph not fully connected, so query is not correctly formulated... < 200; Normalized attribute connection graph has cycle between nodes c.maxRent and 0 with negative valuation sum, so query is contradictory © Pearson Education Limited 1995, 2005 28 Simplification – Detects redundant qualifications, – eliminates common sub-expressions, – transforms query to semantically equivalent but more easily and efficiently computed form Typically, access restrictions, view definitions,... tree represents query result – Sequence is directed from leaves to root © Pearson Education Limited 1995, 2005 20 Example 21.1 - R.A.T © Pearson Education Limited 1995, 2005 21 Normalization Converts query into a normalized form for easier manipulation Predicate can be converted into one of two forms: Conjunctive normal form: (position = 'Manager' ∨ salary > 20000) ∧ (branchNo = 'B003') Disjunctive... graph Relation connection graph Create node for each relation and node for result Create edges between two nodes that represent a join, and edges between nodes that represent projection If not connected, query is incorrectly formulated © Pearson Education Limited 1995, 2005 24 Semantic Analysis - Normalized Attribute Connection Graph Create node for each reference to an attribute, or constant 0 Create . 1 Chapter 21 Query Processing Transparencies © Pearson Education Limited 1995, 2005 2 Chapter 21 - Objectives  Objectives of query processing and optimization.  Static versus dynamic query optimization.  How. in query processing for centralized DBMS. © Pearson Education Limited 1995, 2005 7 Query Processing Activities involved in retrieving data from the database.  Aims of QP: – transform query. Limited 1995, 2005 8 Query Optimization Activity of choosing an efficient execution strategy for processing query.  As there are many equivalent transformations of same high-level query, aim of QO

Ngày đăng: 22/10/2014, 10:13

TỪ KHÓA LIÊN QUAN