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

  1. <small id='qg07D'></small><noframes id='qg07D'>

        <bdo id='qg07D'></bdo><ul id='qg07D'></ul>
      <legend id='qg07D'><style id='qg07D'><dir id='qg07D'><q id='qg07D'></q></dir></style></legend>

    1. 使用 BETWEEN 条件对 INNER JOIN 进行性能调整

      Performance tuning on INNER JOIN with BETWEEN Condition(使用 BETWEEN 条件对 INNER JOIN 进行性能调整)

      <i id='KqmFp'><tr id='KqmFp'><dt id='KqmFp'><q id='KqmFp'><span id='KqmFp'><b id='KqmFp'><form id='KqmFp'><ins id='KqmFp'></ins><ul id='KqmFp'></ul><sub id='KqmFp'></sub></form><legend id='KqmFp'></legend><bdo id='KqmFp'><pre id='KqmFp'><center id='KqmFp'></center></pre></bdo></b><th id='KqmFp'></th></span></q></dt></tr></i><div id='KqmFp'><tfoot id='KqmFp'></tfoot><dl id='KqmFp'><fieldset id='KqmFp'></fieldset></dl></div>
      • <bdo id='KqmFp'></bdo><ul id='KqmFp'></ul>

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

          1. <legend id='KqmFp'><style id='KqmFp'><dir id='KqmFp'><q id='KqmFp'></q></dir></style></legend><tfoot id='KqmFp'></tfoot>
              <tbody id='KqmFp'></tbody>

                本文介绍了使用 BETWEEN 条件对 INNER JOIN 进行性能调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有两个表,分别是 tbl_Smalltbl_Large.

                I have two table's namely tbl_Small and tbl_Large.

                我存储在 Microsoft Azure 中的表和从 Microsoft SQL Server 查询的表.

                Both the table's I have stored in Microsoft Azure and querying from Microsoft SQL Server.

                --表 1:Tbl_Small

                --Table 1: Tbl_Small

                CREATE TABLE tbl_Small
                (
                    cola int
                );
                
                INSERT INTO tbl_Small VALUES(1234),(123),(34); 
                --1000 rows
                

                --表2:tbl_Large

                --Table 2: tbl_Large

                CREATE TABLE tbl_Large
                (
                    ID bigint identity(1,1),
                    cola int,
                    colb int,
                    colc varchar(100)
                );
                
                INSERT INTO tbl_Large(cola,colb,colc) VALUES(0,140,'A'),(150,200,'C'),(1000,15000,'D');
                --30 million rows 
                

                我想通过在条件之间加入小表来获取大表的详细信息.

                I want to get large table details by joining small table with between condition.

                我的尝试:

                1. 在 tbl_Small(cola) 上创建了 NONCLUSTERED 索引.
                2. 在 tbl_Large(cola) 和 tbl_Large(colb) 上创建了 NONCLUSTERED 索引.
                1. Created NONCLUSTERED index on tbl_Small(cola).
                2. Created NONCLUSTERED index on tbl_Large(cola) and tbl_Large(colb).

                查询:

                SELECT s.cola as [Input],l.cola,l.colb,l.colc
                FROM tbl_Large AS l
                INNER JOIN tbl_Small s ON s.cola BETWEEN l.cola and l.colb
                

                注意:上述查询的执行时间超过 10 分钟.

                Note: The above query's execution time is over 10 minutes.

                编辑:按照回答所述在所有列上添加非聚集索引后,我得到了以下执行计划.

                Edit: After adding nonclustered index on all columns as said in answer, I got the following execution plan.

                执行时间:5分钟

                DTU 百分比图:

                推荐答案

                您在 tbl_Large 上的索引需要覆盖,即它包含查询所需的所有数据.如果您只是在一列上创建索引,那么要获取所有数据,服务器将需要使用索引和另一个源来获取另一列数据.它很可能不会发现它值得额外的工作,并且会一起忽略索引.

                Your index on tbl_Large needs to be covering i.e. it holds all the data the query needs. If you just create an index on the one column then to get all the data the server will need to use the index and another source to get the other column data. It's probable it won't find it worth the extra work and will ignore the index all together.

                对于 tbl_Large,在 col a 和 col b 上创建索引,并包含 col c 的值,因此代码如下所示:

                For tbl_Large create an index on both col a and col b and also include the value for col c so the code looks like this:

                CREATE NONCLUSTERED INDEX IX_tbl_Large_cola_colb on tbl_Large (cola, colb)
                INCLUDE (colc)
                

                这篇关于使用 BETWEEN 条件对 INNER JOIN 进行性能调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Oracle PL/SQL - Raise User-Defined Exception With Custom SQLERRM(Oracle PL/SQL - 使用自定义 SQLERRM 引发用户定义的异常)
                Oracle: is there a tool to trace queries, like Profiler for sql server?(Oracle:是否有跟踪查询的工具,例如用于 sql server 的 Profiler?)
                SELECT INTO using Oracle(使用 Oracle SELECT INTO)
                PL/SQL - Use quot;Listquot; Variable in Where In Clause(PL/SQL - 使用“列表Where In 子句中的变量)
                Oracle: Import CSV file(Oracle:导入 CSV 文件)
                How can multiple rows be concatenated into one in Oracle without creating a stored procedure?(如何在不创建存储过程的情况下在 Oracle 中将多行连接为一个?)

                    • <bdo id='iBzMH'></bdo><ul id='iBzMH'></ul>
                        <tbody id='iBzMH'></tbody>

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

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