Câu hỏi phỏng vấn Databases
Câu hỏi

What is Index Cardinality...

Câu trả lời

Index Cardinality and Its Importance

Index Cardinality refers to the uniqueness of values stored in a specific column within an index in a database. It is a measure of how many distinct values are present in that column. Cardinality can be categorized as either high or low:

  • High Cardinality: This means that the column contains a large number of unique values. For example, a column storing unique user IDs or email addresses would have high cardinality.
  • Low Cardinality: This means that the column contains a small number of unique values. For example, a column storing gender values (e.g., 'Male' and 'Female') would have low cardinality.

Why Index Cardinality Matters

  1. Query Performance:

    • High Cardinality: High cardinality indexes are generally more selective, meaning they can significantly narrow down the search space for a query. This improves query performance because the database engine can quickly locate the rows that match the query criteria without scanning the entire table[1][3][8].
    • Low Cardinality: Low cardinality indexes are less selective and may not provide significant performance benefits. In some cases, a full table scan might be more efficient than using an index on a low cardinality column[2][3][17].
  2. Index Selectivity:

    • Selectivity is a measure of how well an index can filter out rows. It is calculated as the ratio of the number of distinct values to the total number of rows. High selectivity (close to 1) means the index is very effective at filtering rows, while low selectivity means it is less effective[9][13][20].
  3. Storage and Maintenance:

    • High Cardinality: High cardinality indexes can consume more storage space because each unique value needs to be stored separately. However, they can reduce the number of data blocks read during query execution, which can offset the storage cost with performance gains[4][6][14].
    • Low Cardinality: Low cardinality indexes consume less storage space but may not justify the overhead of maintaining the index, especially if the index is not frequently used by queries[10][17].
  4. Impact on Write Operations:

    • Indexes need to be updated whenever data is inserted, updated, or deleted. High cardinality indexes can slow down write operations because the database needs to maintain a larger index structure. Conversely, low cardinality indexes might have a lesser impact on write performance but offer limited benefits for read operations[4][6][15].
  5. Query Optimization:

    • Database query optimizers use cardinality estimates to determine the most efficient execution p...
expert

expert

Gợi ý câu hỏi phỏng vấn

middle

What's the difference between a Primary Key and a Unique Key?

expert

Explain the differences in conceptual data design with NoSQL databases?

expert

How does database Indexing work?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào