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.