Postgresql 中文操作指南
13.7. Locking and Indexes #
虽然 PostgreSQL 提供了对表数据的非阻塞读/写访问,但当前不会为 PostgreSQL 中实现的每个索引访问方法提供非阻塞读/写访问。各种索引类型处理方式如下:
Though PostgreSQL provides nonblocking read/write access to table data, nonblocking read/write access is not currently offered for every index access method implemented in PostgreSQL. The various index types are handled as follows:
-
B-tree, GiST and SP-GiST indexes
-
Short-term share/exclusive page-level locks are used for read/write access. Locks are released immediately after each index row is fetched or inserted. These index types provide the highest concurrency without deadlock conditions.
-
-
Hash indexes
-
Share/exclusive hash-bucket-level locks are used for read/write access. Locks are released after the whole bucket is processed. Bucket-level locks provide better concurrency than index-level ones, but deadlock is possible since the locks are held longer than one index operation.
-
-
GIN indexes
-
Short-term share/exclusive page-level locks are used for read/write access. Locks are released immediately after each index row is fetched or inserted. But note that insertion of a GIN-indexed value usually produces several index key insertions per row, so GIN might do substantial work for a single value’s insertion.
-
当前,B 树索引为并发应用程序提供最佳性能;它们还具有比哈希索引更多功能,因此它们是需要为标量数据编制索引的并发应用程序推荐的索引类型。在处理非标量数据时,B 树不起作用,而应改用 Gist、SP-Gist 或 GIN 索引。
Currently, B-tree indexes offer the best performance for concurrent applications; since they also have more features than hash indexes, they are the recommended index type for concurrent applications that need to index scalar data. When dealing with non-scalar data, B-trees are not useful, and GiST, SP-GiST or GIN indexes should be used instead.