我的问题是,数据库如何储存数据以及如何在内部进行查询。
支持在我们的桌子里以下领域:
- ID
- Name
- Age
- Weight
- Manager
和我们问询:slect* from Table1 where age>50 and grand<100
我很奇怪的是,它如何在内部进行询问。
The Node of B-Tre/B+Tree includes in this example?
我的问题是,数据库如何储存数据以及如何在内部进行查询。
支持在我们的桌子里以下领域:
和我们问询: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.
以上问题可由三个可能的指数组合予以支持:
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
.
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.
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 ...
<?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 = ...
我把我的用心从使用QQL转向MySQL。 它与凯科特合作,现在不工作,因为我已经改变,使用MySQL。 这里的错误信息是:
We have a restaurant table that has lat-long data for each row. We need to write a query that performs a search to find all restaurants within the provided radius e.g. 1 mile, 5 miles etc. We have ...
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 ...
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 ...
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 ~...
My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...