COP4540 Database Management System Final Review - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

COP4540 Database Management System Final Review

Description:

If you want to retrieve all records with sal 20, is using the index ... author Giada De Laurentiis /author year 2005 /year price 30.00 /price /book ... – PowerPoint PPT presentation

Number of Views:96
Avg rating:3.0/5.0
Slides: 18
Provided by: fernand4
Category:

less

Transcript and Presenter's Notes

Title: COP4540 Database Management System Final Review


1
COP4540 Database Management SystemFinal Review
  • Reviewed by
  • Fernando Farfán

2
AGENDA
  • Ch8. Storage and Indexing
  • Ch10. Tree-Structured Indexing
  • Ch7. XML Documents
  • Ch27. XQUERY Querying XML Data

3
AGENDA
  • Ch8. Storage and Indexing
  • Ch10. Tree-Structured Indexing
  • Ch7. XML Documents
  • Ch27. XQUERY Querying XML Data

4
CH8. OVERVIEW OF STORAGE AND INDEXING
  • 8.3 Consider a relation stored as a randomly
    ordered file for which the only index is an
    unclustered index on a field called sal. If you
    want to retrieve all records with sal gt 20, is
    using the index always the best alternative?
    Explain.
  • No. In this case, the index is unclustered, each
    qualifying data entry could contain an rid that
    points to a distinct data page, leading to as
    many data page I/Os as the number of data entries
    that match the range query. In this situation,
    using index is actually worse than file scan.

5
CH8. OVERVIEW OF STORAGE AND INDEXING
  • 8.5 Explain the difference between Hash indexes
    and B-tree indexes. In particular, discuss how
    equality and range searches work.
  • Hash Index Hashing function. Quickly maps a
    search key value to a bucket. Inserts/Deletes are
    simple. Linked list for collisions. Good at
    equality searches. Terrible for range queries.
  • B-tree Index Hierarchical search data
    structure. Maintenance is costly. Costly for
    individual record lookup. Efficient for range
    queries.

6
CH8. OVERVIEW OF STORAGE AND INDEXING
  • 8.11 Consider the following relationsEmp(eid
    integer, ename varchar, sal integer, age
    integer, did integer)Dept(did integer, budget
    integer, floor integer, mgr eid
    integer)Salaries?10,000-100,000 Ages?20-80
    Departments? 5 empl. avg. 10 floors
    Budgets?10,000-1M.
  • Query Print ename, age, and sal for all
    employees.
  • Clustered hash index on ename, age, sal fields of
    Emp.
  • Unclustered hash index on ename, age, sal fields
    of Emp.
  • Clustered B tree index on ename, age, sal fields
    of Emp.
  • Unclustered hash index on eid, did fields of Emp.
  • No index.
  • We should create an unclustered hash index on
    ltename, age, salgt fields of Emp (b) since then we
    could do an index only scan. If our system does
    not include index only plans then we shouldnt
    create an index for this query (e). Since this
    query requires us to access all the Emp records,
    an index wont help us any, and so should we
    access the records using a filescan.

7
CH8. OVERVIEW OF STORAGE AND INDEXING
  • 8.11 ContEmp(eid integer, ename varchar, sal
    integer, age integer, did integer)Dept(did
    integer, budget integer, floor integer, mgr
    eid integer)
  • Query Find the dids of departments that are on
    the 10th floor and have a budget of less than
    15,000.
  • Clustered hash index on the floor field of Dept.
  • Unclustered hash index on the floor field of
    Dept.
  • Clustered B tree index on floor, budget fields
    of Dept.
  • Clustered B tree index on the budget field of
    Dept.
  • No index.
  • We should create a clustered dense B tree index
    (c) on ltfloor, budgetgt fields of Dept, since the
    records would be ordered on these fields then. So
    when executing this query, the first record with
    floor 10 must be retrieved, and then the other
    records with floor 10 can be read in order of
    budget. Note that this plan, which is the best
    for this query, is not an index-only plan (must
    look up dids).

8
AGENDA
  • Ch8. Storage and Indexing
  • Ch10. Tree-Structured Indexing
  • Ch7. XML Documents
  • Ch27. XQUERY Querying XML Data

