DOC PREVIEW
UW CSE 444 - Hast Tables and Query Execution

This preview shows page 1-2-15-16-31-32 out of 32 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Hash Tables and Query ExecutionHash TablesHash Table ExampleSearching in a Hash TableInsertion in Hash TableSlide 6Hash Table PerformanceWhere are we?Current Issues in IndexingQuery ExecutionQuery Execution PlansThe Leaves of the Plan: ScansHow do we combine Operations?Implementing Relational OperationsSchema for ExamplesSimple SelectionsUsing an Index for SelectionsTwo Approaches to General SelectionsIntersection of RidsImplementing ProjectionEquality Joins With One Join ColumnDiscussionSimple Nested Loops JoinIndex Nested Loops JoinExamples of Index Nested LoopsBlock Nested Loops JoinSort-Merge Join (R S)Cost of Sort-Merge JoinHash-JoinCost of Hash-JoinHow are we doing?Double Pipelined Join (Tukwila)Hash Tables and Query ExecutionMarch 1st, 2004Hash Tables•Secondary storage hash tables are much like main memory ones•Recall basics:–There are n buckets–A hash function f(k) maps a key k to {0, 1, …, n-1}–Store in bucket f(k) a pointer to record with key k•Secondary storage: bucket = block, use overflow blocks when needed•Assume 1 bucket (block) stores 2 keys + pointers•h(e)=0•h(b)=h(f)=1•h(g)=2•h(a)=h(c)=3Hash Table Exampleebfgac0123•Search for a:•Compute h(a)=3•Read bucket 3•1 disk accessSearching in a Hash Tableebfgac0123•Place in right bucket, if space•E.g. h(d)=2Insertion in Hash Tableebfgdac0123•Create overflow block, if no space•E.g. h(k)=1•More over-flow blocksmay be neededInsertion in Hash Tableebfgdac0123kHash Table Performance•Excellent, if no overflow blocks•Degrades considerably when number of keys exceeds the number of buckets (I.e. many overflow blocks).•Typically, we assume that a hash-lookup takes 1.2 I/Os.Where are we?•File organizations: sorted, hashed, heaps.•Indexes: hash index, B+-tree•Indexes can be clustered or not.•Data can be stored in the index or not.•Hence, when we access a relation, we can either scan or go through an index:–Called an access path.Current Issues in Indexing•Multi-dimensional indexing:–how do we index regions in space?–Document collections?–Multi-dimensional sales data–How do we support nearest neighbor queries?•Indexing is still a hot and unsolved problem!Query ExecutionQuery compilerExecution engineIndex/record mgr.Buffer managerStorage managerstorageUser/ApplicationQueryupdateQuery executionplanRecord, indexrequestsPage commandsRead/writepagesQuery Execution PlansPurchasePersonBuyer=nameCity=‘seattle’ phone>’5430000’buyer(Simple Nested Loops)SELECT S.snameFROM Purchase P, Person QWHERE P.buyer=Q.name AND Q.city=‘seattle’ AND Q.phone > ‘5430000’ Query Plan:• logical tree• implementation choice at every node• scheduling of operations.(Table scan) (Index scan)Some operators are from relationalalgebra, and others (e.g., scan, group)are not.The Leaves of the Plan: Scans•Table scan: iterate through the records of the relation.•Index scan: go to the index, from there get the records in the file (when would this be better?)•Sorted scan: produce the relation in order. Implementation depends on relation size.How do we combine Operations?•The iterator model. Each operation is implemented by 3 functions:–Open: sets up the data structures and performs initializations–GetNext: returns the the next tuple of the result.–Close: ends the operations. Cleans up the data structures.•Enables pipelining!•Contrast with data-driven materialize model.•Sometimes it’s the same (e.g., sorted scan).Implementing Relational Operations•We will consider how to implement:–Selection ( ) Selects a subset of rows from relation.–Projection ( ) Deletes unwanted columns from relation.–Join ( ) Allows us to combine two relations.–Set-difference Tuples in reln. 1, but not in reln. 2.–Union Tuples in reln. 1 and in reln. 2.–Aggregation (SUM, MIN, etc.) and GROUP BYσπ><Schema for Examples•Purchase:–Each tuple is 40 bytes long, 100 tuples per page, 1000 pages (i.e., 100,000 tuples, 4MB for the entire relation).•Person:–Each tuple is 50 bytes long, 80 tuples per page, 500 pages (i.e, 40,000 tuples, 2MB for the entire relation).Purchase (buyer:string, seller: string, product: integer), Person (name:string, city:string, phon e : integer)Simple Selections•Of the form•With no index, unsorted: Must essentially scan the whole relation; cost is M (#pages in R).•With an index on selection attribute: Use index to find qualifying data entries, then retrieve corresponding data records. (Hash index useful only for equality selections.) •Result size estimation: (Size of R) * reduction factor. More on this later.SELECT *FROM Person RWHERE R.phone < ‘543%’σR attr valueopR.( )Using an Index for Selections•Cost depends on #qualifying tuples, and clustering.–Cost of finding qualifying data entries (typically small) plus cost of retrieving records. –In example, assuming uniform distribution of phones, about 54% of tuples qualify (500 pages, 50000 tuples). With a clustered index, cost is little more than 500 I/Os; if unclustered, up to 50000 I/Os!•Important refinement for unclustered indexes: 1. Find sort the rid’s of the qualifying data entries. 2. Fetch rids in order. This ensures that each data page is looked at just once (though # of such pages likely to be higher than with clustering).Two Approaches to General Selections•First approach: Find the most selective access path, retrieve tuples using it, and apply any remaining terms that don’t match the index:–Most selective access path: An index or file scan that we estimate will require the fewest page I/Os.–Consider city=“seattle AND phone<“543%” :• A hash index on city can be used; then, phone<“543%” must be checked for each retrieved tuple.• Similarly, a b-tree index on phone could be used; city=“seattle” must then be checked.Intersection of Rids•Second approach–Get sets of rids of data records using each matching index.–Then intersect these sets of rids.–Retrieve the records and apply any remaining terms.Implementing Projection•Two parts: (1) remove unwanted attributes, (2) remove duplicates from the result. •Refinements to duplicate removal:–If an index on a relation contains all wanted attributes, then we can do an index-only scan.–If the index contains a subset of the wanted attributes, you can remove duplicates locally.SELECT DISTINCT R.name, R.phoneFROM Person


View Full Document

UW CSE 444 - Hast Tables and Query Execution

Documents in this Course
XML

XML

48 pages

SQL

SQL

25 pages

SQL

SQL

42 pages

Recovery

Recovery

30 pages

SQL

SQL

36 pages

Indexes

Indexes

35 pages

Security

Security

36 pages

Wrap-up

Wrap-up

6 pages

SQL

SQL

37 pages

More SQL

More SQL

48 pages

SQL

SQL

35 pages

XML

XML

46 pages

Triggers

Triggers

26 pages

Load more
Download Hast Tables and Query Execution
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Hast Tables and Query Execution and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Hast Tables and Query Execution 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?