Home > Backend Development > PHP Tutorial > sql数据查询优化,该如何解决

sql数据查询优化,该如何解决

WBOY
Release: 2016-06-13 11:45:56
Original
1050 people have browsed it

sql数据查询优化
select a.id,rkno,a.packageno as packageno,cust_no,lotno,count(*) as count from `rk_record` as a right join `sys_barcode_1d_y` as b on a.packageno = b.packageno where rkno = '201401030031' group by packageno,lotno order by packageno,lotno asc

rkno,packageno均含索引。

目前查询需要4000多ms,有没有什么方法可以优化该sql语句?
------解决方案--------------------
b表没有索引被使用

尝试将 a.packageno = b.packageno
写作 b.packageno = a.packageno
------解决方案--------------------
b表字段未用到索引,查看b表关联字段是否新建索引。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template