Docsity

Database Systems | Study Materials | EEL 4852C, Study notes of Deductive Database Systems

Toggle sidebar
bg1
Databases – EEL 4852c
Notes from 18 NOV 2008
Transcribed by Jeff George
I/O cost example of a basic nested loop join:
Table E: 1000 pages, 100 tuples per page
Table W_O: 500 pages, 80 tuples per page
Use equation: M * Pr * N
If E is the outer table: (1000 * 100) * (500) = 50,000,000 I/Os
If W_O is the outer table: (500 * 80) * (1000) = 40,000,000 I/Os
Note: If the page size is the same, I/O cost is constant, regardless of which table is the outer table.
If we use the same tables for a Page-Based nested loop join, the cost is just:
M * N = (1000 * 500) = 5,000,000 I/Os
New join method: Indexed tables
Pseudocode:
For each tuple r in R:
Find all matching tuples in S
Return matched pairs
Cost: Based on indexing method.
Hashing – 1-2 I/O Pages (Average: 1.2)
B+ Trees – 3-4 I/O Pages
Total Cost: M * Pr * C, where C is some constant cost, based on your indexing method. In this case, the
inner-table “S” is the table which is indexed.
There’s no page-based method for indexed joins like there is for nested loop joins, but it doesn’t matter,
since indexing is really fast regardless.
Indexing only really helps if you have the “inner” table indexed. The outer table can be indexed as well,
but it won’t impact the run-time of the join. The only way it could help is during query optimization,
since the query optimizer would be able to pick the optimal inner table based on # of tuples.
Cost example, using the same tables as above, assuming both tables are indexed:
E is the outer table: 500 * 80 * C = 40,000C
W_O is the outer table: 1000 * 100 * C = 100,000C
(Obviously, if both tables are indexed, you would prefer E to be the outer table.)
Sort-Merge Join
Method –
1) Sort relation R according to the join attributes, store it in R’
2) Sort relation S according to the join attributes, store it in S’
pf2

Partial preview of the text

Download Database Systems | Study Materials | EEL 4852C and more Study notes Deductive Database Systems in PDF only on Docsity!

Databases – EEL 4852c Notes from 18 NOV 2008 Transcribed by Jeff George

I/O cost example of a basic nested loop join:

Table E: 1000 pages, 100 tuples per page Table W_O: 500 pages, 80 tuples per page

Use equation: M * Pr * N If E is the outer table: (1000 * 100) * (500) = 50,000,000 I/Os If W_O is the outer table: (500 * 80) * (1000) = 40,000,000 I/Os

Note: If the page size is the same, I/O cost is constant, regardless of which table is the outer table.

If we use the same tables for a Page-Based nested loop join, the cost is just: M * N = (1000 * 500) = 5,000,000 I/Os

New join method: Indexed tables

Pseudocode: For each tuple r in R: Find all matching tuples in S Return matched pairs

Cost: Based on indexing method. Hashing – 1-2 I/O Pages (Average: 1.2) B+ Trees – 3-4 I/O Pages

Total Cost: M * Pr * C, where C is some constant cost, based on your indexing method. In this case, the inner-table “S” is the table which is indexed.

There’s no page-based method for indexed joins like there is for nested loop joins, but it doesn’t matter, since indexing is really fast regardless.

Indexing only really helps if you have the “inner” table indexed. The outer table can be indexed as well, but it won’t impact the run-time of the join. The only way it could help is during query optimization, since the query optimizer would be able to pick the optimal inner table based on # of tuples.

Cost example, using the same tables as above, assuming both tables are indexed: E is the outer table: 500 * 80 * C = 40,000C W_O is the outer table: 1000 * 100 * C = 100,000C (Obviously, if both tables are indexed, you would prefer E to be the outer table.)

Sort-Merge Join Method –

  1. Sort relation R according to the join attributes, store it in R’
  2. Sort relation S according to the join attributes, store it in S’
  1. Merge (R’, S’)

Essentially, step a pointer through each sorted relation. If they don’t match, compare the next elements. If they do match, copy the tuple into the merged relation.

Cost: (M log M) + (N log N) + (M+N+[# of matches])

Plan Evaluation The Cost Model considers:

  1. Response Time – How soon will we start getting results?
  2. Total Processing Time – How soon will the query finish?

Plans -> [Cost Model] -> Optimal Cost Plan

The total number of plans going into the Cost Model may be huge. Think about all the different permutations of a Relational Algebra tree you can draw, then realize that each step of that tree may have a wide variety of methods of execution (We have just shown four different methods of doing a Join). The number of potential plans can obviously get out of hand rather quickly.

If the number of plans grows very rapidly, you may end up running into a situation where the time it takes to analyze the time each plan would require to run, and then the time it would take to compare all these plans to find the optimal plan may itself be longer than the run-time of a sub-optimal plan that was seen earlier.

To resolve this issue and speed up the procedure of finding an optimal plan, in the real world we use Heuristics to find the best plan, or at least find a good plan.

Cost Evaluation requires:

  1. Cost model of algorithms
  2. Size of intermediary results (Some statistics are kept between queries so the cost evaluator can make reasonable approximations)