以下两段sql有性能区别吗?
1、嵌套子查询
select asn.bl_no,max(file.id) as bl_file_id
from (select asnpo.bl_no
from cp_order_asn_po asnpo
where asnpo.bl_file_id is null and asnpo.bl_no is not null and asnpo.bl_no <> '') as asn,

(select id,filename from cp_flow_fileupload 
where cp_flow_fileupload.modeltype=8
and cp_flow_fileupload.pageflag=13
and cp_flow_fileupload.filetype=1 ) as file
where file.filename like '%'|| asn.bl_no ||'%'
group by asn.bl_no
2、全联结查询
select asnpo.bl_no,max(file.id) as bl_file_id
from cp_order_asn_po asnpo,cp_flow_fileupload file
where file.filename like '%'|| asnpo.bl_no ||'%'
and asnpo.bl_file_id is null and asnpo.bl_no is not null and asnpo.bl_no <> ''
and file.modeltype=8
and file.pageflag=13
and file.filetype=1
group by asnpo.bl_nosql中cp_order_asn_po和cp_flow_fileupload都有几万条数据,以后还会更多,用哪个sql更好点?

解决方案 »

  1.   

    where file.filename like '%'|| asn.bl_no ||'%'这个是什么意思两个表没有连接条件吗  自然连接  笛卡尔积?
      

  2.   

    理论上第二个会好一些,这样MYSQL可会一些优化。但MYSQL优化的结果并不保证一定比人为决定的方案好。具体要看你各表中的数据,以及符合条件的记录数及时连接字段上的不重复数的分布情况。