동일한 결과를 제공하는 양식으로 작성하는 경우 쿼리 분석기에서 동일한 * 쿼리 계획을 제공해야합니다. 즉, ,
훨씬 덜 분명하다, 수십 년
두 개의 서로 다른 쿼리의 성능을 비교하려면를 위해 사용되지 않습니다 때문에 사용이 ,
되지 가입했다, 가장 쉬운 방법은 모두를 실행하고 비교하는 것이 얼마나 그들이 쿼리 계획을 비교하여 다른 작업을 수행하고 있는지 확인했지만 (mysql의 EXPLAIN query text here
은 쿼리 계획을 제공합니다)
"다른 결과를 주지만 더 빠른 것을 원한다" 프로그래밍에서 말하는 것이 결코 현명한 방법이 아닙니다. 당신은 항상 당신이 원하는 결과를 정확히 알아야합니다.
e.e.
select table1.a ,table2.b from table1 ,table2 where table1.id=table2.id
는
select table1.a ,table2.b from table1 join table2 on table1.id=table2.id
및
select table1.a ,table2.b from table1 left join table2 on table1.id=table2.id
와 같은 의미를 가지고있다
select table1.a ,table2.b from table1 ,table2 where table1.id=table2.id
union
select table1.a , null from table1 where table1.id not in (select table2.id from table2)
그리고 당신이 사용하지 않은 형태의 참여와 같은 의미 :
select table1.a ,table2.b from table1 right join table2 on table1.id=table2.id
는
select table1.a ,table2.b from table1 ,table2 where table1.id=table2.id
union
select null, table2.b from table2 where table2.id not in (select table1.id from table1)
그리고
select table1.a ,table2.b from table1 full join table2 on table1.id=table2.id
내가 질문을 이해하지
select table1.a ,table2.b from table1 ,table2 where table1.id=table2.id
union
select table1.a , null from table1 where table1.id not in (select table2.id from table2)
union
select null, table2.b from table2 where table2.id not in (select table1.id from table1)
와 같은 의미를 가지고와 같은 의미를 가지고있다. 정교하게 주시겠습니까? – 0xCAFEBABE
둘은 동일하지 않습니다. 'LEFT JOIN'은 일치하는'table2' 행이없는'table1' 행을 반환 할 것이고, 직교 제품은이 행들을 반환하지 않을 것입니다. – Barmar
@ 0xCAFEBABE 동일한 데이터를 쿼리하려면 위의 두 가지 방법을 사용하십시오. 그러나 어떤 경우에는 성능이 향상 될 것입니다. – lpgad