sql连接查询中表别名的重要性是什么?
我在oracle中用两个表编写了一个sql连接查询。 在编写查询时,我没有使用任何表别名来引用 select 子句中的列。 现在这是可能的,因为所选列在两个表中具有不同的名称。
那么问题来了;是否有必要(从性能的角度来看)使用表别名来选择列,无论两个表中是否有任何相似的列名?
请注意:现在我的印象是“在连接查询的情况下,当我们不指定表别名来选择列时,oracle 将始终查找表元数据以找出哪个表具有此列。” 那么我的假设正确吗?
谢谢, 哈努曼特
I wrote a sql join query in oracle with two table.
While writing query I did not use any table alias to refer column in select clause.
Now this was possible because the selected columns were having different names in both the tables.
So the question follows; is it necessary (from performance point of view) to use a table alias to select column regardless there is any similar column name in both the tables?
Please note: Right now I am under impression that "In case of join query when we do not specify table alias to select column oracle will always lookup the table metadata to find out which table has this column." So is my assumption true?
Thanks,
hanumant
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,你的假设不正确。
使用表别名至少有四个原因:
使用它们不会造成明显的性能损失。
No, your assumption is not true.
There are at least four reasons to use table aliases:
There is no significant performance penalty from using them.
为了简单起见...
这会失败
这不会失败
第一个失败的原因是优化引擎不知道从哪个表中提取 ID 字段。使用别名 - 您可以给它一个关于要使用哪个表的“提示”。别名只是完整表名的替代。
您还必须小心尝试访问别名表的位置。有关这方面的更多信息,请查看 SQL 操作顺序。
To make it simple...
This fails
This doesn't fail
The reason the first one fails is because the Optimization Engine does not know which table to pull the ID field from. With the alias - you give it a "hint" as to which table to use. The alias is just a substitute for the full table name.
You also have to be careful where you try to access the aliased tables. For more information on this check out the SQL order of operations.