简体   繁体   English

Oracle 12c内联视图评估

[英]Oracle 12c Inline View Evaluation

A long time ago in a database far, far away a developer wrote a query in which he/she was reliant on the order in which predicates were written. 很久以前,在一个远在很远的数据库中,开发人员编写了一个查询,其中他/她依赖于编写谓词的顺序。

For example, 例如,

select x
  from a, b
 where NOT REGEXP_LIKE (a.column, '[^[:digit:]]')
   and a.char_column = b.numeric_column; 

(explain plan suggests a to_number conversion will be applied to a.char_column ) (解释计划建议将to_number转换应用于a.char_column

I think by chance more than design this "just works" (Oracle 11g). 我认为不仅仅是设计这个“正常工作”(Oracle 11g)。 However, the order of the predicates isn't adhered to when running in Oracle 12c, so this query breaks with an invalid number exception. 但是,在Oracle 12c中运行时,不遵循谓词的顺序,因此此查询会因无效数字异常而中断。 I'm aware that I could try to force 12c to evaluate the predicates in order by using the ORDERED_PREDICATES hint as follows 我知道我可以尝试通过使用ORDERED_PREDICATES提示强制12c按顺序评估谓词

select /*+ ORDERED_PREDICATES +*/ x
  from a, b
 where NOT REGEXP_LIKE (a.column, '[^[:digit:]]')
   and a.char_column = b.numeric_column

.. Or cast one of the values using to_char for the comparison. ..或使用to_char其中一个值进行比较。 The downside is that to_char could operate on say a million rows. 缺点是to_char可能会运行一百万行。 I think the following inline view is probably a better solution. 我认为以下内联视图可能是一个更好的解决方案。 Am I guaranteed that the inline view will be evaluated first? 我保证首先评估内联视图吗?

select x
  from b
  inner join (
              select only_rows_with_numeric_values as numeric_column
                from a 
               where NOT REGEXP_LIKE (a.column, '[^[:digit:]]')
             )  c
     on c.numeric_column = b.numeric_column;

About predicate order - look at https://jonathanlewis.wordpress.com/2015/06/02/predicate-order-2/ 关于谓词顺序 - 请查看https://jonathanlewis.wordpress.com/2015/06/02/predicate-order-2/

You should rewrite your last query to next using rownum according to doc( https://docs.oracle.com/database/121/SQLRF/queries008.htm#SQLRF52358 ) 您应该根据doc( https://docs.oracle.com/database/121/SQLRF/queries008.htm#SQLRF52358 )使用rownum将上一个查询重写为next。

select x
  from b
  inner join (
              select only_rows_with_numeric_values as numeric_column,
                rownum
                from a 
               where NOT REGEXP_LIKE (a.column, '[^[:digit:]]')
             )  c
     on c.numeric_column = b.numeric_column;

to suppress query unnesting or simply using hint /*+ no_unnest*/ 禁止查询取消或仅使用提示/*+ no_unnest*/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM