11

大佬们, mysql 五百万以上的 join left 关联查询统计很慢 怎么操作

 3 years ago
source link: https://www.v2ex.com/t/782830
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  MySQL

大佬们, mysql 五百万以上的 join left 关联查询统计很慢 怎么操作

  edk24 · edk24 · 2 天前 · 2562 次点击

索引已经加了,a 表 people_id 关联 b 表 id, 然后条件是 b 表的某一个字段==1,然后 count(*)

下面是 php 伪代码

$people_ids = Db::name('people_check')->where('admin_id',$value['id'])->column('people_id');
$people1 = Db::name("people")->where('id','in',$people_ids)->where('id_dailu',1)->count();  # 全部检测人数
                

admin_id 加了索引,id_dailu 加了索引。 没有全表扫描

原先写法是 join left,这个是改过的, 这个更慢。 求大佬分析一波


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK