DBMS JOIN INDEXING (1)
DBMS JOIN INDEXING (1)
TYPES
1) Inner join
Inner Join is a join operation in DBMS that combines two or more table based on related
columns and return only rows that have matching values among tables.
Syntax
FROM table1
INNER JOIN table2
ON table1.matching_column = table2.matching_column;
Query
SELECT EMPLOYEE.EMP_NAME, PROJECT.DEPARTMENT
FROM EMPLOYEE
INNER JOIN PROJECT
ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;
Syntax
The first column is the Search key that contains a copy of the primary key or candidate key
of the table.
These values are stored in sorted order so that the corresponding data can be accessed
quickly (Note that the data may or may not be stored in sorted order).
The second column is the Data Reference which contains a set of pointers holding the
address of the disk block where that particular key value can be found.
Attributes of Indexing
Access Types: This refers to the type of access such as value-based search, range access,
etc.
Access Time: It refers to the time needed to find a particular data element or set of
elements.
Insertion Time: It refers to the time taken to find the appropriate space and insert new
data.
Deletion Time: Time taken to find an item and delete it as well as update the index
structure.
Space Overhead: It refers to the additional space required by the index
Indexing methods :
1)Primary indexing:
In this case, the primary key of the database table is used to create the index.
As primary keys are unique and are stored in sorted manner, the performance of searching
operation is quite efficient.
The primary index is classified into two types: Dense Index and Sparse Index.
Dense index
The dense index contains an index record for every search key value in the data file. It
makes searching faster.
In this, the number of records in the index table is same as the number of records in the
main table.
It needs more space to store index record itself. The index records have the search key and a
pointer to the actual record on the disk.
Sparse Index:
The index record appears only for a few items in the data file. Each item points to a block as
shown.
To locate a record, we find the index record with the largest search key value less than or
equal to the search key value we are looking for.
We start at that record pointed to by the index record, and proceed along the pointers in
the file (that is, sequentially) until we find the desired record.
2)Clustered indexing:
Clustering index is defined on an ordered data file. The data file is ordered on a non-key
field.
In some cases, the index is created on non-primary key columns which may not be unique
for each record. In such cases, in order to identify the records faster, we will group two or
more columns together to get the unique values and create index out of them. This method
is known as clustering index. Basically, records with similar characteristics are grouped
together and indexes are created for these groups.
3)Non-Clustered Indexing
A non-clustered index just tells us where the data lies, i.e. it gives us a list of virtual pointers
or references to the location where the data is actually stored. Data is not physically stored
in the order of the index. Instead, data is present in leaf nodes. For example, the contents
page of a book. Each entry gives us the page number or location of the information stored.
The actual data here (information on each page of book) is not organized but we have an
ordered reference (contents page) to where the data points actually lie.
4)Secondary Index
It is used to optimize query processing and access records in a database with some
information other than the usual search key (primary key). In these two levels of indexing
are used in order to reduce the mapping size of the first level and in general. Initially, for the
first level, a large range of numbers is selected so that the mapping size is small. Further,
each range is divided into further sub ranges. In order for quick memory access, first level is
stored in the primary memory. Actual physical location of the data is determined by the
second mapping level.