V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  GGGG430  ›  全部回复第 8 页 / 共 20 页
回复总数  396
1 ... 4  5  6  7  8  9  10  11  12  13 ... 20  
2020-02-22 16:22:01 +08:00
回复了 zuiye111 创建的主题 MySQL 请教一条 mysql 慢查询问题
第一列 type:
ref: 使用非唯一索引(即非 unique,primary key)扫描或唯一索引的前缀扫描,
index: 索引全扫描, MySQL 遍历整个索引来查询匹配的行

这个估计表明 create_time 了扫描了过多的索引,

另外我觉得纠结这些没必要, 就像上面说的, 优化你的 sql 才是关键
2020-02-22 16:13:06 +08:00
回复了 zuiye111 创建的主题 MySQL 请教一条 mysql 慢查询问题
@zuiye111 另外, filtered 这个值范围是 0-100, 你理解的 0-1 是错的
2020-02-22 16:10:31 +08:00
回复了 zuiye111 创建的主题 MySQL 请教一条 mysql 慢查询问题
我建议直接强制使用两种索引的情况下,分别打印一下时间耗在哪里, 一会贴出来看看
set profiling = 1;
select * from order ... force index (xxx);
show profiles;
2020-02-22 16:00:27 +08:00
回复了 zuiye111 创建的主题 MySQL 请教一条 mysql 慢查询问题
哪来的扫全表呢, rows: 预估需要扫描的行数, 你的值在使用 create_time 索引时才 1131
2020-02-22 15:56:46 +08:00
回复了 zuiye111 创建的主题 MySQL 请教一条 mysql 慢查询问题
@zuiye111 是百分比啊, 存储引擎返回的数据在 server 层过滤后, 剩下多少满足查询的记录数量的比例
你能贴一下当用 mchcode 索引时的 explain 记录吗, 看一下 rows 这列值
2020-02-22 15:43:55 +08:00
回复了 zuiye111 创建的主题 MySQL 请教一条 mysql 慢查询问题
@zuiye111 很显然使用 mchcode 索引时(其`选择性`很大), 存储引擎该索引筛选出的结果集很小了啊, 而 create_time 并没有筛除任何数据啊, 你没看到用 create_time 索引时 filtered 这列为 0 吗? 你再看看用 mchcode 索引时, 这一列应该有几十了
2020-02-22 15:24:52 +08:00
回复了 zuiye111 创建的主题 MySQL 请教一条 mysql 慢查询问题
@zuiye111 如果是这样的话, 你仍然可以用我上面那个 sql, 只不过那个联合索引改成多个单列索引或者多个较小的联合索引, 但是这个(order_property_bit & 128)=128 语句一定要移出来在业务层处理, 这个会导致很多索引用不上, 而移出这行也就要导致移出后面的 order by 到业务层面处理
2020-02-22 15:11:30 +08:00
回复了 zuiye111 创建的主题 MySQL 请教一条 mysql 慢查询问题
首先该一下你的 sql:
select * from order
where user_id = 12345
and mchcode = '56789'
and order_state in (2,4,5)
and channel_type = 2;

然后增加索引(先不不考虑列选择性):
create index idx_xx on order (user_id, mchcode, order_state, channel_type)

最后业务层通过上面的 sql 应该查不来的结果集很小了, 手动代码处理:
(order_property_bit & 128) == 128
order by order by create_time desc LIMIT 1 OFFSET 0;

你试试
2020-02-15 21:19:56 +08:00
回复了 alan0liang 创建的主题 远程工作 求腾讯会议 Linux 解决方案
虚拟机里面装个 Windows
2020-02-10 11:18:08 +08:00
回复了 OysterQAQ 创建的主题 问与答 inner join 下 order by 排序不走索引
@OysterQAQ 是耗时增加了的意思吗
2020-02-07 13:06:24 +08:00
回复了 OysterQAQ 创建的主题 问与答 inner join 下 order by 排序不走索引
因为 artist_id 过多导致子查询不方便的话, 你就增加一下(type, create_date)这个索引吧, explain 如下
1 SIMPLE illusts ref artist_id_type_create_date_index,type_create_date_index type_create_date_index 82 const 1 100 Using index condition
1 SIMPLE user_artist_followed ref user_id_artist_id_create_date,idx_artist_id user_id_artist_id_create_date 14 const,func 1 100 Using where; Using index

另外我觉得你第一个子查询中的 order by artist_id,type,create_date 很奇怪, 能否和最后的 order by 合并呢
2020-02-07 12:34:43 +08:00
回复了 OysterQAQ 创建的主题 问与答 inner join 下 order by 排序不走索引
explain select artist_id from user_artist_followed where user_id = 53;
explain select * from illusts where artist_id in (?, ?) and type = 'illust' order by artist_id, type, create_date;
感觉拆分一下子查询好点
2020-02-07 12:30:15 +08:00
回复了 OysterQAQ 创建的主题 问与答 inner join 下 order by 排序不走索引
create index type_create_date_index
on illusts ( type, create_date);
illusts 表上的 where 条件中 artist_id 用了表达式没走联合索引, 重新建一个
2020-02-07 12:09:08 +08:00
回复了 OysterQAQ 创建的主题 问与答 inner join 下 order by 排序不走索引
show create tables;
2020-02-03 20:53:31 +08:00
回复了 zjq123 创建的主题 美酒与美食 你最喜欢的蔬菜?
包菜,花菜,蒜台,藕,蒜苗 都好弄
2020-01-25 01:11:12 +08:00
回复了 Ellis 创建的主题 Apple 大佬们有苹果 APP store 验发票失败的吗
看来不止我一个人
2020-01-12 21:48:54 +08:00
回复了 luyan 创建的主题 生活 关于解酒药
实际上没有解酒药, 也不要去吃解酒药, 喝酒的时候多吃菜, 多上厕所
2019-12-19 22:45:09 +08:00
回复了 raysonlu 创建的主题 PHP PHP 常驻任务不会释放内存的吗?
问题出在 new someObj ()这里,以及调用这个对象中方法中存在申请内存并且未释放,外部的 unset 是不管用的,建议你复用这个对象
2019-12-05 01:59:47 +08:00
回复了 salamanderMH 创建的主题 NVIDIA Ubuntu 更新后,发现 nvidia 驱动不能用了
只有 04 和 10 版本吧
1 ... 4  5  6  7  8  9  10  11  12  13 ... 20  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5554 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 28ms · UTC 06:37 · PVG 14:37 · LAX 23:37 · JFK 02:37
Developed with CodeLauncher
♥ Do have faith in what you're doing.