Sankalp For DBMS - Indexing and ER Diagram
Sankalp For DBMS - Indexing and ER Diagram
Sankalp For DBMS - Indexing and ER Diagram
Diagram
LECTURE 6
1/11/2021
1/11/2021
Why indexing?
1/11/2021
Suppose key field size is 2 byte and record pointer size is 4 byte then the size of index is 6
byte. Size of record is 100 byte.
(1)What is size of index file to store 2000 records.
If block size of hard disk is 512 byte.
(2)How many hard disk blocks required to store index file?
(a) Using Spanned file organization.
(b) Using Unspanned file organization.
(3) What is the maximum number of blocks required to access to search a record?(a) if
indexing is used (b) if indexing is not used.
Solution:
1/11/2021
Types of Index:
(1) Dense Index : In a dense index, a record is created for every search
key valued in the database. This helps you to search faster but needs
more space to store index records.
1/11/2021
(2) Sparse(Non dense) Index: It is an index record that appears for
only some of the values in the file. Sparse Index helps you to resolve
the issues of dense Indexing. In this method of indexing technique, a
range of index columns stores the same data block address, and when
data needs to be retrieved, the block address will be fetched.
However, sparse Index stores index records for only some search-key
values. It needs less space, less maintenance overhead for insertion,
and deletions but It is slower compared to the dense Index for
locating records.
1/11/2021
Types of Indexing:
(1) Primary Indexing : Indexing is performed on a key field of
ordered file. It is always Sparse(non dense).
Anchor record
1/11/2021
Secondary Index: indexing is performed on a key/non key field of
unordered file.
Secondary Index may be dense or sparse.
Non ordered file + key field then dense indexing.
8
1
5
2
2
3
3
4
5
6
6
7
7
1
8
4
1/11/2021
Non ordered file + non key field then sparse indexing.
1
2
3
1
1
2 3
3 1
4 4
3
2
4
1 1/11/2021
2
Clustered Index: indexing on non key field of ordered file.
Index file is maintained according to the data in ordered file.
Anchor record may be possible.
1/11/2021
1/11/2021
Consider a unordered file with 100000000 records with record size of
400 bytes stored with a spanned record organization. We will assume
that no system related information is stored within a block. Suppose
that we construct a single level, secondary index for the file where
search key field is 16 bytes and block pointers is 4 bytes. Assume that
hard disk block size is 4096 bytes.
(1) How many block would be needed to store record file?
(2) How many block would be needed to store index file?
1/11/2021
Multi Level Indexing: Multilevel Indexing is created when a primary
index size is too large and searching time of record require more disk
access. In this type of indexing method, you can reduce the number
of disk accesses to short any record and kept on a disk as a sequential
file and create a sparse base on that file.
1/11/2021
Suppose 1000 records. Index size 10 bytes. Block size 100 bytes.
(1) Single level indexing require 100 blocks to store index file. So to search data we need to
access (100+1) disk block.
(2) If we use multilevel(n-level) indexing then it require (n+1) disk access.
1/11/2021
Q1.______is an index specified on the ordering key field of an ordered file of
records.
(a) Primary Key (b) Clustering index (c) Secondary index (d) Both a and c
Q2. ______is an index specified on the non key ordering field of an ordered
file of records.
(a) Primary Key (b) Clustering index (c) Secondary index (d) Both a and c
Q3. ______is an index specified on the key or non key non ordering field of a
file of records.
(a) Primary Key (b) Clustering index (c) Secondary index (d) Both a and c
1/11/2021
B and B+ Trees
3 7 12 21
◼ B trees are specialized n-ary search
trees
◼ B+ trees are variation of B tree.
◼ Each node has many keys
◼ Sub tree between two keys x
and y contains values v such
that x < v < y v<3 3<v<7 7<v<12 12<v<21 21<v
◼ binary search within a node to
find correct sub tree.
◼ Binary Search tree is B tree
where n = 2.
1/11/2021
B & B+ Tree Properties
• Properties
– All leaf node should at same level.
– For root node : For non root node :
– Maximum no of keys = n -1 Maximum no of keys = n-1
𝑛−1
– Minimum no of keys = 1 Minimum no of keys = ˪ ˩
2
1/11/2021
Difference
B tree B+ tree
➢ Process of insertion and deletion ➢ Process of insertion and deletion
➢ Height : less ➢ Height : more
➢ Searching : random search faster. ➢ Searching : range wise search
faster.
➢ Internal as well as external nodes
contain search keys and record ➢ Internal nodes contain only search keys
(no record pointer). Record pointer
pointer. present at leaf node.
➢ Keys distributed over the tree. ➢ All keys present at leaf node in
sorted sequence and all leaf
nodes connected via link list.
1/11/2021
1/11/2021
1/11/2021
B tree : B+ tree :
Keys : 5, 20, 10, 15, 25, 35,
22, 40, 30, 21, 50, 60, 70, Keys : 5, 20, 10, 15, 25, 35,
80. 22, 40, 30, 21, 50, 60, 70, 80.
1/11/2021
Storage :
B tree: B+ tree:
Internal node: Internal node:
1/11/2021
Q1.With reference to the B+ tree index of order 1 shown
below, the minimum number of nodes (including the root
node) that must be fetched in order to satisfy the following
query: “Get all records with a search key greater than or equal
to 7 and less than 15” is ____.
1/11/2021
Consider a B+-tree in which the maximum number of keys in a node is 5.
What is the minimum number of keys in any non-root node?
(A) 1 (B) 2 (C) 3 (D) 4
1/11/2021
1/11/2021
1/11/2021
For B+ tree of order 101 , consisting of 3 levels, the maximum number of leaf node would be if root is at
level one.
(A) 101 (B) 10201 (C ) 1000 (D) 303
1/11/2021
Mapping E-R Diagrams to
Relational Schemas
1/11/2021
ER to Relational model
1/11/2021
ER to Relational model
1/11/2021
1/11/2021
ER to Relational model
1/11/2021
ER to Relational model
1/11/2021
ER to Relational model
1/11/2021
Generalization –
Generalization is the process of extracting common properties from a
set of entities and create a generalized entity from it
Specialization –
In specialization, an entity is divided into sub-entities based on their
characteristics. It is a top-down approach where higher level entity is
specialized into two or more lower level entities.
1/11/2021
Consider the following ER diagram.
A. 2 B. 3 C.4 D.5
1/11/2021
What is the min and max number of tables required to convert an ER
diagram with 2 entities and 1 relationship between them with partial
participation constraints of both entities?
1/11/2021
Let M and N be two entities in an E-R diagram with simple single value
attributes. R1 and R2
are two relationship between M and N, where as R1 is one-to-many and R2 is
many-to-many.
The minimum number of tables required to represent M, N, R1 and R2 in the
relational model are ______
1/11/2021
Which one of the following is used to represent the supporting many-one
relationships of a weak entity set in an entity-relationship diagram ?
(A) Diamonds with double/bold border
(B) Rectangles with double/bold border
(C) Ovals with double/bold border
(D) Ovals that contain underlined identifiers
1/11/2021
Given the basic ER and relational models, which of the following is INCORRECT?
(A) An attribute of an entity can have more than one value
(B) An attribute of an entity can be composite
(C) In a row of a relational table, an attribute can have more than one value
(D) In a row of a relational table, an attribute can have exactly one value or a
NULL value
1/11/2021
In an Entity-Relationship (ER) model, suppose R is a many-to-one
relationship from entity set E1 to entity set E2. Assume that E1 and E2
participate totally in R and that the cardinality of E1 is greater that the
cardinality of E2.
Which one of the following is true about R?
(A) Every entity in E1 is associated with exactly one entity in E2.
(B) Some entity in E1 is associated with more than one entity in E2.
(C) Every entity in E2 is associated with exactly one entity in E1.
(D) Every entity in E2 is associated with at most one entity in E1.
1/11/2021
1/11/2021