Mysql使用In查询不走索引总结
简介Mysql使用In查询不走索引总结
            表结构
--- 用户表
CREATE TABLE `user` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `phone` char(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `address` varchar(255) NOT NULL,
  `email` varchar(50) NOT NULL,
  `sex` tinyint(1) NOT NULL,
  `birthday` char(10) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `phone` (`phone`)
) ENGINE=InnoDB AUTO_INCREMENT=202001 DEFAULT CHARSET=utf8mb4;
---用户资产表
CREATE TABLE `user_assets` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `money` decimal(10,2) unsigned NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=202001 DEFAULT CHARSET=utf8mb4;
1、in里面值的类型,和查询列定义类型不一致的情况,不走索引
mysql> DESC SELECT * FROM `user` where phone in (15370225886);
+----+-------------+-------+------------+------+---------------+------+---------+------+--------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows   | filtered | Extra       |
+----+-------------+-------+------------+------+---------------+------+---------+------+--------+----------+-------------+
|  1 | SIMPLE      | user  | NULL       | ALL  | phone         | NULL | NULL    | NULL | 201057 |    10.00 | Using where |
+----+-------------+-------+------------+------+---------------+------+---------+------+--------+----------+-------------+
1 row in set (0.03 sec)
mysql> DESC SELECT * FROM `user` where phone in ("15370225886");
+----+-------------+-------+------------+-------+---------------+-------+---------+-------+------+----------+-------+
| id | select_type | table | partitions | type  | possible_keys | key   | key_len | ref   | rows | filtered | Extra |
+----+-------------+-------+------------+-------+---------------+-------+---------+-------+------+----------+-------+
|  1 | SIMPLE      | user  | NULL       | const | phone         | phone | 44      | const |    1 |   100.00 | NULL  |
+----+-------------+-------+------------+-------+---------------+-------+---------+-------+------+----------+-------+
1 row in set (0.04 sec)
2、in查询更新,更新操作不走索引
mysql> DESC UPDATE `user_assets` SET money = 0 where id in (SELECT id FROM `user` where sex = 1);
+----+--------------------+-------------+------------+-----------------+---------------+---------+---------+------+--------+----------+-------------+
| id | select_type        | table       | partitions | type            | possible_keys | key     | key_len | ref  | rows   | filtered | Extra       |
+----+--------------------+-------------+------------+-----------------+---------------+---------+---------+------+--------+----------+-------------+
|  1 | UPDATE             | user_assets | NULL       | index           | NULL          | PRIMARY | 4       | NULL | 202032 |   100.00 | Using where |
|  2 | DEPENDENT SUBQUERY | user        | NULL       | unique_subquery | PRIMARY       | PRIMARY | 4       | func |      1 |    10.00 | Using where |
+----+--------------------+-------------+------------+-----------------+---------------+---------+---------+------+--------+----------+-------------+
2 rows in set (0.04 sec)
mysql> DESC UPDATE `user_assets` SET money = 0 where id in (SELECT id FROM `user` where id < 100);
+----+--------------------+-------------+------------+-----------------+---------------+---------+---------+------+--------+----------+--------------------------+
| id | select_type        | table       | partitions | type            | possible_keys | key     | key_len | ref  | rows   | filtered | Extra                    |
+----+--------------------+-------------+------------+-----------------+---------------+---------+---------+------+--------+----------+--------------------------+
|  1 | UPDATE             | user_assets | NULL       | index           | NULL          | PRIMARY | 4       | NULL | 202032 |   100.00 | Using where              |
|  2 | DEPENDENT SUBQUERY | user        | NULL       | unique_subquery | PRIMARY       | PRIMARY | 4       | func |      1 |   100.00 | Using where; Using index |
+----+--------------------+-------------+------------+-----------------+---------------+---------+---------+------+--------+----------+--------------------------+
2 rows in set (0.05 sec)
mysql> DESC UPDATE `user_assets` SET money = 0 where id in (SELECT id FROM `user` where id < 1000);
+----+--------------------+-------------+------------+-----------------+---------------+---------+---------+------+--------+----------+--------------------------+
| id | select_type        | table       | partitions | type            | possible_keys | key     | key_len | ref  | rows   | filtered | Extra                    |
+----+--------------------+-------------+------------+-----------------+---------------+---------+---------+------+--------+----------+--------------------------+
|  1 | UPDATE             | user_assets | NULL       | index           | NULL          | PRIMARY | 4       | NULL | 202032 |   100.00 | Using where              |
|  2 | DEPENDENT SUBQUERY | user        | NULL       | unique_subquery | PRIMARY       | PRIMARY | 4       | func |      1 |   100.00 | Using where; Using index |
+----+--------------------+-------------+------------+-----------------+---------------+---------+---------+------+--------+----------+--------------------------+
为了将一个大的数据进行压缩,可以采用Gzip的方式进行处理,那么在Go语言中如何通过Gzip方式压缩数据呢,在使用过程中大家也会跟我一样会踩坑。本文主要记录下问题和最终的实现方式。
图像梯度计算的是图像变化的速度。对于图像的边缘部分,其灰度值变化较大,梯度值也较大;相反,对于图像中比较平滑的部分,其灰度值变化较小,相应的梯度值也较小。图像梯度计算需要求导数,但是图像梯度一般通过计算像素值的差来得到梯度的近似值(近似导数值)。本节主要介绍Sobel算子、Scharr算子、Laplacian算子和Canny算子的使用.
网页扫描二维码库:Html5-Qrcode,官网地址:https://scanapp.org/html5-qrcode-docs/
nodejs中使用npm和yarn,使用最新阿里云镜像 aliyun mirror,网上很多还是文章用的是下面这个地址~~yarn config set registry https://registry.npm.taobao.org~~
《康熙王朝》是一部非常优秀的电视连续剧,陈道明演的康熙是我觉得最有帝王气魄,让人意犹未尽,本文主要记录一小段非常经典的对白。
快速生成表格
Electron页面跳转、浏览器打开链接和打开新窗口
Docker编译镜像出现:fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.2c4ac24e.tar.gz: No such file or directory问题
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。