Now, we merge into the "burned into the bytecode" partition for (date'2003-03-12') - and will end in another one !:
so what? the program knows
a) it will be reading from only a given partition
b) but it could be updating into any partition
the src (the thing we'll join to, the part of T we read) is a given partition
the merge is for the table in this case.
The into clause told it what to read.
ops$tkyte%ORA11GR2> merge into t partition for (date'2003-03-12')
2 using
3 (
4 select 1 x, date'2003-03-13' d
5 from dual
6 ) t2
7 on (t.x = t2.x)
8 when matched then update set t.dt = t2.d;
1 row merged.
Execution Plan
----------------------------------------------------------
Plan hash value: 432980191
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------------------------------------------
| 0 | MERGE STATEMENT | | 1 | 28 | 16 (0)| 00:00:01 | | |
| 1 | MERGE | T | | | | | | |
| 2 | VIEW | | | | | | | |
| 3 | NESTED LOOPS | | 1 | 34 | 16 (0)| 00:00:01 | | |
| 4 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 | | |
| 5 | PARTITION RANGE SINGLE| | 1 | 34 | 14 (0)| 00:00:01 | 1 | 1 |
|* 6 | TABLE ACCESS FULL | T | 1 | 34 | 14 (0)| 00:00:01 | 1 | 1 |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
6 - filter("T"."X"=1)
see the pstart/pstop - it isn't key/key. the merge for bit only said what to read.
and that shows that it could easily be burnt into the code - the partition was well known AT COMPILE TIME.
It is interesting to see what happens if you run the merge again with a when not matched:
ops$tkyte%ORA11GR2> merge into t partition for (date'2003-03-12')
2 using
3 (
4 select 1 x, date'2003-03-13' d
5 from dual
6 ) t2
7 on (t.x = t2.x)
8 when matched then update set t.dt = t2.d
9 when not matched then insert (dt,x) values (t2.d, t2.x);
merge into t partition for (date'2003-03-12')
*
ERROR at line 1:
ORA-14401: inserted partition key is outside specified partition
makes me wonder if the update behavior is a bug.... I'll file one - it doesn't look entirely right to me.
But still - that further shows the data we READ for the merge is burnt into the program (the when not matched clause was fired, but we know that x=1 is in there, just in another partition)
but in reality, all of this discussion really isn't relevant.
There are identifiers -
tablenames
tablename partition(partition-name)
tablename for ....
identifiers CANNOT BE BOUND, period. They must be, by definition, known at compile time. The binary plan, the program, depends on knowing them all.