9
CH10. TREE-STRUCTURED INDEXING
  • 10.3 Answer the following questions
  • What is the minimum space utilization for a B
    tree index?
  • What is the minimum space utilization for an ISAM
    index?
  • If your database system supported both a static
    and a dynamic tree index (say, ISAM and B
    trees), would you ever consider using the static
    index in preference to the dynamic index?
  • By def., a B tree, each index page, except for
    the root, has at least d and at most 2d key
    entries. Therefore the minimum space utilization
    guaranteed by a B tree index is 50 percent.
  • The minimum space utilization by an ISAM index
    depends on the design of the index and the data
    distribution over the lifetime of ISAM index.
    Since an ISAM index is static, empty spaces in
    index pages are never filled (in contrast to a B
    tree index, which is a dynamic index). Therefore
    the space utilization of ISAM index pages is
    usually close to 100 percent by design. However,
    there is no guarantee for leaf pages
    utilization.
  • A static index without overflow pages is faster
    than a dynamic index on inserts and deletes,
    since index pages are only read and never
    written. If the set of keys that will be inserted
    into the tree is known in advance, then it is
    possible to build a static index which reserves
    enough space for all possible future inserts.
    Also if the system goes periodically off line,
    static indices can be rebuilt and scaled to the
    current occupancy of the index. Infrequent or
    scheduled updates are flags for when to consider
    a static index structure.

10
AGENDA
  • Ch8. Storage and Indexing
  • Ch10. Tree-Structured Indexing
  • Ch7. XML Documents
  • Ch27. XQUERY Querying XML Data

11
CH7. XML DOCUMENTS
  • 7.1 When is an XML document well-formed? When is
    an XML document valid?
  • An XML document is valid if it has an associated
    DTD and the document follows the rules of the
    DTD. An XML document is well-formed if it follows
    three guidelines
  • It starts with an XML declaration.
  • It contains a root element that contains all
    other elements.
  • All elements are properly nested.

12
AGENDA
  • Ch8. Storage and Indexing
  • Ch10. Tree-Structured Indexing
  • Ch7. XML Documents
  • Ch27. XQUERY Querying XML Data

13
CH27. XQUERY
  • ltbookstoregt ltbook category"COOKING"gt lttitle
    lang"en"gtEveryday Italianlt/titlegt ltauthorgtGiada
    De Laurentiislt/authorgt ltyeargt2005lt/yeargt ltpri
    cegt30.00lt/pricegt lt/bookgt ltbook
    category"CHILDREN"gt lttitle lang"en"gtHarry
    Potterlt/titlegt ltauthorgtJ K. Rowlinglt/authorgt lt
    yeargt2005lt/yeargt ltpricegt29.99lt/pricegt lt/bookgt
    ltbook category"WEB"gt lttitle lang"en"gtXQuery
    Kick Startlt/titlegt ltauthorgtJames
    McGovernlt/authorgt ltauthorgtPer
    Bothnerlt/authorgt ltauthorgtKurt
    Caglelt/authorgt ltauthorgtJames Linnlt/authorgt ltau
    thorgtVaidyanathan Nagarajanlt/authorgt ltyeargt2003lt
    /yeargt ltpricegt49.99lt/pricegt lt/bookgt ltbook
    category"WEB"gt lttitle lang"en"gtLearning
    XMLlt/titlegt ltauthorgtErik T. Raylt/authorgt ltyear
    gt2003lt/yeargt ltpricegt39.95lt/pricegt lt/bookgtlt/boo
    kstoregt

14
CH27. XQUERY
  • Querydoc("books.xml")/bookstore/book/title
  • Resultlttitle lang"en"gtEveryday
    Italianlt/titlegtlttitle lang"en"gtHarry
    Potterlt/titlegtlttitle lang"en"gtXQuery Kick
    Startlt/titlegtlttitle lang"en"gtLearning
    XMLlt/titlegt

15
CH27. XQUERY
  • Querydoc("books.xml")/bookstore/bookpricelt30
  • Resultltbook category"CHILDREN"gt lttitle
    lang"en"gtHarry Potterlt/titlegt ltauthorgtJ K.
    Rowlinglt/authorgt ltyeargt2005lt/yeargt ltpricegt29.99lt
    /pricegtlt/bookgt

16
CH27. XQUERY
  • Queryfor x in doc("books.xml")/bookstore/book
    where x/pricegt30 order by x/title return
    x/title
  • Resultlttitle lang"en"gtLearning
    XMLlt/titlegtlttitle lang"en"gtXQuery Kick
    Startlt/titlegt

17
CH27. XQUERY
  • Queryltulgt for x in doc("books.xml")/bookstor
    e/book/title order by x return ltligtxlt/ligt
    lt/ulgt
  • Resultltulgt ltligtlttitle lang"en"gtEveryday
    Italianlt/titlegtlt/ligt ltligtlttitle lang"en"gtHarry
    Potterlt/titlegtlt/ligt ltligtlttitle
    lang"en"gtLearning XMLlt/titlegtlt/ligt ltligtlttitle
    lang"en"gtXQuery Kick Startlt/titlegtlt/ligtlt/ulgt
Write a Comment
User Comments (0)
About PowerShow.com