使用全外连接进行分区修剪

时间:2018-05-16 08:54:36

标签: oracle

我有两个相同的表,我想在一个特定值(分区列)上执行它们之间的完全外连接。执行计划显示PARTITION RANGE ALL而不是PARTITION RANGE SINGLE。我原本期望过滤谓词应用于id 4& 5,加入之前。这种方式不支持还是我做错了?

select *
  from t1 full join t2 using(d)
 where d = date '2018-01-03';

-----------------------------------------------------------
| Id  | Operation              | Name     | Pstart| Pstop |
-----------------------------------------------------------
|   0 | SELECT STATEMENT       |          |       |       |
|   1 |  PARTITION RANGE ALL   |          |     1 |     3 |
|*  2 |   VIEW                 | VW_FOJ_0 |       |       |
|*  3 |    HASH JOIN FULL OUTER|          |       |       |
|   4 |     TABLE ACCESS FULL  | T1       |     1 |     3 |
|   5 |     TABLE ACCESS FULL  | T2       |     1 |     3 |
-----------------------------------------------------------

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

   2 - filter("D"=TO_DATE(' 2018-01-03 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
   3 - access("T1"."D"="T2"."D")

我可以通过手动推送谓词来获得我想要的东西:

select * 
  from      (select * from t1 where d = date '2018-01-03')
  full join (select * from t2 where d = date '2018-01-03') using(d);

-------------------------------------------------------------
| Id  | Operation                | Name     | Pstart| Pstop |
-------------------------------------------------------------
|   0 | SELECT STATEMENT         |          |       |       |
|   1 |  VIEW                    | VW_FOJ_0 |       |       |
|*  2 |   HASH JOIN FULL OUTER   |          |       |       |
|   3 |    PARTITION RANGE SINGLE|          |     3 |     3 |
|   4 |     VIEW                 |          |       |       |
|*  5 |      TABLE ACCESS FULL   | T1       |     3 |     3 |
|   6 |    PARTITION RANGE SINGLE|          |     3 |     3 |
|   7 |     VIEW                 |          |       |       |
|*  8 |      TABLE ACCESS FULL   | T2       |     3 |     3 |
-------------------------------------------------------------

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

   2 - access("from$_subquery$_001"."D"="from$_subquery$_003"."D")
   5 - filter("D"=TO_DATE(' 2018-01-03 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
   8 - filter("D"=TO_DATE(' 2018-01-03 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))

用于创建这些表的测试用例

create table t1(
   d date   not null
  ,n number not null 
)
partition by range(d)(
   partition jan1 values less than(date '2018-01-02')
  ,partition jan2 values less than(date '2018-01-03')
  ,partition jan3 values less than(date '2018-01-04')
);

create table t2(
   d date   not null
  ,n number not null
)
partition by range(d)(
   partition jan1 values less than(date '2018-01-02')
  ,partition jan2 values less than(date '2018-01-03')
  ,partition jan3 values less than(date '2018-01-04')
);

insert into t1(d,n) values(date '2018-01-01', 1);
insert into t1(d,n) values(date '2018-01-02', 2);
insert into t2(d,n) values(date '2018-01-02', 2);
insert into t2(d,n) values(date '2018-01-03', 3);

commit;

我正在使用Oracle Database 12c企业版12.1.0.2.0版 - 64位生产

0 个答案:

没有答案