数据库查询时间复杂 [英] Database query time complexity

查看:211
本文介绍了数据库查询时间复杂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在现代数据库中,如果我使用索引来访问一行,我相信这将是O(1)的复杂性。但是如果我做一个查询来选择另一列,它会是O(1)还是O(n)?数据库是否必须遍历所有行,或者是否为每个列建立一个排序列表?

解决方案

认为基于索引的访问将是O(log(n)),因为您仍然会通过B-Tree-esque组织搜索到您的记录。


I'm pretty new to databases, so forgive me if this is a silly question.

In modern databases, if I use an index to access a row, I believe this will be O(1) complexity. But if I do a query to select another column, will it be O(1) or O(n)? Does the database have to iterate through all the rows, or does it build a sorted list for each column?

解决方案

Actually, I think access based on an index will be O(log(n)), because you'll still be searching down through a B-Tree-esque organization to get to your record.

这篇关于数据库查询时间复杂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