mysql中标量子查询和关联子查询的性能比较

在mysql执行相同的查询操作:

关联子查询:

SELECT a.BranchID,b.orgname
FROM TargetCustomer AS a
JOIN Organization AS b ON a.BranchID=b.orgid;
执行时间:00:00:00:156

 

标量子查询

SELECT a.branchid,(SELECT orgname FROM Organization AS b WHERE b.orgid=a.branchid) AS branchname
FROM TargetCustomer AS a;
执行时间:00:00:04.087

结论:关联查询的性能要优于标量子查询

你可能感兴趣的:(mysql)