<legend id='rM2vi'><style id='rM2vi'><dir id='rM2vi'><q id='rM2vi'></q></dir></style></legend><tfoot id='rM2vi'></tfoot>
      1. <small id='rM2vi'></small><noframes id='rM2vi'>

        • <bdo id='rM2vi'></bdo><ul id='rM2vi'></ul>

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

        Oracle 是否使用短路评估?

        时间:2023-09-18
        <tfoot id='PPKBB'></tfoot>

            <bdo id='PPKBB'></bdo><ul id='PPKBB'></ul>

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

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

                • <legend id='PPKBB'><style id='PPKBB'><dir id='PPKBB'><q id='PPKBB'></q></dir></style></legend>
                  本文介绍了Oracle 是否使用短路评估?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个结构如下的 Oracle 查询:

                  I have an Oracle query that is structured as followed:

                  SELECT   *
                  FROM     table
                  WHERE    X='true' OR
                           Y IN (complicated subquery)
                  

                  如果 Oracle 发现 X 确实等于真",它还会尝试评估 WHERE 子句的 Y IN(子查询)部分吗?此外,在这样的语句中,子查询是否会针对表中的每个条目执行多次?我会不会更好地使用以下内容:

                  If Oracle sees that X does equal 'true' will it still try to evaluate the Y IN (subquery) part of the WHERE clause? Also, in a statement such as this would the subquery be executed multiple times for each entry in the table? Would I be better off with something like:

                  WITH subQ as (complicated subquery)
                  SELECT   *
                  FROM     table
                  WHERE    X='true' OR
                           Y IN (SELECT id FROM subQ)
                  

                  推荐答案

                  视情况而定..一般情况下,Oracle 不保证 SQL 语句会使用短路求值(尽管 PL/SQL 保证执行短路求值).Oracle 优化器可以按照它认为最有效的任何顺序自由地评估谓词.这可能意味着首先评估第一个谓词,只有匹配的行才评估第二个谓词,但完全有可能发生相反的情况,或者 Oracle 将查询转换为一种 UNION 并且完全在组合结果之前评估两个谓词.

                  It depends. . In general, Oracle does not guarantee that a SQL statement will use short-circuit evaluation (though PL/SQL is guaranteed to perform short-circuit evaluation). The Oracle optimizer is free to evaluate the predicates in whatever order it expects to be most efficient. That might mean that the first predicate is evaluated first and only the matching rows have the second predicate evaluated but it is entirely possible that either the reverse happens or that Oracle transforms the query into a sort of UNION and fully evaluates both predicates before combining the results.

                  话虽如此,如果优化器可以在编译时确定谓词的计算结果始终为 TRUEFALSE,优化器应该将其视为常量.因此,例如,如果表上有一个约束,阻止 X 的值为 'true',优化器根本不应该评估第二个谓词(尽管不同版本的优化器将具有不同的能力来在编译时检测某些内容是否为常量).

                  That being said, if the optimizer can determine at compile time that a predicate will always evaluate to TRUE or FALSE, the optimizer should just treat that as a constant. So if, for example, there is a constraint on the table that prevents X from ever having a value of 'true', the optimizer shouldn't evaluate the second predicate at all (though different versions of the optimizer will have different abilities to detect that something is a constant at compile time).

                  至于你问题的第二部分,没有看到查询计划,很难说.如果有更有效的评估方法,Oracle 优化器往往非常擅长将查询从一种形式转换为另一种形式.但是,一般而言,如果 subQtable 相比将返回相对较多的行,则将查询结构化为 EXISTS 可能更有效 而不是 IN.

                  As for the second part of your question, without seeing the query plans, it's very hard to tell. The Oracle optimizer tends to be pretty good at transforming queries from one form to another if there are more efficient ways of evaluating it. In general, however, if subQ is going to return a relatively large number of rows compared to table, it may be more efficient to structure the query as an EXISTS rather than as an IN.

                  这篇关于Oracle 是否使用短路评估?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:SQL 错误“ORA-01722:无效数字" 下一篇:Oracle:将子查询中的多个结果组合成一个逗号分隔的值

                  相关文章

                  1. <tfoot id='frP0m'></tfoot>

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

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

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