当前位置:网站首页>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 .
边栏推荐
- LeetCode 217. 存在重复元素
- 基于Bézier曲线的三维造型与渲染
- HCIP第十一天比较(BGP的配置、发布)
- Chat system based on webrtc and websocket
- B+树(4)联合索引 --mysql从入门到精通(十六)
- Kubelet CRI 容器运行时
- Student examination system based on C #
- The parent component accesses the methods or parameters of the child component (the child component exposes the method defineexpose)
- Kubernetes---- installing and deploying NFS servers
- panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)
猜你喜欢

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

Unicode文件解析方法及存在问题

【5GC】什么是5G切片?5G切片如何工作?

最好的工程师,就是这样被你“逼”走的!

One stroke problem (Chinese postman problem)

12 brand management of commodity system in gulimall background management

Kubernetes flannel: host-gw mode

Can I take your subdomain? Exploring Same-Site Attacks in the Modern Web

解决方案丨5G技术助力搭建智慧园区

【上位机教程】CANopen通信下一体化步进电机与台达PLC(AS228T)的应用
随机推荐
Bitwise and how to write SQL
Incorrect use of parentdatawidget when the exception was thrown, this was the stack:
Can I take your subdomain? Exploring Same-Site Attacks in the Modern Web
Does Flink CDC only support SQL client to submit SQL scripts
One stroke problem (Chinese postman problem)
HCIP第十二天笔记整理(BGP联邦、选路规则)
V00 - do whatever you want when you are old
Unicode文件解析方法及存在问题
Visual stdio(VS)中的(int argc、char** argv)命令行参数
高通再次「押宝」中科创达,挑战智能驾驶软硬件全栈方案
B+树挑选索引(1)---mysql从入门到精通(二十二)
AI-理论-知识图谱1-基础
key&key_len&ref&filtered(4)—mysql执行计划(五十)
学习pinia 介绍-State-Getters-Actions-Plugins
How to remove underline and color when there is focus in the shutter textfield
JSON format execution plan (6) - MySQL execution plan (52)
[typescript] typescript common types (Part 2)
The parent component accesses the methods or parameters of the child component (the child component exposes the method defineexpose)
Can MySQL customize variable parameter storage functions?
The best engineer was "forced" away by you like this!