我知道在一般情况下如何避免使用内连接的笛卡尔连接。
在加入从用户定义的数组创建的表时,有没有办法避免在Oracle中使用笛卡尔连接?
select col1, col2, ...
from mytable mt
inner join TABLE(user_defined_number_array(1,2,3,4)) t ON t.column_value = mytable.col1
... --inner join other tables
...
where mt.col1 IN (
SELECT column_value FROM TABLE(user_defined_number_array(1,2,3,4))
);
(在这种情况下,user_defined_number_array
是一个数字表(18),而col1的类型相同。)
这是唯一可以定义具有键值的表类型吗? (请注意,出于此目的,我希望数组非常小 - 可能永远不会超过十行。)
谢谢。
编辑:解释计划如下,我已更新查询以更好地反映我正在做的事情。我并没有模仿解释计划,因为我觉得它可能不值得。
Plan hash value: 3336195920
--------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 18 | 1224 | 183K (1)| 00:36:40 |
| 1 | NESTED LOOPS OUTER | | 18 | 1224 | 183K (1)| 00:36:40 |
| 2 | NESTED LOOPS | | 18 | 1026 | 183K (1)| 00:36:40 |
| 3 | NESTED LOOPS | | 18 | 792 | 183K (1)| 00:36:40 |
| 4 | NESTED LOOPS | | 18 | 684 | 183K (1)| 00:36:40 |
| 5 | MERGE JOIN CARTESIAN | | 8168 | 32672 | 179K (1)| 00:36:00 |
| 6 | COLLECTION ITERATOR CONSTRUCTOR FETCH | | | | | |
| 7 | BUFFER SORT | | 8168 | 16336 | | |
| 8 | SORT UNIQUE | | | | | |
| 9 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | | | | |
| 10 | TABLE ACCESS BY INDEX ROWID | LOG_ACTIVITY | 1 | 34 | 1 (0)| 00:00:01 |
|* 11 | INDEX RANGE SCAN | LOG_ACTIVITYC3 | 1 | | 1 (0)| 00:00:01 |
| 12 | TABLE ACCESS BY INDEX ROWID | RESPONSE_CODE | 1 | 6 | 1 (0)| 00:00:01 |
|* 13 | INDEX UNIQUE SCAN | RESPONSE_CODEP1 | 1 | | 1 (0)| 00:00:01 |
| 14 | TABLE ACCESS BY INDEX ROWID | LOG_ACTIVITY_TYPE | 1 | 13 | 1 (0)| 00:00:01 |
|* 15 | INDEX UNIQUE SCAN | LOG_ACTIVITY_TYPEP1 | 1 | | 1 (0)| 00:00:01 |
| 16 | TABLE ACCESS BY INDEX ROWID | EMPLOYEE | 1 | 11 | 1 (0)| 00:00:01 |
|* 17 | INDEX UNIQUE SCAN | EMPLOYEEP1 | 1 | | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------------------------