אינדקסינג והשינג (indexing & hashing)

Slides:



Advertisements
Similar presentations
CpSc 3220 File and Database Processing Lecture 17 Indexed Files.
Advertisements

Quick Review of Apr 10 material B+-Tree File Organization –similar to B+-tree index –leaf nodes store records, not pointers to records stored in an original.
Dr. Kalpakis CMSC 661, Principles of Database Systems Index Structures [13]
תרגול 8 עצי B+ אינדקס משני.
A. Frank File Organization קובץ ישיר מתקדם Advanced Direct File.
A. Frank File Organization Indexed-Sequential File Introduction Thanks to Tamar Barnes.
Data Indexing Herbert A. Evans. Purposes of Data Indexing What is Data Indexing? Why is it important?
חישוב ואופטימיזציה של שאילתות חלק 1
קובץ רב-אינדקס Multi-Indexed File
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part B Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
תרגול 7 עצי B
1 Indexing Structures for Files. 2 Basic Concepts  Indexing mechanisms used to speed up access to desired data without having to scan entire.
1 חישוב ואופטימיזציה של שאילתות חלק 1 Query Evaluation and Optimization Part 1.
1 חישוב של אופרטורים רלציוניים Evaluation of Relational Operators.
Homework #3 Due Thursday, April 17 Problems: –Chapter 11: 11.6, –Chapter 12: 12.1, 12.2, 12.3, 12.4, 12.5, 12.7.
A. Frank File Organization Hardware Size Parameters.
Indexing dww-database System.
Chapter 61 Chapter 6 Index Structures for Files. Chapter 62 Indexes Indexes are additional auxiliary access structures with typically provide either faster.
Indexing. Goals: Store large files Support multiple search keys Support efficient insert, delete, and range queries.
Index Structures for Files Indexes speed up the retrieval of records under certain search conditions Indexes called secondary access paths do not affect.
Database Management 8. course. Query types Equality query – Each field has to be equal to a constant Range query – Not all the fields have to be equal.
Chapter 11 Indexing & Hashing. 2 n Sophisticated database access methods n Basic concerns: access/insertion/deletion time, space overhead n Indexing 
12.1 Chapter 12: Indexing and Hashing Spring 2009 Sections , , Problems , 12.7, 12.8, 12.13, 12.15,
Indexing and hashing Azita Keshmiri CS 157B. Basic concept An index for a file in a database system works the same way as the index in text book. For.
Spring 2003 ECE569 Lecture 05.1 ECE 569 Database System Engineering Spring 2003 Yanyong Zhang
Indexing Database Management Systems. Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B + -Tree Index Files File Organization 2.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18 Indexing Structures for Files.
1 Chapter 12: Indexing and Hashing Indexing Indexing Basic Concepts Basic Concepts Ordered Indices Ordered Indices B+-Tree Index Files B+-Tree Index Files.
Chapter 5 Ranking with Indexes. Indexes and Ranking n Indexes are designed to support search  Faster response time, supports updates n Text search engines.
CS422 Principles of Database Systems Indexes Chengyu Sun California State University, Los Angeles.
CS422 Principles of Database Systems Indexes
Indexing Structures for Files
Indexing Structures for Files
Data Indexing Herbert A. Evans.
Indexing Structures for Files
Tirgul 12 Trees 1.
Indexing Structures for Files and Physical Database Design
CS 540 Database Management Systems
Indexing and hashing.
Tree-Structured Indexes: Introduction
CS 728 Advanced Database Systems Chapter 18
Azita Keshmiri CS 157B Ch 12 indexing and hashing
Dynamic Hashing (Chapter 12)
Database System Implementation CSE 507
Database Management Systems (CS 564)
CPSC-629 Analysis of Algorithms
Database Applications (15-415) DBMS Internals- Part III Lecture 15, March 11, 2018 Mohammad Hammoud.
תירגול 14: מבני נתונים דינאמיים
Chapter 11: Indexing and Hashing
CPSC-310 Database Systems
Chapter 11: Indexing and Hashing
Lecture 26 Multiway Search Trees Chapter 11 of textbook
Indexing and Hashing Basic Concepts Ordered Indices
Lecture 21: Indexes Monday, November 13, 2000.
Random inserting into a B+ Tree
Advance Database System
Indexing and Hashing B.Ramamurthy Chapter 11 2/5/2019 B.Ramamurthy.
Database Systems (資料庫系統)
Chapter 11 Indexing And Hashing (1)
Database Design and Programming
INDEXING.
CPS216: Advanced Database Systems
Storage and Indexing.
Credit for some of the slides in this lecture goes to
Module 12a: Dynamic Hashing
Indexing February 28th, 2003 Lecture 20.
CPSC-608 Database Systems
Indexing Structures for Files
Chapter 11: Indexing and Hashing
Lec 6 Indexing Structures for Files
Presentation transcript:

אינדקסינג והשינג (indexing & hashing) אמצעים לאיתור רשומות בקובץ, למשל לצורך ביצוע שאילתא. קובץ האינדקס מכיל רשומות (כניסות אינדקס) בעלות מבנה: (מפתח חיפוש, פוינטר) כאשר: מפתח החיפוש הוא השדה על פיו מחפשים מידע בקובץ פוינטר הוא מצביע לרשומה בקובץ הנתונים שני סוגים עיקריים של אינדקסים: אינדקסים מסודרים (ordered indices) אינדקסי הש (hash indices)

אינדקסים סדורים (orderd indices) שיטה לגישה מהירה: סדרתית ואקראית. כל אינדקס מאופיין על ידי מפתח חיפוש. נניח כי כל הקבצים בבסיס הנתונים הם קבצים ממוינים. אינדקס ראשי (primary index): אינדקס שמפתח החיפוש שלו מגדיר את סדר הרשומות בקובץ. אינדקס משני (secondary index): כל אינדקס שאינו ראשי.

קובץ סדרתי לרשומות היחס deposit מתאים הן לגישה סדרתית והן לגישה אקראית.

אינדקס צפוף (dense index) אינדקס צפוף: אינדקס הכולל רשומת אינדקס אחת לכל ערך של מפתח החיפוש.

אינדקס דליל (sparse index) אינדקס דליל: אינדקס הכולל רשומת אינדקס רק לחלק מהערכים של מפתח החיפוש.

אינדקס דליל בעל שתי רמות כאשר קבצי האינדקס גדלים יעילותם קטנה. במקרה זה ניתן לבצע אינדקס על קובץ האינדקס. block 1 block 2 block 65 level 2 index (outer index) block 66 level 1 index (inner index) data file

אינדקס משני (secondary index) הקובץ אינו ממוין לפי מפתח החיפוש של האינדקס. Secondary index with buckets block 1 block 2 Block 3 block 4 block 5 Block 6 secondary index Block 7 buckets data file

שיטות למימוש אינדקס משני אינדקס משני צפוף המכיל כתובות לכל רשומות קובץ הנתונים. (כפילות של ערכי מפתח החיפוש באינדקס). רשומת אינדקס אחת לכל ערך של מפתח חיפוש עם פוינטרים אחדים לכל רשומה. רשומת אינדקס אחת לכל ערך של מפתח חיפוש עם הפנייה ל”דלי” (bucket) של פוינטרים לקובץ הנתונים..

עץ (B+ tree index) B+ יעילותו של מבנה אינדקס סדרתי פוחתת עם גודל הקובץ. מבנה נתונים של עץ מאוזן שומר על יעילות גבוהה, במחיר של תקורת זיכרון. צומת אופיינית של העץ: K1, K2,… Kn-1 הם ערכים של מפתח החיפוש P1, P2,… Pn הם מצביעים. P1 K1 P2 K2 Pn-1 Kn-1 Pn

הערכים של מפתח החיפוש מסודרים בכל צומת כך ש K1< K2<…< Kn-1 המצביעים של צמתי הביניים (לא העלים) מורים על תתי עצים כדלקמן: P1 Pj Kj Pj+1 Pn K <Kj K  Kj

המצביעים P1,… Pn-1 בצמתי העלים מצביעים על רשומות בקובץ הנתונים K1 Pj Kj Pn-1 Kn-1 Pn רשומות המתאימות ל K1 רשומות המתאימות ל Kj רשומות המתאימות ל Kn-1

כללים החלים על מבנה עץ B+ כללים החלים על מבנה עץ B+ אם השורש אינו עלה, חייבים להיות לו לפחות שני בנים. לעץ מסדר n , לכל צומת (פרט לשורש ולעלים) בין n/2 ל n בנים. לעץ מסדר n , לכל עלה בין (n-1)/2 ל n-1 בנים.(רשומות בקובץ הנתונים). מספר ערכי מפתח החיפוש בצומת שאינו עלה קטן ב 1 ממספר המצביעים. על העץ להיות מאוזן. העלים מקושרים זה לזה בסדר מפתח החיפוש.

דוגמה למבנה עץ B+ עץ עם n=3 לקובץ deposit . pointers to file records Merkazi Eilat Pinkas Aviv Darom Eilat Merkazi Pinkas Tsafon pointers to file records

B+ tree insertions Find the leaf node where an entry belongs and insert it there. Use the search algorithm to find the appropriate position. If the entry fits in the node (it is not full) the process is finished. If the node is already full split it. Half of the entries go in the old node and half in the new node. With the creation of a new node an entry has to be inserted in the penultimate level of the tree. Adding an entry to this level may also result in a split if the node is full. A new node is created by splitting the old node. One of the values is pushed up to the next level of the tree (removed from the current level). This, in turn may produce a new node. This process is repeated until no new nodes are created or a new root node has been created. Penultimate = next to last

B+ Tree Deletions Find the entry in the leaf node and delete it. This may result in too few entries (less than (n–1)/2) in which case either the predecessor or successor of the node is also affected (pick one) and one of two things occur. If the values from the two nodes fit in one node the nodes are coalesced. Keep track of the value in the parent between the pointers to the two nodes. Combine the two nodes into one. If the node is a leaf node re-connect the links between leaves. Delete (using this procedure) the value in the parent. If the values from the two nodes don’t fit in one node the values are rearranged. Take one value and pointer from the other node. This will create a new initial value in one node. Replace the appropriate parent value with this. If, after recursive deletions, the root node has only one child, make this child the new root and delete the old root.

הגדרת אינדקס ב SQL create [unique] index index-name on relation-name (attribute-list) כדוגמה: create index br_indx on branch (branch-name) drop index index-name השמטת אינדקס:

אינדקסי הש (hash indices) פונקצית השינג מחשבת כתובת של בלוק. שדה/שדות ההש (hash field): שדה/שדות שעליהם פועלת פונקצית ההשינג לחישוב הכתובת.

דוגמת השינג h(x)= (…) mod 5 hash table for deposit . key= branch-name Pinkas h(x)= (…) mod 5 Bucket 0 Tsafon Darom Darom Bucket 1 Darom Darom Eilat Bucket 2 Merkazi Bucket3 Merkazi Merkazi Aviv Bucket 4 hash table for deposit . key= branch-name

השינג דינמי (dynamic hashing) השינג סטטי (static hashing): השינג עם מספר קבוע של דליים. השינג דינמי (dynamic hashing): השינג שבו פונקצית ההשינג ומספר הדליים משתנים בהתאם לגודל קובץ הנתונים.

השינג בר-הרחבה (extendabable hashing) bucket 1 hash prefix i i2 bucket 2 i3 bucket address table bucket 3

דוגמה: הוספת רשומות לקובץ deposit תוך בניית השינג בר-הרחבה Aviv 0010 1101 1111 1011 0010 1100 0011 0000 Carmel 1101 0101 1101 1110 0100 0110 1001 0011 Darom 1010 0011 1010 0000 1100 0110 1001 1111 Eilat 1000 0111 1110 1101 1011 1111 0011 1010 Merkazi 1111 0001 0010 0100 1001 0011 0110 1101 Pinkas 1011 0101 1010 0110 1100 1001 1110 1011 Tsafon 0101 1000 0011 1111 1001 1100 0000 0001 32 bit hash function for branch-name

מבנה סופי לאחר הזנת הרשומות לעיל 1 Aviv Tsafon 3 3 000 Eilat 001 010 011 3 100 101 Darom Pinkas 110 111 bucket address table 2 Merkazi Carmel