+ All Categories
Home > Documents > Advanced Databases - Unit 1

Advanced Databases - Unit 1

Date post: 06-Apr-2018
Category:
Upload: debi-roy
View: 220 times
Download: 0 times
Share this document with a friend

of 40

Transcript
  • 8/3/2019 Advanced Databases - Unit 1

    1/40

    1

    Advance Database Systems

    Course Code: CSE 515

    LTPC:3 10 4

    M. Venkatesan

    Assistant Professor (Selection Grade)

    School of Computing Science &

    EngineeringVIT University

  • 8/3/2019 Advanced Databases - Unit 1

    2/40

    2

    Syllabus

    CSE 515 ADVANCED DATABASE SYSTEMS LTPC3104

    Contents: DATABASE DESIGN AND TUNING

    Introduction to physical database design Guideline for index selection- Overview of database tuningConceptual schema tuning Queries and view tuning.

    PARALLEL AND DISTRIBUTED DATABASE

    Parallel database systems: Architecture of parallel databases, parallel Query evaluation, parallelizing joins andparallel query optimization. Distributed database systems: Distributed database architecture, Properties ofdistributed database, Types of distributed database, storing data in a distributed DBMS, distributed query

    processing EMERGING DATABASE TECHNOLOGIES

    Multimedia databases: Multimedia sources, Multimedia database queries, Multimedia database applications,Mobile databases: Architecture of mobile databases, characteristics of mobile computing, mobile DBMS, ObjectDatabase System: Abstract data types, object identity and reference types, inheritance, and Database design forORDBMS

    DATA WAREHOUSING

    Data warehousing: Definition and terminology, Data Preprocessing, Main components of data warehouse, Data

    warehouse architecture, OLAP technology, Data mart. Text/ Reference Books

    1. Raghu Ramakrishnan and Johannes Gehrke: Database Management Systems, III Edition, McGrawHill,2000.

    2. S.K.Singh, Database Systems: Concepts, Design & Applications, Pearson education, 2006

    3. Ramez Elmasri & B.Navathe: Fundamentals of database systems, IV edition, Addison Wesley, 2005.

    4. Jiawei Han and Micheline Kamber, Data Mining-Concepts and Techniques, Morgan kaufmann publishers,2005.

  • 8/3/2019 Advanced Databases - Unit 1

    3/40

    3

    Introduction to physical database design

    Guideline for index selection

    Overview of database tuning

    Conceptual schema tuning

    Queries and View tuning

    Database Design and Tuning

  • 8/3/2019 Advanced Databases - Unit 1

    4/40

    4

    Tune or adjust all aspects of a database design for Performance

    of Database

    Based on Workload description and user requirement ,thedatabase to be tuned

    Database designer must understand working of indexing,query processing and understand the workload

    choose indexes, make clustering decisions, and to refine theconceptual and external schemas (if necessary) to meetperformance goals

    Introduction to physical database design

  • 8/3/2019 Advanced Databases - Unit 1

    5/40

    5

    Database Workload

    Understanding the workload:

    The most important queries and how often they arise.

    The most important updates and how often they arise.

    The desired performance for these queries and updates

    For each query in the workload:

    Which relations does it access?

    Which attributes are retrieved?

    Which attributes are involved in selection/join conditions? How selective are these conditions likely to be?

    For each update in the workload:

    Which attributes are involved in selection/join conditions?

    How selective are these conditions likely to be?

    The type of update (INSERT/DELETE/UPDATE), and theattributes that are affected.

    Note: while update, index may slow down the process

  • 8/3/2019 Advanced Databases - Unit 1

    6/40

    6

    Choice of indexes to create

    What indexes should we create? Which relations should have indexes? What field(s) should

    be the search key? Should we build several indexes?

    For each index, what kind of an index should it be?

    Clustered? Hash/tree?Tuning the conceptual Schema

    Should we make changes to the conceptual schema?

    Consider alternative normalized schemas? (Remember, there

    are many choices in decomposing into BCNF, etc.)

    Should we ``undo some decomposition steps and settle for alower normal form? (Denormalization.)

    Horizontal partitioning, replication, views ...

    Queries and Transaction tuning

    Rewrite frequently executed queries and transaction to runfaster

    Physical Design and Tuning Decisions

  • 8/3/2019 Advanced Databases - Unit 1

    7/40

    7

    Index

    Is a schema object

    Is used by the Oracle server to speed up the retrieval of rows

    by using a pointer

    Can reduce disk I/O by using a rapid path access method to

    locate data quickly

    Is independent of the table it indexes

    Is used and maintained automatically by the Oracle server

    How Are Indexes Created? Automatically: A unique index is created automatically when

    you define a PRIMARY KEY or UNIQUE constraint in a table

    definition.

    Manually: Users can create nonunique indexes on columns tospeed up access to the rows.

  • 8/3/2019 Advanced Databases - Unit 1

    8/40

    8

    You should create an index if:

    A column contains a wide range of values

    A column contains a large number of null values

    One or more columns are frequently used together in aWHERE clause or a join condition

    The table is large and most queries are expected to retrieve less

    than 2 to 4 percent of the rows

    When to Create an Index

  • 8/3/2019 Advanced Databases - Unit 1

    9/40

    9

    It is usually not worth creating an index if:

    The table is small

    The columns are not often used as a condition in the query

    Most queries are expected to retrieve more than 2 to 4 percentof the rows in the table

    The table is updated frequently

    The indexed columns are referenced as part of an expression

    The USER_INDEXES data dictionary view contains the nameof the index and its uniqueness.

    The USER_IND_COLUMNS view contains the index name,the table name, and the column name.

    When Not to Create an Index

  • 8/3/2019 Advanced Databases - Unit 1

    10/40

    10

    An index on a file speeds up selections on the search key fieldsfor the index.

    Any subset of the fields of a relation can be the search keyfor an index on the relation.

    Search key is not the same as key(minimal set of fields thatuniquely identify a record in a relation).

    An index contains a collection ofdata entries, and supportsefficient retrieval of all data entries k*with a given key valuek.

    Indexes

  • 8/3/2019 Advanced Databases - Unit 1

    11/40

    11

    Alternatives for Data Entry k* in Index

    In a data entry k* we can store:

    1. Actual data record with search key value k, -Clustered

    2. A data entry is a pair, where rid is the record id

    of data record with search key value k3. A data entry is a where rid-list is a list of

    record ids of data records with search key value k

    Note: Alternative 2 & 2 are unclustered

  • 8/3/2019 Advanced Databases - Unit 1

    12/40

    12

    Index Classification

    Primary vs. secondary: If search key contains primary key, then called primary

    index. Unique index: Search key contains a candidate key.

    Clusteredvs. unclustered:

    If order of data records is the same as, or `close to, order of data entries, then

    called clustered index. Alternative 1 implies clustered

    A file can be clustered on at most one search key.

    Cost of retrieving data records through index varies greatly based on whether

    index is clustered or not!Index entries

    Data entries

    direct search for

    (Index File)

    (Data file)

    data entries

    Data entries

    CLUSTEREDUNCLUSTERED

    Data Records Data Records

  • 8/3/2019 Advanced Databases - Unit 1

    13/40

    13

    Choice of IndexesChoice of Indexes

    One approach: consider the most important queries in turn.

    Consider the best plan using the current indexes, and see if a better

    plan is possible with an additional index. If so, create it.

    Before creating an index, must also consider the impact on updates

    in the workload

    Trade-off: indexes can make queries go faster, updatesslower. Require disk space, too.

  • 8/3/2019 Advanced Databases - Unit 1

    14/40

    14

    G1: Whether to Index?

    Do not build index if query component is more on updates

    Create index to speed up for query operation

    G2:Choice of Search key

    Attributes in WHERE clause are candidates for index keys.

    Exact match condition suggests hash index.

    Equality query or exact -match: Every field value is equal to a constant

    value. E.g. wrt index: age=20 and sal =75

    Range query suggests tree index. Range query: Some field value is not a constant. E.g.:

    age>20 and sal > 10

    Benefits from B+ Tree Index, Clustering benefits range queries

    Clustering is especially useful for range queries; can also help onequality queries if there are many duplicates.

    Guidelines for Index Selection

  • 8/3/2019 Advanced Databases - Unit 1

    15/40

    15

    G3:Multi-attribute search keys should be considered when a WHERE

    clause contains several conditions.

    Order of attributes is important for range queries.

    Such indexes can sometimes enable index-only strategies for important

    queries. For index-only strategies, clustering is not important!

    G4: Whether to Cluster:

    At most one index on a given relation can be clustered & clustering affects

    performance greatly, so the choice of clustered index is important

    Range queries benefits from clustering If an index enables an index only evaluation strategy, no need of clustered

    index

    Guidelines for Index Selection

  • 8/3/2019 Advanced Databases - Unit 1

    16/40

    16

    G5:Hash versus Tree Index B+Tee index is preferable ,it supports range queries and equality

    queries

    When considering a join condition: Hash index is better in the case of Index nested loop join and equality

    queries B+-tree on inner is very good for Index Nested Loops

    Should be clustered if join column is not key for inner, and innertuples need to be retrieved.

    Clustered B+ tree on join column(s) is good for Sort-Merge.

    G6: Balancing the Cost of Index Maintenance If index slow down the frequent update operation, drop the index

    Adding an index may well speed up given update operation. Forexample an index on employee id could speed up the operation of theincreasing the salary of a given employee.

    Guidelines for Index Selection

  • 8/3/2019 Advanced Databases - Unit 1

    17/40

    17

    Example for Index Selection

    SELECT E.ename, D.mgr FROM Emp E, Dept D

    WHERE D.dname=Toy AND E.dno=D.dno

    Hash index onD.dnamesupports Toy selection.

    Given this, index on D.dno is not needed.

    Hash index onE.dno allows us to get matching (inner) Emptuples for each selected (outer) Dept tuple.

    What if WHERE included: `` ... AND E.age=25 ?

    Could retrieve Emp tuples using index onE.age, then join

    with Dept tuples satisfying dname selection. Comparableto strategy that usedE.dno index.

    So, ifE.age index is already created, this query providesmuch less motivation for adding anE.dno index.

    Index onD.dname

    Index on E.dnoinstead of d.dno

    Index on E.age noneed of index on

    E.dno

  • 8/3/2019 Advanced Databases - Unit 1

    18/40

    18

    Example for Index Selection

    SELECT E.ename, D.mgr FROM Emp E, Dept D WHERE E.sal

    BETWEEN 10000 AND 20000 AND E.hobby=Stamps AND

    E.dno=D.dno

    Clearly, Emp should be the outer relation.

    Suggests that we build a hash index onD.dno. What index should we build on Emp?

    B+ tree onE.sal could be used, OR an index onE.hobby could be used.

    Only one of these is needed, and which is better depends upon the

    selectivity of the conditions.

    As a rule of thumb, equality selections more selective than rangeselections.

    Selective: number of tuple from database-less number of tuple-

    good selective-more number of tuple-poor selectivy

  • 8/3/2019 Advanced Databases - Unit 1

    19/40

    19

    B+ tree index on E.age can be used to get qualifying tuples.

    How selective is the condition?

    Is the index clustered?

    Consider the GROUP BY query.

    If many tuples haveE.age > 10, usingE.age index and sorting theretrieved tuples may be costly.

    ClusteredE.dno index may be better!

    Equality queries and duplicates:

    Clustering onE.hobby helps!

    Examples of Clustered Indexes

    SELECT E.dnoFROM Emp EWHERE E.age>40

    SELECT E.dno, COUNT (*)FROM Emp E

    WHERE E.age>10GROUP BY E.dno

    SELECT E.dnoFROM Emp E

    WHERE E.hobby=Stamps

  • 8/3/2019 Advanced Databases - Unit 1

    20/40

    20

    Clustering and Joins

    SELECT E.ename, D.mgr FROM Emp E, Dept D

    WHERE D.dname=Toy AND E.dno=D.dno

    Clustering is especially important when accessing inner tuplesin INL.

    Should make index onE.dno clustered. Suppose that the WHERE clause is instead:

    WHERE E.hobby=Stamps AND E.dno=D.dno

    If many employees collect stamps, Sort-Merge join may be

    worth considering. A clusteredindex on D.dno wouldhelp.

    Summary: Clustering is useful whenever many tuples are to beretrieved.

  • 8/3/2019 Advanced Databases - Unit 1

    21/40

    21

    To retrieve Emp records with age=30 AND sal=4000, an index on

    would be better than an index on age or an index on sal.

    If condition is: 20

  • 8/3/2019 Advanced Databases - Unit 1

    22/40

    22

    Records from more than one relation to be stored in a singlefileCo-clustering.

    Parts(pid,pname,cost,supplierid)

    Assembly(partid,componentid,quantity)

    Select P.Pid, A.Componentid from Parts P,Assembly Awhere P.pid=A.partid and P.supplierid= KAVEN

    Co-cluster two tables, store records of two table together,with each Parts record P followed by all the Assemblyrecords A.

    Co-Clustering Two Relations

  • 8/3/2019 Advanced Databases - Unit 1

    23/40

    23

    Co-Clustering

    It can speed of Joins, in particular key-foreign key joins

    corresponding to 1:N rel

    A sequential scan of either relation becomes slower .

    All inserts deletes and updates that alter records lengths

    become slower

    I d th t E bl I d

  • 8/3/2019 Advanced Databases - Unit 1

    24/40

    24

    Indexes that Enable Index

    Only Plans

    A number ofqueries can beansweredwithout

    retrieving anytuples from oneor more of therelationsinvolved if a

    suitable indexis available.

    SELECT D.mgrFROM Dept D, Emp EWHERE D.dno=E.dno

    SELECT D.mgr, E.eidFROM Dept D, Emp EWHERE D.dno=E.dno

    SELECT E.dno, COUNT(*)

    FROM Emp EGROUP BY E.dno

    SELECT E.dno, MIN(E.sal)FROM Emp E

    GROUP BY E.dno

    SELECTAVG(E.sal)FROM Emp EWHERE E.age=25 AND

    E.sal BETWEEN 3000 AND 5000

    B-tree trick!

    or

  • 8/3/2019 Advanced Databases - Unit 1

    25/40

    25

    The choice of conceptual schema should be guided by theworkload, in addition to redundancy issues:

    We may settle for a 3NF schema rather than BCNF.

    Workload may influence the choice we make in

    decomposing a relation into 3NF or BCNF. We may further decompose a BCNF schema!

    We might denormalize (i.e., undo a decomposition step), orwe might add fields to a relation.

    We might consider horizontal decompositions. If such changes are made after a database is in use, called

    schema evolution; might want to mask some of these changesfrom applications by defining views

    Tuning the Conceptual Schema

  • 8/3/2019 Advanced Databases - Unit 1

    26/40

    26

    Example Schemas

    Contracts (Cid, Sid, Jid, Did, Pid, Qty, Val)

    Depts (Did, Budget, Report)

    Suppliers (Sid, Address)

    Parts (Pid, Cost) Projects (Jid, Mgr)

    We will concentrate on Contracts, denoted as CSJDPQV. The

    following ICs are given to hold: JP C, SD P,

    C is the primary key. What are the candidate keys for CSJDPQV?

    What normal form is this relation schema in?

  • 8/3/2019 Advanced Databases - Unit 1

    27/40

    27

    CSJDPQV can be decomposed into SDP and CSJDQV, andboth relations are in BCNF. (Which FD suggests that we dothis?)

    Lossless decomposition, but not dependency-preserving.

    Adding CJP makes it dependency-preserving as well. Suppose that this query is very important:

    Find the number of copies Q of part P ordered in contractC.

    Requires a join on the decomposed schema, but can beanswered by a scan of the original relation CSJDPQV.

    Could lead us to settle for the 3NF schema CSJDPQV

    Settling for 3NF vs BCNF

  • 8/3/2019 Advanced Databases - Unit 1

    28/40

    28

    Suppose that the following query is important:

    Is the value of a contract less than the budget of

    the department?

    To speed up this query, we might add a field budgetB to Contracts.

    This introduces the FD D B wrt Contracts.

    Thus, Contracts is no longer in 3NF.

    Denormalization

  • 8/3/2019 Advanced Databases - Unit 1

    29/40

    29

    There are 2 ways to decompose CSJDPQV into BCNF:

    SDP and CSJDQV; lossless-join but not dep-preserving.

    SDP, CSJDQV and CJP; dep-preserving as well.

    The difference between these is really the cost of enforcing theFD JP C.

    2nd decomposition: Index on JP on relation CJP

    Choice of Decompositions

  • 8/3/2019 Advanced Databases - Unit 1

    30/40

    30

    Choice of Decompositions

    The following ICs were given to hold:JP C, SD P, C is the primary key.

    Suppose that, in addition, a given supplier always charges thesame price for a given part: SPQ V.

    If we decide that we want to decompose CSJDPQV intoBCNF, we now have a third choice:

    Begin by decomposing it into SPQV and CSJDPQ.

    Then, decompose CSJDPQ (not in 3NF) into SDP,

    CSJDQ. This gives us the lossless-join decomp: SPQV, SDP,

    CSJDQ.

    To preserve JP C, we can add CJP, as before.

    Choice: { SPQV, SDP, CSJDQ } or { SDP, CSJDQV } ?

    Choice of Decompositions (cont)

  • 8/3/2019 Advanced Databases - Unit 1

    31/40

    31

    Suppose that we choose { SDP, CSJDQV }. This is in BCNF,

    and there is no reason to decompose further (assuming that all

    known ICs are FDs).

    However, suppose that these queries are important:

    Find the contracts held by supplier S.

    Find the contracts that department D is involved in.

    Decomposing CSJDQV further into CS, CD and CJQV could

    speed up these queries. (Why?)

    On the other hand, the following query is slower:

    Find the total value of all contracts held by supplier S.

    Decomposition of a BCNF Relation

  • 8/3/2019 Advanced Databases - Unit 1

    32/40

    32

    Our definition of decomposition: Relation is replaced by a

    collection of relations that areprojections. Most important

    case.

    Sometimes, might want to replace relation by a collection of

    relations that are selections.

    Each new relation has same schema as the original, but a

    subset of the rows.

    Collectively, new relations contain all rows of the original.

    Typically, the new relations are disjoint.

    Horizontal Decompositions

  • 8/3/2019 Advanced Databases - Unit 1

    33/40

    33

    Suppose that contracts with value > 10000 are subject to

    different rules. This means that queries on Contracts will often

    contain the condition val>10000.

    One way to deal with this is to build a clustered B+ tree index

    on the val field of Contracts.

    A second approach is to replace contracts by two new

    relations: LargeContracts and SmallContracts, with the same

    attributes (CSJDPQV).

    Performs like index on such queries, but no index

    overhead.

    Can build clustered indexes on other attributes, in addition!

    Horizontal Decompositions

  • 8/3/2019 Advanced Databases - Unit 1

    34/40

    34

    If a query runs slower than expected, check if an index needsto be re-built, or if statistics are too old.

    Sometimes, the DBMS may not be executing the plan you hadin mind. Common areas of weakness:

    Selections involving null values. Selections involving arithmetic or string expressions.

    Selections involving OR conditions.

    Lack of evaluation features like index-only strategies or

    certain join methods or poor size estimation. Check the plan that is being used! Then adjust the choice of

    indexes or rewrite the query/view

    Tuning Queries

  • 8/3/2019 Advanced Databases - Unit 1

    35/40

    35

    Complicated by interaction of:

    NULLs, duplicates, aggregation, subqueries.

    Guideline: Use only one query block, if possible

    Tuning Queries

    SELECT DISTINCT *FROM Sailors S

    WHERE S.sname IN

    (SELECT Y.sname

    FROM YoungSailors Y)

    SELECT DISTINCT S.*FROM Sailors S,

    YoungSailors Y

    WHERE S.sname = Y.sname

    =

  • 8/3/2019 Advanced Databases - Unit 1

    36/40

    36

    Minimize the use of DISTINCT: dont need it if duplicates are

    acceptable, or if answer contains a key.

    Minimize the use of GROUP BY and HAVING

    Guidelines for Query Tuning

    SELECT MIN (E.age)FROM Employee EGROUP BY E.dnoHAVING E.dno=102

    SELECT MIN (E.age)FROM Employee EWHERE E.dno=102

    Consider DBMS use of index when writing arithmetic

    expressions: E.age=2*D.agewill benefit from index on

    E.age, but might not benefit from index onD.age!

  • 8/3/2019 Advanced Databases - Unit 1

    37/40

    37

    Avoid using intermediate relations:

    Guidelines for Query Tuning

    SELECT * INTO TempFROM Emp E, Dept D

    WHERE E.dno=D.dnoAND

    D.mgrname=Joe

    SELECT T.dno, AVG(T.sal)

    FROM Temp TGROUP BY T.dno

    SELECT E.dno, AVG(E.sal)FROM Emp E, Dept DWHERE E.dno=D.dno

    AND D.mgrname=JoeGROUP BY E.dno

    =

    If there is a dense B+ tree index on , an index-only plan

    can be used to avoid retrieving Emp tuples in the second query

    Conclusion

  • 8/3/2019 Advanced Databases - Unit 1

    38/40

    38

    Understanding the nature of the workloadfor the application,and the performance goals, is essential to developing a gooddesign.

    What are the important queries and updates? Whatattributes/relations are involved?

    Indexes must be chosen to speed up important queries (andperhaps some updates!).

    Index maintenance overhead on updates to key fields.

    Choose indexes that can help many queries, if possible.

    Build indexes to support index-only strategies. Clustering is an important decision; only one index on a

    given relation can be clustered!

    Order of fields in composite index key can be important.

    Static indexes may have to be periodically re-built.

    Statistics have to be periodically updated

    Conclusion

    Important Points in Physical DatabaseDesign

    Conclusion

  • 8/3/2019 Advanced Databases - Unit 1

    39/40

    39

    Over time, indexes have to be fine-tuned (dropped, created, re-clustered, ...) for performance.

    Should determine the plan used by the system, and adjustthe choice of indexes appropriately.

    System may still not find a good plan: Only left-deep plans?

    Null values, arithmetic conditions, string expressions, theuse of ORs, nested queries, etc. can confuse an optimizer.

    So, may have to rewrite the query/view: Avoid nested queries, temporary relations, complex

    conditions, and operations like DISTINCT and GROUPBY

    Conclusion

    Important Points in Physical DatabaseDesign

  • 8/3/2019 Advanced Databases - Unit 1

    40/40

    40

    Tune U Minds to Solve the Problems


Recommended