0% found this document useful (0 votes)
7 views4 pages

23bce385 DBMS PR 8 Final

The document outlines a practical exercise on indexing, views, and performance analysis in a Database Management System using Oracle Database. It includes the creation of sample tables, data insertion, and execution of queries with and without indexes, demonstrating the impact on performance. The conclusion emphasizes that indexing significantly improves query execution time, while views enhance query structure without major performance gains on their own.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

23bce385 DBMS PR 8 Final

The document outlines a practical exercise on indexing, views, and performance analysis in a Database Management System using Oracle Database. It includes the creation of sample tables, data insertion, and execution of queries with and without indexes, demonstrating the impact on performance. The conclusion emphasizes that indexing significantly improves query execution time, while views enhance query structure without major performance gains on their own.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Name :- Harshil Zalavadiya

Roll Number :- 23BCE385


Subject :- Database Management System (2CS505CC23)

Practical :- 8
Aim :- Indexing, View, and Performance Analysis ,Comparing Query
Execution Time with and without Indexes and Views

1. Environment Setup

• Database: Oracle Database (using SQL*Plus)


• Tables: Students, Enrollments, Courses
• Metrics: Execution time (measured with SET TIMING ON) and query execution plans
using EXPLAIN PLAN.

2. Sample Tables Creation


CREATE TABLE Students (
StudentID INT PRIMARY KEY,
FullName VARCHAR(255),
Programme VARCHAR(50),
EnrollmentDate DATE
);

CREATE TABLE Courses (


CourseID INT PRIMARY KEY,
CourseName VARCHAR(255)
);

CREATE TABLE Enrollments (


EnrollmentID INT PRIMARY KEY,
StudentID INT,
CourseID INT,
Marks INT,
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);
3. Sample Data Insertion
INSERT INTO Students (StudentID, FullName, Programme, EnrollmentDate) VALUES
(1, 'Ali Shah', 'BCE', '2022-01-10'),
(2, 'Sara Khan', 'BCE', '2021-01-11'),
(3, 'David Warner', 'CSE', '2021-01-12');

INSERT INTO Courses (CourseID, CourseName) VALUES


(1, 'Database Management System'),
(2, 'Operating Systems'),
(3, 'Software Engineering');

INSERT INTO Enrollments (EnrollmentID, StudentID, CourseID, Marks) VALUES


(1, 1, 1, 90),
(2, 2, 1, 85),
(3, 3, 2, 88);

4. Queries Without Index (Baseline)

Enable Timing in SQL*Plus:

SET TIMING ON;

4.1 Find Students of ‘BCE’ programme

SELECT * FROM Students WHERE Programme = 'BCE';

4.2 Find students enrolled in ‘Database Management System’

SELECT S.* FROM Students S


JOIN Enrollments E ON S.StudentID = E.StudentID
JOIN Courses C ON E.CourseID = C.CourseID
WHERE C.CourseName = 'Database Management System';

4.3 Find students with ‘Shah’ surname

SELECT * FROM Students WHERE FullName LIKE '%Shah';

4.4 Find highest marks in each course

SELECT CourseID, MAX(Marks) AS HighestMarks FROM Enrollments GROUP BY


CourseID;

5. Create Indexes and Measure Impact

5.1 Create Indexes

CREATE INDEX idx_programme_fullname ON Students (Programme, FullName);


CREATE UNIQUE INDEX idx_unique_fullname ON Students (FullName);
CREATE INDEX idx_courseid_marks ON Enrollments (CourseID, Marks);
5.2 Rerun Queries with Indexes

SELECT * FROM Students WHERE Programme = 'BCE';


SELECT S.* FROM Students S
JOIN Enrollments E ON S.StudentID = E.StudentID
JOIN Courses C ON E.CourseID = C.CourseID
WHERE C.CourseName = 'Database Management System';
SELECT * FROM Students WHERE FullName LIKE '%Shah';
SELECT CourseID, MAX(Marks) AS HighestMarks FROM Enrollments GROUP BY
CourseID;

Execution Plan Analysis: Use EXPLAIN PLAN FOR before each query and retrieve the plan
using:

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);

6. Create, Update, and Query Views

6.1 Create Views

CREATE VIEW BCE_Students AS


SELECT * FROM Students WHERE Programme = 'BCE';

CREATE VIEW DBMS_Students AS


SELECT S.* FROM Students S
JOIN Enrollments E ON S.StudentID = E.StudentID
JOIN Courses C ON E.CourseID = C.CourseID
WHERE C.CourseName = 'Database Management System';

CREATE VIEW Highest_Marks_Per_Course AS


SELECT CourseID, MAX(Marks) AS HighestMarks FROM Enrollments GROUP BY
CourseID;

6.2 Update a View

CREATE OR REPLACE VIEW BCE_Students AS


SELECT StudentID, FullName FROM Students WHERE Programme = 'BCE';

6.3 Query Views and Analyze Performance

SELECT * FROM BCE_Students;


SELECT * FROM DBMS_Students;
SELECT * FROM Highest_Marks_Per_Course;

7. Drop a View
DROP VIEW BCE_Students;
DROP VIEW DBMS_Students;
DROP VIEW Highest_Marks_Per_Course;
Performance Comparison

1. Without Indexes:
o Queries took longer execution time due to full table scans.
o EXPLAIN PLAN showed sequential scans instead of index usage.
2. With Indexes:
o Execution time reduced significantly.
o EXPLAIN PLAN indicated index-based access, reducing scan time.
3. Using Views:
o Simplified query logic and improved readability.
o Performance impact varied based on view complexity.

Conclusion

• Indexing improved query execution time by reducing full table scans.


• Views provided structured and reusable queries but did not significantly impact
performance alone.
• A combination of indexes and well-designed queries led to optimal performance.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy