Docsity

Database Management Systems: Index Structures and Search Algorithms, Slides of Introduction to Database Management Systems

Partial preview of the text

Download Database Management Systems: Index Structures and Search Algorithms and more Slides Introduction to Database Management Systems in PDF only on Docsity!

Database Management Systems Design

Range queries

• Queries that retrieve group of records that lies inside a

range of values

• Examples:

  • Find the name of all students with a gpa between 3.40 and 3.
  • Find all the items with a prices greater than $50.
  • Find all the parts with an average stock amount less than 30.
  • Find all the galaxies that are within 10 light year from galaxy NC-
  • Find all the images for regions that overlap the area of Puerto

Rico.

• Note: Tree are also good for equality.

Three major styles

• ISAM

  • Static tree index
  • Good for alphanumeric data sets

• B+-tree

  • Dynamic tree index
  • Good for alphanumeric data sets

• R-tree

  • Dynamic tree index
  • Good for alphanumeric and spatial data sets
    • Polygons, maps, galaxies
    • Dimensions in a data warehouse
      • Parts, sales, date,

General form for index pages

• Index pages have

– Key values – number, strings, rectangles (R-tree)

– Pointers to child nodes

– P0 leads to values less than K

– Pm leads to values greater or equal than Km

– For any other case, Pi points to values greater or

equal than Ki, and values less than K i+

– For R-tree is all about overlapping regions …

P0 K1 P1 K2 P2 … Km Pm

ISAM

• Indexed sequential access method (ISAM)

• Support insert, delete, search operations

• Static index structure based on tree

– Balanced tree

• Number of leaves and internal nodes is fixed at

file creation time

• More space is allocated as overflow pages

– Chained with appropriate leaf

– Long overflow chains are no good.

ISAM Structure

Overflow pages

ISAM Disk Organization

• Data pages are allocated sequentially

– Fixed number of pages at file creation

• Index pages are then allocated

– Fixed number of pages at file creation

• Overflow pages go at the end of file

– Variable number

– Must be chained with the base data pages

Data pages

Index pages

Overflow pages

ISAM

File

Structure

ISAM Tree After a few insertions

Insertions:

23, 48, 41, 42

Overflow

page

Search Algorithm

• Above algorithms just finds a pointer to the

page where record might be

• Once we get the pointer, need to search the

value inside the page

– Use either sequential or binary search

• If overflow pages exists, need to traverse them

– Lots of overflow pages mean more I/Os

• Here need to understand the format of the

page

– Determine the how to locate the record Docsity.com

Insertion and Deletion

• Use search algorithm to find the page where

the record(s) should go

• Then within this page

– Insert the record

– Delete the record

• If not found, then if there are overflow pages,

– Repeat this process on the overflow page

B+-trees

  • Dynamic index structure
  • Adapts its size and height to the pattern of insertion and deletions.
    • Balanced tree because all leaf nodes are at the same height
  • No overflow pages (unless duplicates are there)
  • Each leaf and internal node has an order
    • Capacity of node to hold m keys
    • Order d has the property d <= m <= 2d
      • Tree of order 1 has between 1 and 2 keys, and between 2 and tree children.
  • Internal nodes have
    • Up to m keys
    • Up to m+1 pointers to child nodes
  • Leaf nodes have the data entries

Example B+Tree

• Internal Nodes have search keys & pointers

to child nodes

• Data entries have data or pairs of <search

key,rid>

• Data entries are linked in a doubly linked

B+ tree with

fan out of 2

Search Operation

  • Search Operation is a follows:
  • findTuples(key, treeSearch(root,key));
    • Finds page with tuples with search key and searches tuples

node treeSearch(Node N, Object key){

if (N is a leaf) return N; // find page

else if (key < K1) return treeSearch(N.P0, key);

else if (key >= Km) return treeSearch(N.Pm, key);

else {

for each key Ki in N, i <=1 <(m-1)

if ((Ki <= key) && (key < Ki+1))

return treeSearch(N.Pi. key);

Example: Search on B+tree

  • Search for 15 and 56 is yields results.
  • Search for 20 does not
  • In either case, search reaches leaf level and returns page where data

might be

  • Function find Tuples must binary and full search within the page to get the actual tuples.