是什么算法在数据库中查询搜索?数据库中、算法

2023-09-11 04:33:35 作者:赤岸 -

美好的一天每个人,我目前正在做的搜索算法优化研究。

Good day everyone, I'm currently doing research on search algorithm optimization.

截至目前,我正在研究的数据库。

As of now, I'm researching on the Database.

在数据库瓦特/ SQL的支持。

In a database w/ SQL Support.

我可以编写查询特定表。

I can write the query for a specific table.

从表1 选择号码其中Name =测试; 选择*从表1其中Name =测试;

1搜索从表1的数量从​​那里名称是Test,并且2检索所有的列名测试。

1 searches the number from Table1 from where the Name is Test and 2 searches all the column for name Test.

我理解函数的概念,但是我想学习什么是搜索的方法?

I understand the concept of the function however what I'm interested in learning what is the approach of the search?

难道只是简单的线性搜索,其中从第一个索引,直到第n个指标会抢,只要条件为真,因此具有O(n)的速度还是有独特的算法来加快其进程?

Is it just plain linear search where from the first index until the nth index it will grab so long as the condition is true thus having O(n) speed or does it have a unique algorithm that speeds its process?

感谢您事先=)

推荐答案

如果没有索引,那么是的,线性搜索。

If there's no indexes, then yes, a linear search is performed.

但是,数据库通常使用 B +树指数。这些是专门调整(高乙树支化因子),以在磁盘硬件,这里最显著耗时的因素是查找操作执行以及特殊的数据结构格式(磁头必须移动到该文件的一个差异部分)。

But, databases typically use a B Tree index when you specify a column(s) as a key. These are special data structure formats that are specifically tuned(high B Tree branching factors) to perform well on magnetic disk hardware, where the most significant time consuming factor is the seek operation(the magnetic head has to move to a diff part of the file).

您可以把指数作为值的列的排序/结构的副本。它可以很快确定是否被搜索的值是在索引中。如果它发现它,那么它也将找到一个指针指回相应的行的主数据文件中的正确的位置(因此它可以去读取行中的其它列)。有时,一个多列索引包含所有查询所请求的数据,然后将它并不需要跳过返回主文件时,它可以只读它找到了什么,然后它的完成。

You can think of the index as a sorted/structured copy of the values in a column. It can be determined quickly if the value being searched for is in the index. If it finds it, then it will also find a pointer that points back to the correct location of the corresponding row in the main data file(so it can go and read the other columns in the row). Sometimes a multi-column index contains all the data requested by the query, and then it doesn't need to skip back to the main file, it can just read what it found and then its done.

还有其他类型的索引,但我认为你的想法 - 重复数据,并安排它的方式,是快速搜索

There's other types of indexes, but I think you get the idea - duplicate data and arrange it in a way that's fast to search.

在一个大的数据库,索引使差等待一秒钟的时间之间,VS可能天为一个复杂的查询完成

On a large database, indexes make the difference between waiting a fraction of a second, vs possibly days for a complex query to complete.

btw-乙树的不是一个简单易懂的数据结构,并且在遍历算法也复杂。此外,遍历是比大多数$ C $的偶数丑陋c您会发现,因为在数据库中,他们都在不断加载/从磁盘卸载数据的块,并将其在存储器管理,而这显著uglifies的code 。但是,如果你熟悉二叉搜索树的,那么我想你理解这个概念不够好。

btw- B tree's aren't a simple and easy to understand data structure, and the traversal algorithm is also complex. In addition, the traversal is even uglier than most of the code you will find, because in a database they are constantly loading/unloading chunks of data from disk and managing it in memory, and this significantly uglifies the code. But, if you're familiar with binary search trees, then I think you understand the concept well enough.

 
精彩推荐
图片推荐