内连接与笛卡尔积的性能 [英] Performance of Inner Join vs Cartesian product

查看:137
本文介绍了内连接与笛卡尔积的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
显式与隐式 SQL 连接

我想知道性能上的区别

select * from A,B,C where A.x = B.y and B.y = C.z

select * from A INNER JOIN B on A.x = B.y INNER JOIN C on B.y = C.z

基本上我想知道内连接是否比笛卡尔积表现更好?另外,inner join 是在内部进行笛卡尔积吗?

Basically i want to know if inner join performs better than cartesian product? Also, in inner join is cartesian product carried out internally?

推荐答案

首先这两个操作有两个不同的目的,而笛卡尔积为您提供了一个结果,将一个表中的每一行连接到另一个表中的每一行.而内连接(有时称为简单连接)是连接两个或多个表,仅返回满足连接条件的行.
现在来看你在这里写的:
在笛卡尔积的情况下,首先创建一个由 A、B、C 组成的表,然后根据给定的条件,我们得到结果.但正如你所见,这是一个繁重的过程.
另一方面,内连接只选择那些真正满足给定条件的结果.因此,它是实现最终结果的更好解决方案.
第一个是滥用SQL语言.

First of All these two Operations are for Two different purposes , While Cartesian Product provides you a result made by joining each row from one table to each row in another table. while An inner join (sometimes called a simple join ) is a join of two or more tables that returns only those rows that satisfy the join condition.
Now coming to what You have Written here :
In case of Cartesian product First A table comprising of A,B,C is created and after that on the basis of what ever condition is given,we Get result. But as you see it's heavy process.
On the other hand Inner join only chooses those result which are really fulfilling the given condition .Hence it's a better solution for achieving end results.
First one is abuse of SQL language.

这篇关于内连接与笛卡尔积的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