表别名如何影响性能? [英] How does table alias names affect performance?

查看:322
本文介绍了表别名如何影响性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读关于调整SQL查询的时候,当你使用多个表时,我在某处读到总是使用表别名,并在所有列名前加上别名。

While reading about tuning SQL queries, I read somewhere that 'Always use table alias and prefix all column names with the aliases when you are using more than one table.'

表别名如何影响性能?

How does table alias names affect performance? Or Do they actually affect?

推荐答案

别名不会以任何实际或可衡量的方式影响效果 >在所有(在编辑添加的斜体)。也就是说,它将添加一个勉强(如果一切)可测量延迟查询编译。一旦编译(并重新使用),它就没有效果。

The alias doesn't affect performance in any practical or measurable way at all (italics added on edit). That is, it would add a barely (if it all) measurable delay to query compilation. Once compiled (and re-used), it has no effect.

当你有多个表时,别名消除歧义,因为你知道它来自哪个表。它还防止未来的表更改打破查询。说,您可以在一个表中添加一个审计列,而在另一个表中已经存在该表。没有使用这两个表的别名的查询将会中断。

An alias removes ambiguity when you have more than one table because you know which table it comes from. It also prevents future table changes from breaking a query. Say, you add an audit column to one table where it already exists in another table. Queries without aliases using both tables will break.

在某些情况下,别名也是必需的。模式绑定视图。

An alias is also mandatory in some cases e.g. schema bound views.

SQL解析引擎(在执行它们之前读取所有查询,并使用信息来缓存已编译的查询以便更快地执行)只有查看别名的东西,并使用它来帮助消除符号查找中的歧义。在执行存储之前,系统将已经生成符号,就像任何其他语言的任何其他可编译语句一样。

The SQL parsing engine (that reads all queries before executing them, and uses the information to cache the compiled queries in the future for faster execution) is the only thing that looks at the aliases, and uses it to help remove ambiguities in symbol lookups. The system would already produce symbols, just like any other compilable statement in any other language, when it's being parsed prior to execution-storage.

这篇关于表别名如何影响性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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