首页 > 数据库 >【MySQL 8.0】新特性:函数索引

【MySQL 8.0】新特性:函数索引

时间:2023-08-27 11:04:36浏览次数:43  
标签:customer 8.0 since count 索引 +----------+ MySQL NULL select

(root@node01) > select count(*) from customer where year(c_since)=2020;
+----------+
| count(*) |
+----------+
|      702 |
+----------+
1 row in set (0.46 sec)

(root@node01) > explain select count(*) from customer where year(c_since)=2020;
+----+-------------+----------+------------+------+---------------+------+---------+------+--------+----------+-------------+
| id | select_type | table    | partitions | type | possible_keys | key  | key_len | ref  | rows   | filtered | Extra       |
+----+-------------+----------+------------+------+---------------+------+---------+------+--------+----------+-------------+
|  1 | SIMPLE      | customer | NULL       | ALL  | NULL          | NULL | NULL    | NULL | 287382 |   100.00 | Using where |
+----+-------------+----------+------------+------+---------------+------+---------+------+--------+----------+-------------+
1 row in set, 1 warning (0.00 sec)

(root@node01) > alter table customer add key idx_customer_since((year(c_since)));          
Query OK, 0 rows affected (6.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

(root@node01) > select count(*) from customer where year(c_since)=2020;
+----------+
| count(*) |
+----------+
|      702 |
+----------+
1 row in set (0.01 sec)

(root@node01) > explain select count(*) from customer where year(c_since)=2020;
+----+-------------+----------+------------+------+--------------------+--------------------+---------+-------+------+----------+-------+
| id | select_type | table    | partitions | type | possible_keys      | key                | key_len | ref   | rows | filtered | Extra |
+----+-------------+----------+------------+------+--------------------+--------------------+---------+-------+------+----------+-------+
|  1 | SIMPLE      | customer | NULL       | ref  | idx_customer_since | idx_customer_since | 5       | const |  702 |   100.00 | NULL  |
+----+-------------+----------+------------+------+--------------------+--------------------+---------+-------+------+----------+-------+
1 row in set, 1 warning (0.00 sec)

标签:customer,8.0,since,count,索引,+----------+,MySQL,NULL,select
From: https://blog.51cto.com/dbprofessional/7251435

相关文章

  • MySQL事务
    2023.8.261.事务的四大特性A原子性C一致性I隔离性D持久性2.会出现的问题脏读:读到了另一个事物中未提交的修改不可重复读:一个事务前后两次因为另一个事务做了修改或导致读到的数据不同幻读:一个事务前后两次因为另一个事务做了新增而读取到了......
  • MySQL.js用法
    mysql.js是一个用于连接MySQL数据库的JavaScript库。以下是一些常用的方法及其详细参数说明: 1.创建连接对象: ```javascriptconstmysql=require('mysql');constconnection=mysql.createConnection({ host:'localhost',//数据库地址 user:'root',//数据......
  • MySQL 8与复制可观察性
    许多老MySQLDBA都使用showreplicastatus中的seconds_behind_source来了解(异步)复制的状态和正确执行情况。不过,MySQL复制已经有了很大的发展,复制团队已经努力为MySQL的所有复制方式提供了大量有用的信息。例如,增加了并行复制、组复制......所有这些信息都是老的showreplica......
  • mysql中truncate表对auto_increment的影响
    在mysql中,如果对表执行truncate操作后,会重新设置auto_increment的值,比如:root@localhost(none)>useabce;Databasechangedroot@localhostabce>createtabletest(idintnotnullauto_incrementprimarykey,ageint);QueryOK,0rowsaffected(0.02sec)root@localho......
  • 【MySQL 8.0】新特性:ALTER TABLE … ALGORITHM=INSTANT
    MySQL8.0.29之前,在线DDL操作中即时添加列只能添加在表的最后一列MySQL8.0.29扩展了对ALTERTABLE…ALGORITHM=INSTANT的支持:用户可以在表的任何位置即时添加列、即时删除列、添加列时评估行大小限制(root@node01)>altertablecustomeraddcolumnc_commentvarcha......
  • rhel 7.3搭建MySQL 5.7.21(一主一从GTID半同步复制)
    文档课题:rhel7.3搭建MySQL5.7.21(一主一从GTID半同步复制)数据库:MySQL5.7.21系统:rhel7.3环境:角色 主机名 IP 操作系统 server_id MySQL安装包master mysql-leo-master 192.168.133.111 rhel7.3 1 Percona-Server-5.7.21-20-Linux.x86_64.ssl101.tar.gzslave mysql-leo-s......
  • mysql 深入学习三 索引优化一
    测试建表CREATETABLE`employees`(`id`int(11)NOTNULLAUTO_INCREMENT,`name`varchar(24)NOTNULLDEFAULT''COMMENT'姓名',`age`int(11)NOTNULLDEFAULT'0'COMMENT'年龄',`position`varchar(20)NOT......
  • 【MySQL 8.0】新特性:支持CHECK约束
    (root@node01)>createtablestudent(idintprimarykey,namevarchar(255),ageint,genderchar(1),scorefloat,constraintchk_agecheck(age>=18),constraintchk_scorecheck(score>=0andscore<=100));QueryOK,0rowsaffected(0.20......
  • MySQL 一行记录是怎么存储的?
    一、数据存在哪个文件可以看到,共有三个文件,这三个文件分别代表着:db.opt,用来存储当前数据库的默认字符集和字符校验规则。t_order.frm,t_order的表结构会保存在这个文件。在MySQL中建立一张表都会生成一个.frm文件,该文件是用来保存每个表的元数据信息的,主要包含表结构定义......
  • 【MySQL 8.0】通过pt-archiver实现表的历史数据归档
    (root@node02)>setgloballocal_infile=on;QueryOK,0rowsaffected(0.00sec)(root@node02)>createtablecustomer_jplikecustomer;QueryOK,0rowsaffected(0.20sec)(root@node01)>setgloballocal_infile=on;QueryOK,0rowsaffected......