0% found this document useful (0 votes)
95 views5 pages

Database Indexing and File Organization Analysis

This document discusses database indexing and performance. It includes: 1) Questions about sorting data, clustered vs unclustered indexes, and different file organizations for various database operations. 2) A scenario involving professors and departments where indexes would help optimize specific queries. 3) Questions about hash indexing, linear hashing, and its performance benefits over tree indexes for tables with few inserts and frequent lookups by item ID. 4) An assignment to implement a student database with indexing to improve query performance, and report on the findings.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views5 pages

Database Indexing and File Organization Analysis

This document discusses database indexing and performance. It includes: 1) Questions about sorting data, clustered vs unclustered indexes, and different file organizations for various database operations. 2) A scenario involving professors and departments where indexes would help optimize specific queries. 3) Questions about hash indexing, linear hashing, and its performance benefits over tree indexes for tables with few inserts and frequent lookups by item ID. 4) An assignment to implement a student database with indexing to improve query performance, and report on the findings.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Part 1: Concepts and Principles

Question 1
A. Briefly explain the three main alternatives for sorting information in a data entry of an
index.

B. Define clustered index, and discuss the relation between the three alternatives and
clustered/unclustered indexes.

Question 2
Consider the following file organizations: sorted files, heap files with an unclustered tree
index on the search key, and heap files with an unclusted hash index. Briefly discuss the
suitability of each of these file organizations to perform the following operations: file
scans, range selections, inserts, and deletes.

Question 3
A. Briefly describe the two internal organizations for heap files (using lists versus
directory of pages).
B. Explain which organization you would choose if records are variable in length.

Question 4
Compare ISAM and B+ Tree index. Explain briefly their differences in handling Search,
Insert and Delete, and discus when you would use ISAM and when you would use B+
Tree index.

Question 5
Does the final structure of a B+ tree depend on the order in which the terms are added to
it? Explain your answer using an illustration example.

Question 6
Explain how extendible hashing uses a directory of buckets and discuss the global depth
of the index and local depth of a bucket.
Part 2: Design considerations for application

Question 1

Consider the following relations:

Professor (profid: integer, name: varchar, salary: integer, age: integer, depid: integer)
Department (did: integer, budget: integer, location: varchar, mgr eid: integer)

Salaries range from $30,000 to $100,000, ages vary from 20 to 80, each department has about 20
employees on average, there are 10 locations, and budgets vary from $100,000 to $1 million.
You can assume uniform distributions of values.

For each of the following queries, what index would you choose to speed up the query? If your
database system does not consider index-only plans (i.e., data records are always retrieved even
if enough information is available in the index entry), how would your answer change? Explain
briefly.

A. Query1: Print name, age, and salary for all professors.


B. Query2: Find the dids of departments that are located in Edmonton and have a budget of
more than $150,000. 

Question 2

The CVT Company is a leader in the manufacture of work clothes. You are hired as database
administrator for the company and your IT supervisor asked you to solve a retrieval speed
problem they used to have with a large file for item records. Your supervisor mentioned that they
have sorted the file but the problem didn’t improve, so they need to create a B+ tree index to
solve the problem. Your supervisor outlined the way to do it: “The best way to accomplish this
task is to scan the file, record by record, inserting each one using the B+ tree insertion
procedure.” Being a fresh graduate, you noticed that since the file is already sorted there is a
better way to do it.

a. What performance and storage utilization problems are there with your
supervisor’s approach? 
b. Explain how the bulk-loading algorithm provides a better alternative than the
proposed scheme. 
Question 3

Your team in charge of database administration was discussing different alternatives for indexing
your organization’s databases. Some tables in one database have very few insertions but they are
used intensively by different services to check for information about items using the item_ID
number. While many of your colleagues proposed using a tree index, you argued for a Hash
index for these tables because it provides an average-case search cost of only slightly more than
one disk I/O. The team leader agrees to adopt your solution but has asked you to write a short
explanation for two questions:

a. How does Linear Hashing provide an average-case search cost of only slightly
more than one disk I/O, given that overflow buckets are part of its data
structure? (6 marks)
b. If a Linear Hashing index using Alternative (1) for data entries contains 10,000
records, with 10 records per page and an average storage utilization of 80 percent,
what is the worst-case cost for an equality search? Under what conditions would
this cost be the actual search cost? (6 marks)
Part 3: Implementation Case

Consider the following database schema with the following relations:

Student (SID, Name, Address, Telephone, Age)


Course (CourseNo, Title, Department, NumberOfCredits, CourseFees)
Registration (SID, CourseNo, startDate, CompleteDate, Grade)

Consider the following queries:

