原文:
Database indexes are data structures that improve query performance at the cost of additional storage and slower writes. A B-tree index maintains sorted data, enabling logarithmic-time lookups instead of full table scans. Without an index, a query must examine every row — an O(n) operation. With an appropriate index, the same query becomes O(log n). However, over-indexing is counterproductive because each insert and update must also modify the indexes. The key is creating indexes on columns frequently used in WHERE clauses and JOIN conditions.
翻译:
数据库索引是提高查询性能的数据结构,代价是额外存储和更慢的写入。B树索引维护排序数据,实现对数时间查找,而不是全表扫描。没有索引时,查询必须检查每一行——这是O(n)操作。有了适当的索引,同样的查询变为O(log n)。然而,过度索引会产生反效果,因为每次插入和更新也必须修改索引。关键是在WHERE子句和JOIN条件中频繁使用的列上创建索引。
词汇注释:
