mysql笔记.txt

时间:2022-08-03 06:43:52
【文件属性】:
文件名称:mysql笔记.txt
文件大小:13KB
文件格式:TXT
更新时间:2022-08-03 06:43:52
da 最近整理的笔记 SQL执行计划 explain select customer_id,title,content from product_comment where audit_status=1 and product_id=199 limit 0,5; 查询计划的限制 无法展示存储过程,触发器,UDF对查询的影响 联合索引 应当把区分度好的放到联合索引的左侧 sql语句改写 select customer_id,title,content from product_comment where audit_status=1 and product_id=199 limit 0,5; 该语句缺点越往后翻页效率越差, 适用于表数据量不大,10000行一下, 或者查询条件特别复杂,比如涉及到多个不同的查询判断或表关联的时候。 select t.customer_id,t.table,t.comment from ( select customer_id from product_comment where product_id=199 and audit_status=1 limit 0,5 ) a join product_comment t on a.comment_id=t.comment_id; 需要product_comment表的主键是comment_id,且有覆盖索引product_id与audit_status, 优点每次翻页效率相同,消耗资源, 适用条件where和order by所涉及的字段有覆盖索引或者中间结果集很大的情况。

网友评论

相关文章