MySQL source code: data structure related to the Range access method-continued

Source: Internet
Author: User
The previous article focuses on how the WHERE condition of MySQL constructs the corresponding SEL_ARG structure for a single index. This article is a supplement and will briefly introduce the SEL_TREE structure corresponding to Multiple indexes. For a complete WHERE condition, MySQL traverses all available indexes and constructs the corresponding SEL_ARG structure one by one. All SEL_ARG structures are pointer arrays.

The previous article focuses on how the WHERE condition of MySQL constructs the corresponding SEL_ARG structure for a single index. This article is a supplement and will briefly introduce the SEL_TREE structure corresponding to Multiple indexes. For a complete WHERE condition, MySQL traverses all available indexes and constructs the corresponding SEL_ARG structure one by one. All SEL_ARG structures are pointer arrays.

The previous article focuses on how the WHERE condition of MySQL targetsSingleIndex construction corresponds to the SEL_ARG structure. This article is a supplement to briefly introduce the SEL_TREE structure of Multiple indexes.

For a complete WHERE condition, MySQL traverses all available indexes and constructs the corresponding SEL_ARG structure one by one, all SEL_ARG structures are stored in SEL_TREE-> keys as pointer arrays. If the corresponding index cannot construct SEL_ARG, the corresponding pointer is null.

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

Gdb prints the corresponding structure:

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

SEL_TREE is an array, but if it is a tree like his name, it will be in the following structure:

                                          [ 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,∞)  $                                                          $

(Big chart)

That's all. This article is relatively simple.

Original article address: MySQL source code: data structure related to the Range access method -- continued. Thank you for sharing it with the original author.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.