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

What is Selectivity of...

Câu trả lời

Selectivity in MongoDB refers to the ability of a query to narrow down the results using an index. It is a measure of how well a query predicate can exclude or filter out documents in a collection. More selective queries match a smaller percentage of documents, which allows MongoDB to use indexes more effectively, resulting in faster query execution.

Key Points about Selectivity:

  1. Definition:

    • Selectivity is the proportion of documents in a collection that match a query. High selectivity means fewer documents match the query, making the index more efficient[2][3][4][5][7].
  2. Impact on Performance:

    • Highly selective queries can significantly improve performance because they reduce the number of documents that need to be scanned. This minimizes the amount of data processed and speeds up query execution[1][2][3][4][5][7].
  3. Index Design:

    • Effective indexes are designed to be selective. For example, a compound index that includes both a low-selectivity field and a high-selectivity field can improve performance by narrowing down the results more efficiently[2][3][4][5][7].
    • The order of fields in a compound index can also affect selectivity. Generally, placing the more selective field first in the index can enhance performance[6].
  4. Examples:

    • An index on a unique field like _id is highly selective because it can match at most one document.
    • An index on a field with few distinct values (e.g., a status field with values "new" and "processed") is less selective and may not be as effective[2][3][4][5][7].
  5. Query Optimization:

    • MongoDB's query optimizer uses selectivity to determine the most efficient index to use for a query. It periodic...
senior

senior

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

junior

Explain difference between scaling horizontally and vertically for databases

senior

Explain use of transactions in NoSQL

senior

Explain BASE terminology in a context of NoSQL

Bình luận

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

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