0
0
DBMS Theoryknowledge~10 mins

Index selection guidelines in DBMS Theory - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Index selection guidelines
Identify Query Patterns
Check Column Usage in WHERE/JOIN
Evaluate Column Selectivity
Decide Index Type (Single/Multi-column)
Create Index
Monitor Query Performance
Adjust or Drop Index if Needed
This flow shows how to choose columns for indexing by analyzing queries, checking column usage, evaluating selectivity, creating indexes, and monitoring performance.
Execution Sample
DBMS Theory
SELECT * FROM employees WHERE department_id = 5;
-- Index on department_id helps

SELECT * FROM employees WHERE last_name = 'Smith';
-- Index on last_name helps

SELECT * FROM employees WHERE salary > 50000;
-- Index may help if selective
These queries show how indexes on columns used in WHERE clauses can speed up data retrieval.
Analysis Table
StepActionColumn EvaluatedSelectivityIndex DecisionReason
1Analyze querydepartment_idHigh (few departments)Create indexUsed in WHERE, high selectivity
2Analyze querylast_nameMedium (many unique names)Create indexUsed in WHERE, moderate selectivity
3Analyze querysalaryLow (many salaries > 50000)Consider indexRange query, less selective
4Create indexdepartment_idN/AIndex createdImproves equality search
5Create indexlast_nameN/AIndex createdImproves equality search
6Monitor queriesAllN/AAdjust if neededCheck if indexes help performance
7Drop indexsalaryN/AIndex not createdLow benefit, maintenance cost high
💡 Index decisions made based on column usage and selectivity; low benefit indexes removed
State Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
department_id indexNoneConsideredConsideredConsideredCreatedExists
last_name indexNoneNoneConsideredConsideredCreatedExists
salary indexNoneNoneNoneConsideredConsideredNot created
Key Insights - 3 Insights
Why do we create an index on department_id but not on salary?
Because department_id has high selectivity (few departments), making the index efficient (see execution_table rows 1 and 3). Salary has low selectivity for the query, so the index is less useful and later dropped (rows 3 and 7).
What does 'selectivity' mean in index selection?
Selectivity means how many unique values a column has. High selectivity means many unique values, which makes indexes more effective (refer to execution_table column 'Selectivity').
Why monitor query performance after creating indexes?
Because indexes can improve or sometimes slow down queries. Monitoring helps decide if an index should be kept or dropped (see execution_table rows 6 and 7).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the index on last_name created?
AStep 5
BStep 2
CStep 4
DStep 7
💡 Hint
Check the 'Index Decision' column for last_name in execution_table rows
According to variable_tracker, what happens to the salary index after step 4?
AIt is created then dropped
BIt is created and remains
CIt is never created
DIt is created and monitored
💡 Hint
Look at the 'salary index' row in variable_tracker after step 4 and final
If department_id had low selectivity, what would likely change in the execution_table?
AIndex would still be created
BIndex decision would be to consider or drop
CNo change in index decision
DIndex would be created on salary instead
💡 Hint
Refer to how selectivity affects index decision in execution_table rows 1 and 3
Concept Snapshot
Index Selection Guidelines:
- Analyze queries to find columns used in WHERE/JOIN
- Evaluate column selectivity (unique values ratio)
- Create indexes on high-selectivity columns
- Use single or multi-column indexes as needed
- Monitor performance and adjust indexes
- Drop indexes with low benefit to save resources
Full Transcript
Index selection guidelines help decide which columns to index for faster queries. First, look at query patterns and find columns used in WHERE or JOIN clauses. Then check how selective these columns are—columns with many unique values are better for indexing. Create indexes on these columns to speed up searches. After creating indexes, watch query performance to see if they help. If an index does not improve performance or is costly to maintain, consider dropping it. This process ensures indexes improve database speed without wasting resources.