10.07.2015 Views

Expert Oracle Exadata - Parent Directory

Expert Oracle Exadata - Parent Directory

Expert Oracle Exadata - Parent Directory

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 13 MIGRATING TO EXADATAdirect path load transaction active against that table. Note that others can still read that table, as SELECTstatements don’t take enqueue locks on tables they select from.So, how to work around this concurrency issue? Luckily <strong>Oracle</strong> INSERT syntax allows you to specifythe exact partition or subpartition where you want to insert, by its name:INSERT /*+ APPEND */INTOfact PARTITION ( Y20080101 )SELECT*FROMfact@sourcedbWHEREorder_date >= TO_DATE('20080101 ', 'YYYYMMDD ')AND order_date < TO_DATE('20080102', 'YYYYMMDD ')With this syntax, the direct-path insert statement would lock only the specified partition, and othersessions could freely insert into other partitions of the same table. <strong>Oracle</strong> would still perform partitionkey checking, to ensure that data wouldn’t be loaded into wrong partitions. If you attempt to insert aninvalid partition key value into a partition, <strong>Oracle</strong> returns the error message:ORA-14401: inserted partition key is outside specified partition.Note that we did not use the PARTITION ( partition_name ) syntax in the SELECT part of the query.The problem here is that the query generator (unparser), which composes the SQL statement to be sentover the database link, does not support the PARTITION syntax. If you try it, you will get an error:ORA-14100: partition extended table name cannot refer to a remote object.That’s why we are relying on the partition pruning on the source database side—we just write thefilter predicates in the WHERE condition so that only the data in the partition of interest would bereturned. In the example just shown, the source table is range-partitioned by order_date column; andthanks to the WHERE clause passed to the source database, the partition pruning optimization in thatdatabase will only scan through the required partition and not the whole table.Note that we are not using the BETWEEN clause in this example, as it includes both values in the rangespecified in the WHERE clause, whereas <strong>Oracle</strong> Partitioning option’s “values less than” clause excludes thevalue specified in DDL from the partition’s value range.It is also possible to use subpartition-scope insert syntax, to load into a single subpartition (thuslocking only a single subpartition at time). This is useful when even a single partition of data is too largeto be loaded fast enough via a single process/database link, allowing you to split your data into evensmaller pieces:INSERT /*+ APPEND */INTOfact SUBPARTITION ( Y20080101_SP01 )SELECT*FROMfact@sourcedbWHEREorder_date >= TO_DATE('20080101 ', 'YYYYMMDD ')AND order_date < TO_DATE('20080102', 'YYYYMMDD ')AND ORA_HASH(customer_id, 63, 0) + 1 = 1440

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!