• MYSQL8.0降序索引


    官方文档地址:https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html
    https://dev.mysql.com/blog-archive/mysql-8-0-labs-descending-indexes-in-mysql/

    首先我们先看一下5.7版本和8.0以上版本之间建立索引的区别

    • 5.7版本只支持升序索引
    • 5.7版本不能支持降序索引的主要限制是优化器必须使用文件排序来实现混合顺序
    • 8.0+ 版本增加了降序索引
      进行对比
    • 这个是5.7版本的降序索引创建,可以看出是不生效的
    mysql 5.7> CREATE TABLE t1 (a INT, b INT, INDEX a_desc_b_asc (a DESC, b ASC));
    Query OK, 0 rows affected (0.47 sec)
    
    mysql 5.7> SHOW CREATE TABLE t1\G
    *************************** 1. row ***************************
           Table: t1
    Create Table: CREATE TABLE `t1` (
      `a` int(11) DEFAULT NULL,
      `b` int(11) DEFAULT NULL,
      KEY `a_desc_b_asc` (`a`,`b`) <-- Order is not preserved
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1
    1 row in set (0.00 sec)
    
    • 这个是8.0以后版本增加降序索引的信息
    mysql 8.0> CREATE TABLE t1 (a INT, b INT, INDEX a_desc_b_asc (a DESC, b ASC));
    Query OK, 0 rows affected (0.47 sec)
    
    mysql 8.0> show create table t1;
    +-------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Table | Create Table |
    +-------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
    | t1 | CREATE TABLE `t1` (
    `a` int(11) DEFAULT NULL,
    `b` int(11) DEFAULT NULL,
    KEY `a_desc_b_asc` (`a` DESC,`b`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
    +-------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
    1 row in set (0.00 sec)
    

    降序索引的限制

    • 1.只能用于innodb存储引擎
      • 如果索引包含降序索引键列或主键包含降序索引列,则二级索引不支持更改缓冲。
      • InnoDBSQL 解析器不使用降序索引 。
    • 2.可用升序索引的所有数据类型都支持降序索引
    • 3.降序键部分的索引不用于 MIN()/MAX() 全部数据的聚合操作
  • 相关阅读:
    behavior planning——15.cost function design weightTweaking
    behavior planning——14.implement a cost function in C++
    behavior planning——13. implement a cost function in C++
    behavior planning——12.example cost funtion -lane change penalty
    发布全局项目
    http
    网址大全
    JSON.parse()和JSON.stringify()
    Ajax+Node分页
    H5移动端的注意细节
  • 原文地址:https://www.cnblogs.com/perferect/p/16022283.html
Copyright © 2020-2023  润新知