English 中文(简体)
B-Tree/B+Tree内部的数据
原标题:How Database stores data internally in B-Tree/B+Tree

我的问题是,数据库如何储存数据以及如何在内部进行查询。

支持在我们的桌子里以下领域:

  1. ID
  2. Name
  3. Age
  4. Weight
  5. Manager

和我们问询:slect* from Table1 where age>50 and grand<100

我很奇怪的是,它如何在内部进行询问。

The Node of B-Tre/B+Tree includes in this example?

问题回答

你们选择的例子就是少数几例,一只树木可以做这项工作(两个独立范围)。

然而,我在工作-进步电子-Book的第一章解释了B-Tree指数的内部工作:http://use-the-index-luke.com/anatomy/

EDIT for more details why two indexes might be useful for the above example.

以上问题可由三个可能的指数组合予以支持:

  1. concatenated index on AGE and then WEIGHT (in this order).
    In case, the query would read all records WHERE AGE > 50 and then filter by WEIGHT.

  2. concatenated index on WEIGHT and then AGE (the other order).
    That goes the different way: read all records WHERE WEIGHT < 100 and then filter by AGE.

无论哪一种效率更高,都取决于你掌握的数据。 如果记录低于<代码>AGE > 50> 低于WEOW <100<>/code>,则第一个记录将更为有效,否则第二个记录将更有效。 然而,如果你问到不同的价值观,情况可能会改变。

压缩指数不能支持询问,其原因是,每个指数单上只一个轴。 每一指数条目在另一条目之前或之后,但从来都不在后面。 所有指数条目都有一链条。

有两个独立的范围问题需要两个轴心,而不是像一个链条,而是像一个焦炭板。 <代码>AGE的轴心,另一轴为WEless。 如果可能的话,您的询问只需要扫描一角的ches。

然而,树只有一个轴,因此,你必须选择哪些标准首先使用。 如果你选择<代码>AGE,这意味着从AGE 50开始,整个链条将作扫描直至尾为止。 只有在链条一侧储存的一些记录也符合以下条件:<条码>。

So, a long story to explain why one tree can not support a query with two independent range clauses. On the other hand, one concatenated index can do the following quite well:

WHERE age = 50 AND weight < 100
WHERE weight = 100 AND age > 50
WHERE age > 50 AND age < 70;

然而,如果在两个不同的栏目上使用两个不平等的操作者,就会产生问题。

因此,需要做些什么?

The third possible approach is to have two independent indexes on the two columns. That allows to have as many axes as you like (just create more indexes). However, there are a few huge problems with that. First of all, not all DB products support that. Whenever it is supported, it is a rather expansive operation. It works typically that way that each index is scanned, a bitmap index is built for each result. Those bitmap indexes are then joined to apply the AND operator. That s a lot of data munging--it is only worth the effort if each condition is not very selective for it s own, but both together are very selective.

我的建议吗?

If your query runs in an OLTP environment: use one concatenated index. Two independent indexes are an option of last resort only. However, if you are working in an OLAP environment, you might anyways need bitmap indexes.

ps.: Indexing AGE was an exercise in my book (with solution)--especially because storing AGE is a bad practice, you should store the date of birth instead.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签