Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

sql - Why do we use dense indexes for unique columns?

I'm reading about Oracle database indexes, and there is some point that I couldn't get it on my head, why do we need dense indexes especially in case of dense indexes for unique columns ? the fact that having an entry on dense indexes for each entry on our database table, makes the I/O cost the same for searching over the index table or over the database table, which on my point of view doesn't optimize the performance of our DBMS, I'm sure that I'm missing a point on how dense indexes work, but I've really searched over the Oracle doc without finding an appropriate response to my question.
Ok I get the point, of using a dense index in case of non unique key, but my real question is how would using it for a unique key gain performance ? what is the difference between accessing entries on dense indexes and accessing database entries in case of unique key dense indexes as they have both the same number of entries ?

EDIT :

In a dense index, a record is created for every search key valued in the database. This helps you to search faster but needs more space to store index records. In this Indexing, method records contain search key value and points to the real record on the disk. enter image description here

Dense indexes definition

question from:https://stackoverflow.com/questions/65641955/why-do-we-use-dense-indexes-for-unique-columns

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

the fact that having an entry on dense indexes for each entry on our database table, makes the I/O cost the same for searching over the index table or over the database table,

Because indexes that I'm familiar with are all "dense indexes", I'll use "index" to mean that and "sparse index" for other varieties.

This is simply misguided.

The purpose of an index is to significantly reduce I/O costs of reading tables. An index conceptually does so by storing an ordered list of the keys. The index structure can then be quickly traversed to find a particular value or in many cases a range of values.

Conceptually you can think of an index as an ordered list of the keys and binary search. However, the actual implementation could be quite different. The most common use balanced trees. More esoteric types use hash codes. And then some types are specific to particular data types, such as GIS indexes and full text indexes.

A very important part of an index is that it can locate the specific rows with a particular value. A second important part is that SQL tables represent unordered multisets (multisets are just sets that allow duplicate values).

If you put these together, you will realize that a sparse index really doesn't make sense, because there is no way to find values that are not in the index.

What this is probably referring to are clustered indexes on a table. A clustered index is a particular type of index where the underlying data is actually sorted by the index key (only one clustered index per table). As a space optimization on clustered indexes, sparse storage makes some sense. Scanning the records on a single page is often comparable in cost to descending a few levels of index depth.

I also want to point out that "sparse" has a more common usage in database-talk -- and that would be sparse data. Column-oriented databases are optimized for -- among other things -- columns that often have NULL values. However, I don't think this use of "sparse index" is related to sparse data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...