当前位置:网站首页>B+ tree index use (8) sorting use and precautions (20)
B+ tree index use (8) sorting use and precautions (20)
2022-07-26 13:17:00 【User 9919783】
In the last article, we introduced matching column prefixes , Because the index sort is compared by letter , If % The index cannot be triggered before , And range matching , Range query , The leftmost column can trigger the index , When there is an exact value in front , such as name = ‘’, The second range can also trigger the index , The latter cannot trigger the index .
B+ Tree index uses (7) Match column prefix , Matching value range ( nineteen )
Sort
We use it sql Have you used it before order by. Traditional sorting does not sort in memory or disk , Sorting in memory can use some sorting algorithms , Quick sort , Merge, sort, etc , After sorting , Then return the result to the client . stay mysql in , The method of sorting in disk or memory is uniformly called file sorting ( English name :filesort). Generally, it is related to documents , It's going to be slow , Compare the speed of disk and memory , It's like a plane is better than a green train , Even the disk is slower than the green train . But if it's used order by sentence , Such as :order by name,birthday,phone; At this time, the query result is first pressed name Sort ,name If the same, press birthday Sort ,birthday identical , Then press phone Sort . because b+ Tree index sort , It is sorted according to this , So it saves the cost of sorting in memory or disk , Get data directly from the database .
Joint index sorting considerations
Order by When sorting , Followed by index fields . When sorting by joint index, you need to pay attention to :
1)、 When order by name,birthday,phone When , At this time, press name Sort , When the same , Will press birthday Sort , If it's the same, press phone.
2)、 When used order by phone,birthday,name When sorting , Index sorting will not be triggered , The principle is the same as before , Because you need to name identical , Will trigger the subsequent sorting .
Or take an exact value before where name = ‘A’ order by birthday,phone;
At this time, the subsequent sorting will also trigger the index , The reason is similar to the above , Said many times .
Several cases where index sorting cannot be used
ASC、DESC A mixture of
For the usage scenario of joint index , We require that the order be consistent , Or press ASC Sort , Or press DESC Sort ( When not writing , The default with ASC Ascending ). Let's first recall the sort structure of the index :1) According to the first name Sort .2) If it is the same, press birthday Sort .3) How to press the same phone Sort . If the sorting is consistent, how to get the value ?
order by name,birthday ASC limit 10; At this time, you only need to count from the leftmost side of the index 10 individual .
order by name,birthday DESC limt 10; Just count from the far right of the index 10 individual .
But if we press name Ascending , Press birthday Descending :
Order by name asc,birthday desc limit 10; In this case, using index lookup is very complicated ,mysql Designers feel that this is not as fast as sorting files , So the sorting must be consistent .
The rank contains non indexed columns
Order by name,country limit 10;name and country Does not belong to the union index , therefore country Definitely not sort by index .
Sorting uses complex expressions
such as order by upper(name) limit 10; Used upper Then it's not a separate column , You can't use search engines .
边栏推荐
- HCIP第十二天笔记整理(BGP联邦、选路规则)
- 同花顺开的账户安全吗?
- 同站攻击(相关域攻击)论文阅读 Can I Take Your Subdomain?Exploring Same-Site Attacks in the Modern Web
- 关于自动重复调用接口的一种实现方式-反射
- Probability theory and mathematical statistics
- Square root of leetcode 69. x
- Create EOS account action
- Qualcomm once again "bet" on Zhongke Chuangda to challenge the full stack solution of intelligent driving software and hardware
- Extra(5)—mysql执行计划(五十一)
- 【5GC】什么是5G切片?5G切片如何工作?
猜你喜欢

同站攻击(相关域攻击)论文阅读 Can I Take Your Subdomain?Exploring Same-Site Attacks in the Modern Web

PostgreSQL official website download error

Probability theory and mathematical statistics

Dimension disaster dimension disaster suspense

C#把Type当做泛型T,来作为方法的泛型进行使用

Solution 5g technology helps build smart Parks

JVM: what does the class loading subsystem do? What is it made of? What eight part essay do you need to remember?

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

基于ASP.NET的某高校学院档案管理系统

A college archives management system based on asp.net
随机推荐
Detailed explanation of redis's single login
从其他文件触发pytest.main()注意事项
Probability theory and mathematical statistics
0 basic programming resources (collect first ~ read slowly ~)
Hcip day 11 comparison (BGP configuration and release)
Flink is slow to write redis. Do you have any ideas for optimization?
File upload and download performance test based on the locust framework
jvm:类加载子系统干什么的?由什么组成?需要记住哪些八股文?
基于BERT的情感分析模型
B+树(3)聚簇索引,二级索引 --mysql从入门到精通(十五)
【上位机教程】CANopen通信下一体化步进电机与台达PLC(AS228T)的应用
Mysql数据目录(3)---表数据结构myISAM(二十六)
Some practical operations of vector
Does Flink CDC only support SQL client to submit SQL scripts
【花雕动手做】有趣好玩的音乐可视化系列小项目(13)---有机棒立柱灯
Leetcode 217. there are duplicate elements
HCIP第十二天笔记整理(BGP联邦、选路规则)
[5g] what are Cu and Du in 5g?
key&key_len&ref&filtered(4)—mysql执行计划(五十)
panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)