Oracle 反向主键

Oracle Reverse Primary Keys

我正在尝试在我的主键列上创建一个带有反向索引的 table。

创建了table,我插入了很多数据,生成了一个有序列的键值。

根据我对反向键的理解,关于它如何获取 nextval 并反转它,然后插入...我期待在我的 select 语句中看到反转的键值。

如果 nextval 是 112,当我从 table select 我期待看到 211。但我仍然看到 112。

是否仍在执行反向键索引,而 Oracle 只是以非反向格式显示?

还是真的出了什么问题?

我用于索引的SQL是

CREATE UNIQUE INDEX "<schema>"."<index_name>" ON "<schema>"."<table_name>" ("SYS_I") REVERSE;

反向键索引不会更改键值。
只有它存储在磁盘上的物理表示发生了变化。
来自 the documentation

Reverse Key Indexes

A reverse key index is a type of B-tree index that physically reverses the bytes of each index key while keeping the column order. For example, if the index key is 20, and if the two bytes stored for this key in hexadecimal are C1,15 in a standard B-tree index, then a reverse key index stores the bytes as 15,C1.

Reversing the key solves the problem of contention for leaf blocks in the right side of a B-tree index. This problem can be especially acute in an Oracle Real Application Clusters (Oracle RAC) database in which multiple instances repeatedly modify the same block. For example, in an orders table the primary keys for orders are sequential. One instance in the cluster adds order 20, while another adds 21, with each instance writing its key to the same leaf block on the right-hand side of the index.

In a reverse key index, the reversal of the byte order distributes inserts across all leaf keys in the index. For example, keys such as 20 and 21 that would have been adjacent in a standard key index are now stored far apart in separate blocks. Thus, I/O for insertions of sequential keys is more evenly distributed.

Because the data in the index is not sorted by column key when it is stored, the reverse key arrangement eliminates the ability to run an index range scanning query in some cases. For example, if a user issues a query for order IDs greater than 20, then the database cannot start with the block containing this ID and proceed horizontally through the leaf blocks.