1 / 22

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

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

tamber
Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

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

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

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

  7. אינדקס משני (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

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

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

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

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

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

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

  14. 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.

  15. 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.

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

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

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

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

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

  21. דוגמה:הוספת רשומות לקובץ deposit תוך בניית השינג בר-הרחבה הרשומות שיוזנו לקובץ 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

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

More Related