NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle+0 views

In what cases would you use a Hash index or a B-tree?

Practice

AI answer

A hash index is suitable for exact equality comparisons (=), if the DBMS and the specific implementation support the required use case. It generally does not help with range conditions, sorting, or prefix searches. A B-tree is a versatile choice: it supports equality and range conditions (<, BETWEEN), sorting, and often prefix searches. In practice, choose based on the query patterns and inspect the execution plan; behavior depends on the DBMS.