<bdo id='Do483'></bdo><ul id='Do483'></ul>
    <i id='Do483'><tr id='Do483'><dt id='Do483'><q id='Do483'><span id='Do483'><b id='Do483'><form id='Do483'><ins id='Do483'></ins><ul id='Do483'></ul><sub id='Do483'></sub></form><legend id='Do483'></legend><bdo id='Do483'><pre id='Do483'><center id='Do483'></center></pre></bdo></b><th id='Do483'></th></span></q></dt></tr></i><div id='Do483'><tfoot id='Do483'></tfoot><dl id='Do483'><fieldset id='Do483'></fieldset></dl></div>
    1. <small id='Do483'></small><noframes id='Do483'>

    2. <tfoot id='Do483'></tfoot>

    3. <legend id='Do483'><style id='Do483'><dir id='Do483'><q id='Do483'></q></dir></style></legend>

    4. 使用联合或加入 - 哪个更快

      Use A Union Or A Join - What Is Faster(使用联合或加入 - 哪个更快)

    5. <tfoot id='13j9F'></tfoot>

          <bdo id='13j9F'></bdo><ul id='13j9F'></ul>

            1. <small id='13j9F'></small><noframes id='13j9F'>

            2. <i id='13j9F'><tr id='13j9F'><dt id='13j9F'><q id='13j9F'><span id='13j9F'><b id='13j9F'><form id='13j9F'><ins id='13j9F'></ins><ul id='13j9F'></ul><sub id='13j9F'></sub></form><legend id='13j9F'></legend><bdo id='13j9F'><pre id='13j9F'><center id='13j9F'></center></pre></bdo></b><th id='13j9F'></th></span></q></dt></tr></i><div id='13j9F'><tfoot id='13j9F'></tfoot><dl id='13j9F'><fieldset id='13j9F'></fieldset></dl></div>
              <legend id='13j9F'><style id='13j9F'><dir id='13j9F'><q id='13j9F'></q></dir></style></legend>
                  <tbody id='13j9F'></tbody>
                本文介绍了使用联合或加入 - 哪个更快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我只是想知道如果你有一张桌子并且你联合了它会比使用连接更有效吗??

                我确实知道连接会创建更多列,但这更具理论性 - 联合是否需要像连接那样对另一个表进行嵌套循环扫描?

                解决方案

                Union 会更快,因为它只是传递第一个 SELECT 语句,然后解析第二个 SELECT 语句并将结果添加到输出表的末尾.

                Join 将遍历两个表的每一行,在另一个表中查找匹配项,因此由于为每一行搜索匹配的行,因此需要更多的处理.

                编辑

                Union,我的意思是 Union All,因为它似乎足以满足您想要实现的目标.虽然普通的 Union 通常比 Join 快.

                编辑 2(回复@seebiscuit 的评论)

                我不同意他的观点.从技术上讲,无论您的连接有多好,JOIN"仍然比纯连接更昂贵.我在我的博客

                JOIN 执行计划

                实际结果

                实际上,聚集索引查找的差异可以忽略不计:

                I just wonder if you had a table and you unioned it would it be more efficent then using a join??

                I do know that the join creates more columns but this is more theoretical - Will the union need to do a nested loop scan of the other table like a join would have to?

                解决方案

                Union will be faster, as it simply passes the first SELECT statement, and then parses the second SELECT statement and adds the results to the end of the output table.

                The Join will go through each row of both tables, finding matches in the other table therefore needing a lot more processing due to searching for matching rows for each and every row.

                EDIT

                By Union, I mean Union All as it seemed adequate for what you were trying to achieve. Although a normal Union is generally faster then Join.

                EDIT 2 (Reply to @seebiscuit 's comment)

                I don't agree with him. Technically speaking no matter how good your join is, a "JOIN" is still more expensive than a pure concatenation. I made a blog post to prove it at my blog codePERF[dot]net. Practically speaking they serve 2 completely different purposes and it is more important to ensure your indexing is right and using the right tool for the job.

                Technically, I think it can be summed using the following 2 execution plans taken from my blog post:

                UNION ALL Execution Plan

                JOIN Execution Plan

                Practical Results

                Practically speaking the difference on a clustered index lookup is negligible:

                这篇关于使用联合或加入 - 哪个更快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                SQL query to group by day(按天分组的 SQL 查询)
                What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                Include missing months in Group By query(在 Group By 查询中包含缺失的月份)

                <small id='TwH4c'></small><noframes id='TwH4c'>

                  <i id='TwH4c'><tr id='TwH4c'><dt id='TwH4c'><q id='TwH4c'><span id='TwH4c'><b id='TwH4c'><form id='TwH4c'><ins id='TwH4c'></ins><ul id='TwH4c'></ul><sub id='TwH4c'></sub></form><legend id='TwH4c'></legend><bdo id='TwH4c'><pre id='TwH4c'><center id='TwH4c'></center></pre></bdo></b><th id='TwH4c'></th></span></q></dt></tr></i><div id='TwH4c'><tfoot id='TwH4c'></tfoot><dl id='TwH4c'><fieldset id='TwH4c'></fieldset></dl></div>
                1. <legend id='TwH4c'><style id='TwH4c'><dir id='TwH4c'><q id='TwH4c'></q></dir></style></legend>

                      <tfoot id='TwH4c'></tfoot>

                        <bdo id='TwH4c'></bdo><ul id='TwH4c'></ul>
                          <tbody id='TwH4c'></tbody>