Fatskills
Practice. Master. Repeat.
Study Guide: Comp. Sci and Programming Basics: Databases Indexes and Performance
Source: https://www.fatskills.com/bsc-cs/chapter/databases-indexes-and-performance

Comp. Sci and Programming Basics: Databases Indexes and Performance

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~6 min read

Concept Summary

  • An index is a data structure that improves the speed of data retrieval by allowing direct access to specific data elements.
  • Indexes are commonly used in databases and file systems to optimize query performance.
  • Indexes can be created on one or more columns of a table, depending on the query patterns and data distribution.
  • Indexes can be categorized into different types, such as B-tree, hash, and full-text indexes.
  • Properly designed indexes can significantly improve the performance of database queries, but poorly designed indexes can lead to performance degradation.

Questions


WHAT (definitional)

  • What is an index in the context of databases?
  • Answer: An index is a data structure that improves the speed of data retrieval by allowing direct access to specific data elements.
  • Real-world example: A phonebook is an example of an index, where names are listed alphabetically to facilitate quick lookup.
  • Misconception cleared: An index is not a physical copy of the data, but rather a separate data structure that points to the location of the data.
  • What is the purpose of creating an index on a table?
  • Answer: The purpose of creating an index on a table is to improve the speed of data retrieval by allowing direct access to specific data elements.
  • Real-world example: Creating an index on a table of customer names can speed up queries that filter by name.
  • Misconception cleared: Indexes are not created solely for data insertion or deletion, but rather for query performance.
  • What types of indexes are commonly used in databases?
  • Answer: B-tree, hash, and full-text indexes are commonly used in databases.
  • Real-world example: B-tree indexes are often used for queries that filter by a range of values, such as a date range.
  • Misconception cleared: Indexes are not limited to a single type, but rather can be chosen based on the specific query patterns and data distribution.

WHY (causal reasoning)

  • Why is it necessary to create indexes on a table?
  • Answer: It is necessary to create indexes on a table to improve the speed of data retrieval and reduce the time it takes to execute queries.
  • Real-world example: A query that filters by a column with no index may take several seconds to execute, while the same query with an index may take only milliseconds.
  • Misconception cleared: Indexes do not slow down data insertion or deletion, but rather improve query performance.
  • Why do poorly designed indexes lead to performance degradation?
  • Answer: Poorly designed indexes lead to performance degradation because they can cause unnecessary disk I/O, slow down query execution, and even lead to deadlocks.
  • Real-world example: A poorly designed index on a table with a high volume of inserts and deletes can cause the index to become fragmented, leading to performance degradation.
  • Misconception cleared: Indexes are not a one-time solution, but rather require ongoing maintenance and optimization to ensure optimal performance.
  • Why are indexes particularly important in large databases?
  • Answer: Indexes are particularly important in large databases because they can significantly improve query performance and reduce the time it takes to execute complex queries.
  • Real-world example: A large e-commerce database may use indexes to speed up queries that filter by product category, price range, and other attributes.
  • Misconception cleared: Indexes are not limited to large databases, but rather can be beneficial in any database that experiences high query volumes.

HOW (process/application)

  • How do you create an index on a table?
  • Answer: You can create an index on a table using a SQL statement, such as CREATE INDEX, and specifying the column(s) to be indexed.
  • Real-world example: Creating an index on a table of customer names can be done using the following SQL statement: CREATE INDEX idx_customer_name ON customers (name).
  • Misconception cleared: Indexes can be created on multiple columns, not just a single column.
  • How do you maintain and optimize indexes?
  • Answer: You can maintain and optimize indexes by rebuilding or reorganizing them periodically, and monitoring their performance to identify areas for improvement.
  • Real-world example: Rebuilding an index on a table with a high volume of inserts and deletes can help to prevent fragmentation and improve query performance.
  • Misconception cleared: Indexes do not require manual maintenance, but rather can be automated using database tools and scripts.
  • How do you choose the right index type for a query?
  • Answer: You can choose the right index type for a query by considering the query patterns, data distribution, and performance requirements.
  • Real-world example: Choosing a B-tree index for a query that filters by a range of values can improve performance, while choosing a full-text index for a query that searches for a specific keyword can improve relevance.
  • Misconception cleared: Indexes are not a one-size-fits-all solution, but rather require careful consideration of the specific query and data characteristics.

CAN (possibility/conditions)

  • Can indexes be created on multiple columns?
  • Answer: Yes, indexes can be created on multiple columns.
  • Real-world example: Creating an index on multiple columns, such as name and address, can speed up queries that filter by both attributes.
  • Misconception cleared: Indexes can be created on multiple columns, not just a single column.
  • Can indexes be used to improve query performance?
  • Answer: Yes, indexes can be used to improve query performance by allowing direct access to specific data elements.
  • Real-world example: Creating an index on a table of customer names can speed up queries that filter by name.
  • Misconception cleared: Indexes are not limited to query performance, but rather can also improve data insertion and deletion performance.
  • Can indexes be used to improve data insertion and deletion performance?
  • Answer: Yes, indexes can be used to improve data insertion and deletion performance by reducing the time it takes to update the index.
  • Real-world example: Creating an index on a table with a high volume of inserts and deletes can help to prevent fragmentation and improve query performance.
  • Misconception cleared: Indexes are not limited to query performance, but rather can also improve data insertion and deletion performance.

TRUE/FALSE (misconception testing)

  • Statement: Indexes slow down data insertion and deletion.
  • Answer: FALSE
  • Real-world example: Indexes can actually improve data insertion and deletion performance by reducing the time it takes to update the index.
  • Misconception cleared: Indexes do not slow down data insertion and deletion, but rather improve query performance.
  • Statement: Indexes can only be created on a single column.
  • Answer: FALSE
  • Real-world example: Indexes can be created on multiple columns, such as name and address.
  • Misconception cleared: Indexes can be created on multiple columns, not just a single column.
  • Statement: Indexes are not necessary for small databases.
  • Answer: FALSE
  • Real-world example: Indexes can be beneficial even in small databases, especially if they experience high query volumes.
  • Misconception cleared: Indexes are not limited to large databases, but rather can be beneficial in any database that experiences high query volumes.


ADVERTISEMENT