Warm tip: This article is reproduced from serverfault.com, please click

Can we access a record in SQL table using primary key in O(1) time?

发布于 2020-11-28 12:35:00

I want to know that while finding a record using the primary key does RDBMS takes O(1) time or not?

Questioner
Dishant Vashistha
Viewed
0
Gordon Linoff 2020-11-28 20:37:28

No. In all databases that I know of, the primary key index is a B-tree index. Finding a particular element in such an index is an O(log n) operation, not O(1).

Note that for the sizes of databases, O(log n) is pretty close to O(1). After all, the log of one billion is only about 30 (base 2).