sql join语句中的表顺序是否有任何意义 [英] Is there any significance in the order of table in sql join statement

查看:37
本文介绍了sql join语句中的表顺序是否有任何意义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sql join语句中表的顺序是否有任何意义.例如

Is there any significance in the order of table in sql join statement. For example

SELECT dept_name, emp_name 
FROM   Employee 
INNER JOIN Department ON Employee.dept_id = Department.dept_id

SELECT dept_name, emp_name 
FROM Department 
INNER JOIN Employee  ON Employee.dept_id = Department.dept_id

表格顺序是否有性能优势?

Is there is any performance advantage in the order of tables?

推荐答案

没有.

大多数(如果不是全部)DBMS使用基于成本的优化器.您指定语句的顺序不会影响执行速度.

Most (if not all) DBMS's use of a Cost based optimizer. The order in which you specify your statements does not affect speed of execution.

基于Oracle SQL成本的优化

Oracle基于成本的SQL优化器(CBO)非常复杂Oracle的组件,它控制每个Oracle查询的执行.CBO已发展成为世界上最先进的组织之一软件组件,并且它具有评估任何具有挑战性的工作SQL语句,并为该语句生成最佳"执行计划声明.

Oracle's cost-based SQL optimizer (CBO) is an extremely sophisticated component of Oracle that governs the execution for every Oracle query. The CBO has evolved into one of the world's most sophisticated software components, and it has the challenging job of evaluating any SQL statement and generating the "best" execution plan for the statement.

您的两条语句都会生成相同的执行计划,因此具有相同的性能特征.请注意,费用将基于可用的统计数据.更新统计信息对于优化器能够生成最有效的执行计划非常重要.

Both your statements will generate the same execution plan and hence have the same perfomance characteristics. Note that the cost will be based on available statistics. Updated statistics is very important for the optimizer to be able to generate the most efficient execution plan.

这篇关于sql join语句中的表顺序是否有任何意义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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