ORA-01652 为什么未使用的行限制器解决了这个问题?

ORA-01652 Why does unused row limiter solve this?

如果我 运行 一个没有行限制器的查询,我会得到一个 ora-01652 告诉我我超出了临时 table space。 (我不是 DBA,我承认我并不完全理解这个错误。)如果我添加一个 rownum < 1000000000 它会在几秒钟内 运行s (是的,它被限制为十亿行)。我的内部查询只有 returns 大约 1,000 行。一个从未达到的荒谬大行限制器如何进行此查询 运行?有限查询和无限查询应该没有区别吧?

select
    col1,
    col2,
    ...
from
        (
            select
                col1, col2,...
            from table1 a
                join table2 b-- limiter for performance
                     on a.column= b.column
                     or a.col= b.col
            where
                filter = 'Y'
                and rownum <1000000000  -- irrelevant but query doesn't run without it.
    )  c
join table3 d
        on c.id  = d.id

我们需要查看带有和不带 rownum 条件的查询的执行计划。但是举个例子,添加一个"rownum" 可以改变一个执行计划

SQL> create table t as select * from dba_objects
  2  where object_id is not null;

Table created.

SQL>
SQL> create index ix on t ( object_id );

Index created.

SQL>
SQL> set autotrace traceonly explain
SQL> select * from t where object_id > 0 ;

Execution Plan
----------------------------------------------------------
Plan hash value: 1601196873

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      | 82262 |    10M|   445   (2)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T    | 82262 |    10M|   445   (2)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("OBJECT_ID">0)

SQL> select * from t where object_id > 0  and rownum < 10;

Execution Plan
----------------------------------------------------------
Plan hash value: 658510075

---------------------------------------------------------------------------------------------
| Id  | Operation                            | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                     |      |     9 |  1188 |     3   (0)| 00:00:01 |
|*  1 |  COUNT STOPKEY                       |      |       |       |            |          |
|   2 |   TABLE ACCESS BY INDEX ROWID BATCHED| T    |     9 |  1188 |     3   (0)| 00:00:01 |
|*  3 |    INDEX RANGE SCAN                  | IX   |       |       |     2   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------

这是一个简单的示例,但您可以通过连接等得到类似的东西,特别是,"rownum" 子句可能会禁止最内层的连接折叠到最外层的连接中,从而产生不同的计划。