o List the student numbers and names of students who received a grade greater or
equal to 70% in the course “COMP418,” sorted by age ascending.
o List the course numbers and titles of courses that have more than 10 students
getting a grade lower than 50. [(Use group by courseNo and count(SID)].
o List the course numbers and titles of courses whose course fees are between 400
and 600 dollars.
o List all courses in the database.
o Update all the course fees by adding 6 dollars to each course.

Your task is to implement this database using PostgreSQL or any other DBMS of the list
(Oracle, MySQL, DB2, SQL server) then compare the performance of the system before creating
the indexes and after creating the indexes. Make sure that you create indexes that support the
queries.

o You should use test data to identify performance issues: the more data, the better.
Make sure there is sufficient test data in your system to be able to run queries that
can return at least a dozen rows of data even when using the queries. Unless there
is a fair amount of test data, you will not be able to see much difference in query
execution times.
o Decide on the type of indexing that would be most appropriate. This will require
you to read about the different indexing options in your DBMS. The PostgreSQL 9
manual on the subject is available
at [Link] Most DBMSs,
including PostgreSQL, provide an 'ANALYZE,' 'EXPLAIN' or similar command
that can be used to help tune your database and make recommendations on
indexing that you may find very useful.
o Check the performance of the queries before adding indexes. If using PostgreSQL,
you will likely find the EXPLAIN command useful in accomplishing this. There is
a visual EXPLAIN tool available as part of some versions of PgAdmin that you
may want to try. Information on reading and interpreting the results as well as on
how to use the tool is available at
[Link]
[Link]
o Add your indexes. You will probably be using the CREATE INDEX command for
this, but do feel free to use other DBMS tools if they are available. For a better
analysis you may want to add one index at a time and check performance changes
between each addition to discover the cumulative effects of each index.
o Check the performance again, and record the results. If you have the time and
inclination, it would be informative to experiment more with your DBMS to
discover what differences different kinds of indexes make to different queries. If
you have enough test data, you may find considerable differences in performance
as a result.

Write a short report (1-2 pages maximum) that summarizes your findings during the experiment.
The report should include:

o A description of your implementation of the database. Include the SQL code for
implementing the tables. How many records did you enter in each table?
o A description of the execution time of the queries before creating the indexes.
o A description of the created indexes, and a justification of why you think those
indexes would improve the system performance for the specified queries.
o A table comparing both execution times before and after indexing for each query.

Common questions

Powered by AI

Creating indexes reduces the query execution time by enabling quicker data retrievals at the expense of increased storage and maintenance overheads on DML operations like insert, update, or delete. The process should be approached systematically, starting by assessing query execution times without indexes, then adding indexes one at a time, using tools like PostgreSQL's EXPLAIN to identify performance changes. Recording results of each step ensures that benefits outweigh overhead costs, helping highlight the most impactful indexes in terms of query performance enhancement .

ISAM (Indexed Sequential Access Method) indexes maintain static structure, meaning after initial setup, it doesn’t adjust automatically which can cause imbalance over time. B+ Trees, on the other hand, dynamically adjust as data is inserted and deleted, maintaining balance at all times. B+ Trees are generally preferred for databases requiring frequent updates or where the data set size varies over time, as they handle insertions and deletions more efficiently without imbalance. ISAM may be preferred in systems where the data set is static and where read access far exceeds write access .

A tree index, like a B+ Tree, is efficient for range queries due to its ordered nature but tends to be slower for exact match queries compared to hash indexes. Hash indexes, using mechanisms like Linear Hashing, allow fast exact match queries because they offer a constant average search time, typically involving fewer disk I/Os due to direct entry location without needing to traverse tree levels. When databases handle frequent exact match lookups versus range queries, a hash index will significantly improve performance .

Analyzing data distribution informs which columns are most selective and can, therefore, significantly benefit from indexing. For example, queries searching for specific departments by location and budget require indexes on those columns if values are not uniformly distributed, such as location being much less frequent or budget having a large range. Such analysis ensures that high-cardinality columns are indexed, leading to more efficient query plans where fewer rows are scanned, thus speeding up retrieval times significantly .

The three main alternatives for sorting information in a data entry of an index are sorted files, heap files with an unclustered tree index on the search key, and heap files with an unclustered hash index. In a clustered index, the data entries are stored in the order of the index key, making it suitable for range queries. In contrast, an unclustered index maintains a separate structure from data file, so data entries are stored in different orders than index keys. Sorted files are naturally clustered by the sorting key, making them efficient for range queries but costly for insertions and deletions. Whether an index is clustered or unclustered depends on how data entries are arranged in relation to the data file structure .

Inserting entries into a B+ tree in sorted order leads to frequent node splits since each new entry is placed into an already full leaf node. This often results in under-utilized trees with many half-empty nodes. For example, if a B+ tree has nodes that can each hold four entries and entries 'A' to 'G' are inserted in sorted order, every fifth entry requires a split. This continuous splitting results in a tree with many nodes having only two entries, defying the purpose of packing nodes as densely as possible for performance .

Bulk-loading a B+ tree is preferable because it allows the structure to be built in a single operation optimized for space and search efficiency, minimizing node splits or merges that occur during individual insertions. When data is already sorted, bulk-loading can create a balanced B+ tree with high storage utilization and reduced I/O operations compared to record-by-record insertion, which can result in a non-optimized tree where less data fits per node, increasing search and storage costs .

The worst-case cost for an equality search in a Linear Hashing index where each page holds 10 records with 80% average storage utilization is determined by how overflow pages are managed. If overflow buckets need to be checked, the search could involve accessing multiple pages, upping the disk I/O. This scenario occurs when a bucket has overflowed and all its overflow pages need to be examined to ensure the queried record isn't amongst them. Therefore, worst-case occurs when buckets have an optimal split maintained, minimizing overflow chain length, but still requiring multiple page accesses .

Extendible hashing uses a directory of buckets, where each bucket can hold multiple entries. The principal idea is to use a directory of pointers to buckets to handle dynamic partitioning of data entries. The global depth indicates the number of bits used to index into the directory, while the local depth indicates bits used within the bucket. This scheme allows for dynamic growth without needing to reorganize the entire data structure, as only specific buckets that overflow are split, preserving efficiency in insertions and searching .

When dealing with variable-length records, a directory of pages is often more efficient to manage space allocation because it can better adapt to changing record sizes without the need to physically rearrange records within each page. The directory structure keeps track of which pages have available space for new or expanding entries, optimizing both space utilization and the time required to locate records. In contrast, list-based organizations tend to become inefficient as they struggle with fragmentation and space reclamation .

You might also like