Home > Database > Mysql Tutorial > body text

MySQL源码:Range访问方式相关的数据结构--续

WBOY
Release: 2016-06-07 16:34:56
Original
1609 people have browsed it

前文着重介绍了MySQL的WHERE条件如何针对 单个 索引构造对应的SEL_ARG结构,本文是一个补充,将简单介绍多个索引对应的SEL_TREE结构。 对于一个完整的WHERE条件,MySQL会遍历所有可以使用的索引,逐一构造其对应的SEL_ARG结构,所有的SEL_ARG结构以指针数组

前文着重介绍了MySQL的WHERE条件如何针对单个索引构造对应的SEL_ARG结构,本文是一个补充,将简单介绍多个索引对应的SEL_TREE结构。

对于一个完整的WHERE条件,MySQL会遍历所有可以使用的索引,逐一构造其对应的SEL_ARG结构,所有的SEL_ARG结构以指针数组的形式存放在SEL_TREE->keys中。如果对应索引无法构造SEL_ARG,那么对应的指针为空。

class SEL_TREE :public Sql_alloc
{
...
  SEL_ARG *keys[MAX_KEY];
...
};
Copy after login

gdb打印对应的结构:

(gdb) p $1
$2 = (SEL_TREE *) 0x7f59c4038348
(gdb) p *$1
$3 = {
...
  keys = {0x0, 0x7f59c4038598, 0x0 },
...
}
Copy after login

SEL_TREE是一个数组,但如果像他的名字,他如果真是一棵树的话,那么将是如下结构:

                                          [ key1 part1 ]        [ key1 part2 ]            [ key1 part3 ]
            -\ /-                                        $                            $
              -                         / SEL_ARG(-∞, 1) $ ===>  SEL_ARG  [5,5] ===>  $ SEL_ARG [10,10]
              |......                   |        |^      $                            $        |^
              |                         |    next||      $                            $    next||
        ......|                         |        ||prev  $                            $        ||prev
    0x0       |              /--------->|        ||      $                            $        v
      \       |              |          |        ||      $                            $ SEL_ARG [12,12]
       \------|              |          |        ||      $                            $
        [key4]|              |          |        v|      $                            $
              |              |          | SEL_ARG [2, 2] $=== next_key_part =====|    $
              |      [link of SEL_ARG]  |        |^      $                       |    $
              |         /               |    next||      $                       |    $
              |--------/                |        ||prev  $                       |===>$ SEL_ARG[11,11]
              | [key3]                  |        v|      $                       |    $         |^
              |                         \ SEL_ARG [3, 3] $=== next_key_part =====|    $     next||
              |                                          $                            $         ||prev
              |                                          $                            $         v|
              |                                                                      SEL_ARG[14,14]
  [SEL_ARG]   |     *************************
      \       |     * structure of SEL_TREE *
       \------|     *************************
        [key2]|
              |
              |                           [ key1 part1 ]
              |                         / SEL_ARG (-∞,2]  $            SEL_ARG [3,5)
              |                         |        |^       $                /\ Black
              |                         |    next||       $               /  \
              |      [link of SEL_ARG]  |        ||prev   $              /    \
              |         /     |         |        v|       $ SEL_ARG (-∞,2]   SEL_ARG (10,∞)
              |--------/      |         | SEL_ARG [3,5)   $         Red           Red
              | [key1]        |-------->|        |^       $
              |                         |    next||       $
              |                         |        ||prev   $
          SEL_TREE                      |        v|       $
                                        \ SEL_ARG (10,∞)  $
                                                          $
Copy after login

(大图)

That's all. 本文较为简单。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!