UNIT1 Notes ABDA
UNIT1 Notes ABDA
Performance Tuning
Optimizing SQL performance is crucial because poorly optimized queries can severely affect
the speed of the database, increase CPU usage, and lead to system downtime. By improving
query execution times and resource utilization, performance tuning enhances the overall
performance of the SQL database.
Indexes - Indexes in SQL are used to improve the speed of data retrieval operations on a
database table. They are similar to the index in a book, where instead of reading through the
entire content, you can quickly jump to the specific page you're looking for. In the case of
SQL, indexes help speed up query performance by allowing the database engine to quickly
locate the rows that satisfy a query condition.
Benefits of Indexes:
Lower Disk I/O: Reduces the load on your database by limiting the amount of data
scanned.
Syntax
Types of Index –
1. Single-Column Index/simple index : A single-column index is an index created on one
column of a table. This is the most basic type of index, and it speeds up queries that filter or
sort data based on a single column
Eg: Suppose you have a students table with first_name and last_name columns, and you
often query students by both names:
3. Unique Index: A unique index ensures that the values in the indexed column(s) are
unique. It is automatically created when you add a UNIQUE constraint to a column or a set
of columns.
For the users table, where the email column must have unique values, you can create a
unique index:
4. Reverse key index : In a Reverse Key Index, the bytes of the index key are reversed before
being stored in the B-tree index structure. A Reverse Key Index is a special type of index
used primarily to distribute data more evenly across index blocks, improving performance
in specific high-insertion use cases—especially in Oracle Database.
5.A Bitmap Index is a specialized type of SQL index that uses bitmaps (bit arrays) instead of
traditional tree structures (like B-trees) to represent index entries. It is especially efficient for
queries on low-cardinality columns—columns with a small number of distinct values (e.g.,
gender, status, region).
DROPPING INDEX:
ROWID is a pseudo-column that exists in every table and returns a unique address for each
row.
The ROWID is not a physical column that you can modify. It’s a system-generated identifier.
Selecting ROWID:
1. Fast Retrieval:
2. Efficient Deletion/Update:
o Using ROWID for DELETE or UPDATE ensures that you target the exact row
without ambiguity. This is often used in scenarios where the table doesn’t
have a unique identifier (like a PRIMARY KEY).
o In large tables, using ROWID can speed up queries, especially when dealing
with indexed or non-unique columns. Since ROWID is unique and fast to
access, it reduces the overhead of scanning the entire table.
The ROWNUM function is used to assign a unique, sequential number to rows in the result
set of a query. It is most commonly used in Oracle databases.
FROM employees;
Example SELECT ROWNUM, employee_name, department
FROM employees;
1 John Sales
2 Jane HR
3 Bob Marketing
View in sql
Views in SQL are a type of virtual table that simplifies how users interact with data across
one or more tables. Unlike traditional tables, a view in SQL does not store data on disk;
instead, it dynamically retrieves data based on a pre-defined query each time it’s accessed.
SQL views are particularly useful for managing complex queries, enhancing security, and
presenting data in a simplified forma
FROM table_name
WHERE condition;
Name VARCHAR(100)
);
CustomerID INT,
OrderDate DATE,
);
SELECT
c.CustomerID,
c.Name,
o.OrderID,
o.OrderDate,
o.TotalAmount
FROM Customers c
CLUSTER INDEX
A clustered index determines the physical order of data in a table. There can be only one
clustered index per table because the table rows themselves are stored in the order of the
clustered index.
Key Characteristics
ON Employees(Department);
Indexed Cluster :
An Indexed Cluster in Oracle is a way of storing related rows from different tables together
based on a common key — but instead of using a hash function (like a hash cluster), it uses a
cluster index (B-tree) to locate rows.
It’s a physical data organization technique that improves join performance between tables
sharing the same cluster key.
Syntax
ON CLUSTER customer_cluster;
HASH CLUSTER :
A Hash Cluster is a special data storage method unique to Oracle Database. It allows rows to
be stored together based on the result of a hash function applied to a key value — improving
direct access performance for equality searches (=).
Instead of using a traditional index, Oracle uses a hash function to determine where to store
and find the data.
The dataset is static or rarely updated (hash collisions can cause performance issues
during inserts/updates).
Syntax
EmployeeID NUMBER
)
HASHKEYS 100;
Access
Cluster index (B-tree) Hash function Clustered B-tree index
method
Best for Multi-table joins Fast equality lookups Sorting, range scans
Multiple
Yes No No
tables