当前位置:网站首页>B+ tree index uses (7) matching column prefix, matching value range (19)
B+ tree index uses (7) matching column prefix, matching value range (19)
2022-07-26 13:17:00 【User 9919783】
The cost of indexing the last article ,b+ Trees take up a lot of space , Add, delete and correct b+ The index sorting of each node of the tree also has a great impact , It takes a long time , So there is no need to build indexes , It also introduces the leftmost principle of index and full value query .
B+ Tree index uses (6) The principle of left --mysql From entry to mastery ( eighteen )
Match column prefix
innoDB Add secondary indexes to other columns , Will sort him by column , Whether it's two-way linked list sorting between pages , Or one-way list sorting of data slot points in the page , They are all arranged by column value . such as name Column , If the name has TOM,Anny,Aone etc. ,1) First sort him alphabetically .2) The initials are A equally , Then sort him by the second letter .3) By analogy , Just sort him in the back . So when we use fuzzy query where name like ‘a%’; This percentage number can trigger index queries after it , But if where name like ‘%a’; Because the first letter cannot be found , This kind is not sorted well , As a result, you can only scan the whole disk , Discard index query .
for instance , When we have field columns url, There are data ,www.baidu.com,www.google,www.gov.com,www.wto.com.
At this time, we want to inquire com At the end of the , If you use where url like ‘%com’; Then the efficiency will be very low , Unable to trigger index query . In order to improve efficiency , Use index to query data , You can sort the data of the table in reverse , Change it to ,moc.udiab.www,moc.elgoog.www,nc.vog.www,gro.otw.www, It can be used at this time where url like ‘com%’; To trigger index queries .
Matching value range
Let's see idx_name_birthday_phone Indexes b+ Sketch Map , All records are sorted by index from small to large , For example, we use where name > ‘Anny’ and name < ‘barlow’; So this query process :1) First in b+ Tree leaf node found name Greater than Anny Secondary index records for , Read the primary key , Using cluster index to query back to the table , Get all the user record data of the cluster index and send it to the client .2) According to the record found in the previous step , Along the position of the linked list ( Two way linked list association between pages , In page data , One way linked list Association ) Find the next secondary index record , Judge whether the record <barlow, If meet , Return to client .3) repeat 2 The operation of , Until it doesn't meet .
therefore , At this time, index query will be used , But the point needs attention , Be careful , Be careful ( Say important things three times ): If you perform a range query on multiple columns , Only the leftmost column of the index will be used when querying b+ Query the index of the tree .
such as where name > ‘Anny’ and name < ‘barlow’and birthday > ‘1990-01-01’; At this time, the query process :1) Same as before , First name stay b+ The tree leaf node finds the column >Anny Primary key of , Tree back to table operation of querying clustered index with primary key , After the query , Query whether the next one meets <barlow.2) For the top name Different values , It's going on birhday Conduct birthday>’1990-01-01’ Filter .
In this way, queries are important for federated indexes , It's just name Index sorting is used in , And because biryhday The sorting condition is that name Only when the sorting is the same , Obtained at this moment name It's all different , So in birthday Index cannot be triggered during range query .
Accurate to a certain column , Range another column
When we use where name = ‘Anny’ and birthday > ‘1990-01-01’ and phone > ‘13200000000’; At this time, our query process is :1)name Definitely use b+ The secondary index of the tree first queries the column value of the leaf node plus the primary key , The clustered index back to table operation returns all the data of the clustered index leaf nodes .2) because name In the same case ,birthday Will trigger index query , First in b+ Tree leaf node found >’1990-01-01’ Column value and primary key , Query all data through the primary key back table 3) because phone The premise of using index query is birthday identical , The front one is different birthday, Indexes phone Cannot use index query .
边栏推荐
- Bitwise and how to write SQL
- Guys, how can CDC Oracle set the reading from the specified SCN number, or how to set the read-only full archive, not to read fast
- HCIP第十二天笔记整理(BGP联邦、选路规则)
- The best engineer was "forced" away by you like this!
- Shutter background graying effect, how transparency, gray mask
- 关于自动重复调用接口的一种实现方式-反射
- 终极套娃 2.0 | 云原生交付的封装
- How to face scientific and technological unemployment?
- Huawei recruited "talented teenagers" twice this year; 5.4 million twitter account information was leaked, with a selling price of $30000; Google fired engineers who believed in AI consciousness | gee
- Leetcode 217. there are duplicate elements
猜你喜欢

Kubernetes - Introduction to PV and PVC of advanced storage

PostgreSQL official website download error

Solution 5g technology helps build smart Parks

Learn about Pinia state getters actions plugins

Kubernetes ---- life cycle introduction of PV and PVC

Kubernetes flannel: host-gw mode

基于C#开放式TCP通信建立与西门子PLC的socket通信示例

从其他文件触发pytest.main()注意事项

二叉树的初阶笔记

Version of NDK matched the requested version 21.0.6113669. versions available locally: 2
随机推荐
【TypeScript】TypeScript常用类型(上篇)
Activity.onStop() 延迟10秒?精彩绝伦的排查历程
Flink is slow to write redis. Do you have any ideas for optimization?
Today in history: IBM obtained the first patent; Verizon acquires Yahoo; Amazon releases fire phone
postgresql官网下载出错
基于C#开放式TCP通信建立与西门子PLC的socket通信示例
Mysql数据目录(3)---表数据结构myISAM(二十六)
Version of NDK matched the requested version 21.0.6113669. versions available locally: 2
Can I take your subdomain? Exploring Same-Site Attacks in the Modern Web
[5g] what are Cu and Du in 5g?
LeetCode 263.丑数
基于WebRTC和WebSocket实现的聊天系统
Display inline+calc realizes left, middle and right layout, and the middle is adaptive
Create EOS account action
PostgreSQL official website download error
【花雕动手做】有趣好玩的音乐可视化系列小项目(13)---有机棒立柱灯
我们被一个 kong 的性能 bug 折腾了一个通宵
Mysql数据目录(1)---数据库结构(二十四)
解决方案丨5G技术助力搭建智慧园区
The best engineer was "forced" away by you like this!