7
Contents 1. Query Processing 2. Translating SQL queries into RA 3. Evaluation Plan 4. Query Execution 5. Query Optimization 6. Translation Rules 7. Cost Estimations

1 query processing

Embed Size (px)

Citation preview

Page 1: 1 query processing

Contents

1. Query Processing

2. Translating SQL queries into RA

3. Evaluation Plan

4. Query Execution

5. Query Optimization

6. Translation Rules

7. Cost Estimations

Page 2: 1 query processing

1. Query Processing

▪ Aim of query processing - to find information in one or more databases, - and deliver it to the user quickly and efficiently. - to choose the most cost effective.

▪ Translation of queries - into expressions that can be used at physical level of file system. - Includes query optimization and query evaluation.

1. Query Processing

Page 3: 1 query processing

1. Query Processing ▪ Typical steps when processing a high-level query (e.g. SQL query) Query tree internal representation of the query  Execution strategy how to retrieve results of query  

1. Query Processing

Page 4: 1 query processing

2. Translating SQL queries into RA

▪ Translate query into its internal form. - This is then translated into Relational Algebra(RA). - The parser checks syntax, verifies relations.

▪ A RA expression may have many equivalent expressions.

▪ Example Σbalance<2500(πbalance(account))

Is equivalent to Πbalance(σbalance<2500(account))

Each relational algebra operation can be evaluated using one of several different algorithms. Correspondingly, a relational-algebra expression can be evaluated in many ways.

2. Translating SQL queries into RA

Page 5: 1 query processing

3. Evaluation Plan ▪ Annotated expression specifying detailed evaluation strategy.

▪ Example Use an index on balance to find accounts with balance < 2500, Or perform complete relation scan and discard accounts with balance ≥ 2500.

Initial canonical query tree

3. Evaluation Plan

Book (access#, title) Member (ticket#, name) Loan(loanedbook,loanedto)

Select member.name rom book, loan, member

where book.title = "dracula" and member.ticket# = loan.loanedto and loan.loanedbook = book.access#

Page 6: 1 query processing

4. Query Execution

For each operation (join, select, project, aggregation …) - Typical algorithms (e.g. Binary search for simple selection) - Specific or not to storage structure and access paths  Book (access#, title) Member (ticket#, name) Loan(loanedbook,loanedto)  Select member.name From book, loan, member

where book.title = "dracula" and member.ticket# = loan.loanedto and loan.loanedbook = book.access#

4. Query Execution

Page 7: 1 query processing

4. Query Execution

4. Query Execution