作者:木棉 | 来源:互联网 | 2023-08-13 13:03
selectexec_sqnfromawherebarcode11101072089978;a表barcode建有索引,查询很快,得到结果33562465selectg
select exec_sqn from a where barcode='11101072089978';a表barcode建有索引 ,查询很快, 得到结果'33562465'
select groupno from b where exec_sqn='33562465';b表exec_sqn建有索引,查询很快
select groupno from a,b where a.exec_sqn=b.exec_sqn and a.barcode='11101072089978'
两个表连接后查询就很慢了,求解释!
7 个解决方案
2个表的exec_sqn都建了索引 还是很慢
我目前只能用连续2次查询来解决
exec_sqn 上加索引,如果引用列固定,可以考虑应用include来解决。
说明2个表都是字段很多的大表,数据量都是上百万的,用连接2次查询都是瞬间插出结果,但关联查询却要10几秒