© 2010 IBM Corporation September 9, 2010 IDS 11.7 – New Fragmentation Strategies Scott Pickett...

63
© 2010 IBM Corporation September 9, 2010 IDS 11.7 – New Fragmentation Strategies Scott Pickett – WW Informix Technical Sales For questions about this presentation contact: [email protected]

Transcript of © 2010 IBM Corporation September 9, 2010 IDS 11.7 – New Fragmentation Strategies Scott Pickett...

© 2010 IBM CorporationSeptember 9, 2010

IDS 11.7 – New Fragmentation Strategies

Scott Pickett – WW Informix Technical SalesFor questions about this presentation contact: [email protected]

© 2010 IBM Corporation2

List / Interval Fragmentation Strategies. OAT - List / Interval Fragmentation Strategies. ALTER FRAGMENT support. ALTER FRAGMENT ONLINE support.

ALTER FRAGMENT Support

Agenda

© 2010 IBM CorporationSeptember 9, 2010

List / Interval Fragmentation Strategies

© 2010 IBM Corporation4

Fragmentation (or Partitioning)

Allows data from a single table to be stored on multiple disks.

Non-fragmented table:

CREATE TABLE tab1 (i INT);

CREATE TABLE tab2 (i INT) IN dbs0;

Fragmented table:

CREATE TABLE tab3 (i INT)

FRAGMENT BY ROUND ROBIN IN dbs1, dbs2;

CREATE TABLE tab4 (i INT)

FRAGMENT BY EXPRESSION

(i < 100) IN dbs1, (i >= 100 AND i < 200) IN dbs2,

REMAINDER IN dbs3;

© 2010 IBM Corporation5

List Fragmentation Strategy

Fragments data based on a list of discrete values:

– States in a country or departments in an organization.

© 2010 IBM Corporation6

List FragmentationCREATE TABLE customer(id SERIAL, fname CHAR(32), lname CHAR(32), state Char(2), phone CHAR(12))FRAGMENT BY LIST (state) PARTITION p0 VALUES ("KS", "IL") IN dbs0, PARTITION p1 VALUES ("CA", "OR") IN dbs1, PARTITION p2 VALUES ("NY", "MN") IN dbs2, PARTITION p3 VALUES (NULL) IN dbs3, PARTITION p4 REMAINDER IN dbs3;

The table is fragmented on the column “state” – also known as the fragment or partitioning key.

The fragment key can be a column expression:– FRAGMENT BY LIST (SUBSTR(phone, 1, 3))

The fragment key expression can have multiple columns:

– FRAGMENT BY LIST (fname[1,1] || lname[1,1])

© 2010 IBM Corporation7

List FragmentationCREATE TABLE customer(id SERIAL, fname CHAR(32), lname CHAR(32), state CHAR(2) , phone CHAR(12))FRAGMENT BY LIST (state) PARTITION p0 VALUES ("KS", "IL") IN dbs0, PARTITION p1 VALUES ("CA", "OR") IN dbs1, PARTITION p2 VALUES ("NY", "MN") IN dbs2, PARTITION p3 VALUES (NULL) IN dbs3, PARTITION p4 REMAINDER IN dbs3;

The fragments do not overlap - no duplicates in the list values:

– For example, the following is not allowed PARTITION p0 VALUES ("KS", "IL") IN dbs0, PARTITION p1 VALUES ("CA", "KS") IN dbs1,

– The following is also not allowed PARTITION p0 VALUES ("KS", "IL“, "KS") IN dbs0,

The list values must be constant literals:– For example, the following is not allowed

PARTITION p0 VALUES (name, "KS", "IL“) IN dbs0,

© 2010 IBM Corporation8

List Fragmentation Strategy - Summary

Helps in the logical segregation of the data.

Useful when a table has finite set of values for the fragment key and queries on table have equality predicate on the fragment key.

Both the table and the index can be fragmented using this strategy.

The fragment key can be an column expression and can contain multiple columns.

Fragments cannot overlap.

Remainder, Null fragments are allowed.

© 2010 IBM Corporation9

Interval Fragmentation Strategy

Fragments data based on an interval value:

– For example, a fragment for every month or every million customer records.

Tables have an initial set of fragments defined by a range expression.

When a row is inserted that does not fit in the initial range of fragments, IDS will automatically create a fragment to hold the row (no DBA intervention).

© 2010 IBM Corporation10

Interval Fragmentation - Example CREATE TABLE employee (id INTEGER, name CHAR(32), basepay DECIMAL (10,2), varpay DECIMAL (10,2), dept CHAR(2), hiredate DATE) FRAGMENT BY RANGE (id) INTERVAL (100) STORE IN (dbs1, dbs2, dbs3, dbs4) PARTITION p0 VALUES IS NULL IN dbs0, PARTITION p1 VALUES < 200 IN dbs1, PARTITION p2 VALUES < 400 IN dbs2;

– The fragment or partitioning key for interval fragmentation can have only a single column. For example, the following is not allowed:• FRAGMENT BY RANGE (basepay + varpay)

– The fragment key can be a column expression:• FRAGMENT BY RANGE ((ROUND(basepay))

– The fragment key must be numeric, DATE or DATETIME data type:• Fragment key “id” in example is a INTEGER data type (numeric)

© 2010 IBM Corporation11

SQL Functions to Specify Interval Values NUMTOYMINTERVAL( <NUMBER>, {"YEAR"|"MONTH"]})

TO_YMINTERVAL( <NUMBER>, {"YEAR"|"MONTH"} )

– NUMTOYMINTERVAL(1, "YEAR") = INTERVAL (1-0) YEAR TO MONTH

– NUMTOYMINTERVAL(1.5, "YEAR") = INTERVAL (1-6) YEAR TO MONTH

_____________________________________________________________________________________________________

NUMTODSINTERVAL( <NUMBER>, {"DAY" | "HOUR" | "MINUTE" | "SECOND"})

TO_DSINTERVAL( <NUMBER>, {"DAY" | "HOUR" | "MINUTE" | "SECOND"})

NUMTODSINTERVAL(1.5, "DAY") = INTERVAL (1 12:00:00) DAY TO SECOND

NUMTODSINTERVAL(1.5, "HOUR") = INTERVAL (0 01:30:00) DAY TO SECOND

NUMTODSINTERVAL(1.5, "MINUTE") = INTERVAL (0 00:01:30) DAY TO SECOND

© 2010 IBM Corporation12

SQL Functions to Specify Interval Values (cont'd)

TO_YMINTERVAL("YY-mm");

TO_YMINTERVAL("01-00") = INTERVAL (1-0) YEAR TO MONTH

TO_YMINTERVAL("00-01’) = INTERVAL (0-1) YEAR TO MONTH

TO_YMINTERVAL("01-06") = INTERVAL (1-6) YEAR TO MONTH

_____________________________________________________________________________________________________

TO_DSINTERVAL("DD HH:MM:SS")

TO_DSINTERVAL("1 12:00:00") = INTERVAL (1 12:00:00) DAY TO SECOND

TO_DSINTERVAL("0 01:30:00") = INTERVAL (0 01:30:00) DAY TO SECOND

TO_DSINTERVAL("0 00:01:30") = INTERVAL (0 00:01:30) DAY TO SECOND

© 2010 IBM Corporation13

SQL Functions

CREATE TABLE orders (order_id INT, cust_id INT, order_date DATE, order_desc CHAR (1024) FRAGMENT BY RANGE (order_date) INTERVAL (NUMTOYMINTERVAL (1.5,’YEAR’)) STORE IN (dbs1, dbs2, dbs3) PARTITION p0 VALUES < DATE (‘01/01/2004’) IN dbs0, PARTITION p1 VALUES < DATE (‘01/01/2006’) IN dbs1,

PARTITION p2 VALUES < DATE (‘01/01/2008’) IN dbs2, PARTITION p3 VALUES < DATE (‘01/01/2010’) IN dbs3;

© 2010 IBM Corporation14

Interval Fragmentation Strategy

© 2010 IBM Corporation15

Interval Fragmentation Strategy - Summary

Useful when DBA does not want to pre-allocate fragments for data that is not yet there.

Both table and index can be fragmented using this strategy.

Only single column expressions for fragment keys.

Only numeric, DATE or DATETIME types for fragment key column.

The interval value supports only a non-zero positive numeric or INTERVAL constant literal expression.

© 2010 IBM Corporation16

Questions?

© 2010 IBM CorporationSeptember 9, 2010

OAT - List / Interval Fragmentation Strategies

© 2010 IBM Corporation18

Fragment by List and Interval (1)

You can specify a fragmentation strategy by using the OAT Schema Manager plug-in.

On the OAT menu, expandSQL ToolBox > Schema Manager.

These fragmentation strategies provide additional ways to control how data is stored on disk.

© 2010 IBM Corporation19

Fragment by List and Interval (2)

Select a database. Then on the Actions menu, click Create Table.

The first two pages of the Create Table Wizard guide you through defining the columns and the primary, foreign, and unique keys.

© 2010 IBM Corporation20

Fragment by List and Interval (3)

On page 3 of the wizard, you can define the fragmentation strategy for the table.

© 2010 IBM Corporation21

Fragment by List

Specify the values

Specify the fragment key column

Select the dbspaces

Specify the null and

remainder partitions

OAT generates the SQL

for the table

Fragment the data based on a list of discrete values; for example, states in a country.

© 2010 IBM Corporation22

Fragment by Interval

In OAT, fragment by interval is separated into two options:

• Date-range fragmentation: for DATE and DATETIME columns.

• Range fragmentation: for numeric columns.

For ease of use in either strategy:

• You specify only one predefined partition and the interval.

• When a row is inserted that does not match the range of any existing fragment, the database server creates a fragment based on the specified interval.

© 2010 IBM Corporation23

Fragment by Date Range

Specify the start date for

automatic fragmentation

Specify the interval in days, months, or years

Specify thefragment key

column

Specify the dbspaces

Specify null partition

OAT generates the SQL

Fragment the data based on a date interval.

© 2010 IBM Corporation24

Questions?

© 2010 IBM CorporationSeptember 9, 2010

Fragmentation – ALTER FRAGMENT Support List and Interval Strategies

© 2010 IBM Corporation26

ALTER FRAGMENT

Statement to change the distribution strategy or the storage location of an existing table or index.

Supports the following tasks:

– INIT

– ADD

– ATTACH

– DROP

– DETACH

– MODIFY

© 2010 IBM Corporation27

ALTER FRAGMENT – INIT (1)

Defines and initializes a fragmentation strategy on a table:

– Convert an interval or list fragmented table/index to any other type of fragmentation.

– Convert any type of fragmented table/index to an interval or list fragmented table/index.

– Convert a non-fragmented table/index to interval or list fragmented table/index.

– Convert interval or list fragmented table/index to a non-fragmented table/index.

© 2010 IBM Corporation28

ALTER FRAGMENT – INIT (2)

Defines and initializes a fragmentation strategy on a table (cont’d):

– Move the table to another set of dbspaces.

– Change the order of evaluation of fragment expressions (only supported with list fragmentation strategy).

– Change the partitioning key or fragment key.

– Change the interval value (for interval fragmentation strategy only).

– Table and indexes are rebuilt from scratch.

© 2010 IBM Corporation29

ALTER FRAGMENT – INIT exampleCREATE TABLE customer

(id SERIAL, fname CHAR(32), lname CHAR(32), state CHAR(2) , phone CHAR(12));

ALTER FRAGMENT ON TABLE customer INIT

FRAGMENT BY RANGE (id)

INTERVAL (1000) STORE IN (dbs1, dbs2, dbs3, dbs4)

PARTITION p0 VALUES < 2000 IN dbs0;

ALTER FRAGMENT ON TABLE customer INIT

FRAGMENT BY LIST (state)

PARTITION p0 VALUES ("KS", "IL") IN dbs0,

PARTITION p1 VALUES ("CA", "OR") IN dbs0,

PARTITION p2 REMAINDER IN dbs1;

ALTER FRAGMENT ON TABLE customer INIT

FRAGMENT BY ROUND ROBIN IN dbs0, dbs1, dbs2;

© 2010 IBM Corporation30

ALTER FRAGMENT - ADD

Add a fragment to interval or list fragmented table/index:

– Resulting table should not have any overlaps.

– For interval fragmentation, fragments can be added only below the transition value. Above the transition value, fragments are created automatically when rows are inserted with values > transition value.

– For list fragmentation, one can use BEFORE and AFTER clause to specify the placement position for new fragment:

• If the BEFORE/AFTER clause is not specified, the new fragment is added at the end or just before remainder fragment, if one exists.

– Addition of fragment can cause data to move from existing fragments to the newly added fragment. Only affected fragments are scanned and data moved.

© 2010 IBM Corporation31

ALTER FRAGMENT - ADD Add dbspace to list of dbspaces for interval fragments:

– Add dbspace to STORE IN list.

© 2010 IBM Corporation32

ALTER FRAGMENT – ADD exampleCREATE TABLE customer (id SERIAL, fname CHAR(32), lname CHAR(32), state

CHAR(2), ...)FRAGMENT BY LIST (state) PARTITION p0 VALUES ("KS", "IL") IN dbs0, PARTITION p1 VALUES ("CA", "OR") IN dbs1;

ALTER FRAGMENT ON TABLE customer ADD PARTITION p2 VALUES ("NY", "MN") IN dbs2 BEFORE p1;

ALTER FRAGMENT ON TABLE customer ADD PARTITION p3 REMAINDER IN dbs2;

CREATE TABLE employee (id INTEGER, name CHAR(32), ...)FRAGMENT BY RANGE (id) INTERVAL (100) STORE IN (dbs1, dbs2) PARTITION p1 VALUES < 200 IN dbs1, PARTITION p2 VALUES < 400 IN dbs2; transition fragment

ALTER FRAGMENT ON TABLE employee ADD PARTITION p3 VALUES IS NULL IN dbs1;

ALTER FRAGMENT ON TABLE employee ADD PARTITION p4 VALUES <300 in dbs3;ALTER FRAGMENT ON TABLE employee ADD INTERVAL STORE IN (dbs3, dbs4);

© 2010 IBM Corporation33

ALTER FRAGMENT – ATTACH (1) Provides a way to load large amounts of data

incrementally into an existing table.

Use to combine tables that have identical structures into a single table:

– Resulting table should not have any overlaps.

– For interval fragmentation, fragments can be attached below and above the transition value:• You can attach fragments to the initial range portion or the interval

portion.

– The consumed table has to be non-fragmented. The surviving table has to be fragmented.

– Similar to ADD, one can use BEFORE and AFTER clause to specify the placement position for the fragment being attached (list fragmentation only).

© 2010 IBM Corporation34

ALTER FRAGMENT – ATTACH (2)

– Attaching a fragment can cause data to move from a consumed table to other fragments of the surviving table.

– If a REMAINDER fragment is present, data can move from that fragment to the consumed table fragment. Only affected fragments are scanned and data moved:• If check constraint exists on the consumed table that exactly

matches the fragment expression being attached and there are no remainder fragments, there is no data movement.

– An attach operation can reuse the existing indexes and avoid rebuilds, if the indexes are fragmented the same as the table or with the same set of fragment expressions as the table.

© 2010 IBM Corporation35

ALTER FRAGMENT – ATTACH exampleCREATE TABLE customer (id INTEGER, fname CHAR(32), lname CHAR(32),

state CHAR(2), ...)

FRAGMENT BY LIST (state)

PARTITION p0 VALUES ("KS", "IL") IN dbs0,

PARTITION p1 VALUES ("CA", "OR") IN dbs1;

CREATE TABLE customer2 (id INTEGER, fname CHAR(32), lname CHAR(32), state CHAR(2), ...)[

ALTER FRAGMENT ON TABLE customer ATTACH customer2 AS PARTITION p2 VALUES ("NY", "MN") AFTER p1;

ALTER FRAGMENT ON TABLE customer ATTACH customer2 AS PARTITION pn VALUES (NULL) BEFORE p0;

ALTER FRAGMENT ON TABLE customer ATTACH customer2 AS PARTITION p3 VALUES ("TX");

ALTER FRAGMENT ON TABLE customer ATTACH customer2 AS PARTITION pr REMAINDER;

© 2010 IBM Corporation36

ALTER FRAGMENT - DROP

Drop a fragment from an interval or list fragmented table/index:

– Cannot drop a fragment containing data that cannot be moved to another fragment

• For interval fragmentation, you cannot drop an interval fragment unless its empty.

– You can drop a fragment even if the table has only two fragments provided it meets the previous criteria

• The resultant table is a fragmented table. Both interval and list fragmentation supports single fragment tables/indexes.

• For interval fragmentation, the resultant table must have at least one range fragment.

– Dropping a fragment can cause data to move from fragment being dropped to other fragments in a table. Only affected fragments are scanned and data moved.

© 2010 IBM Corporation37

ALTER FRAGMENT - DROP Drop dbspace from list of dbspaces for interval fragments:

– Drop dbspace from STORE IN list.

© 2010 IBM Corporation38

ALTER FRAGMENT – DROP example

CREATE TABLE customer (id SERIAL, fname CHAR(32), lname CHAR(32), state CHAR(2), ...)

FRAGMENT BY LIST (state)

PARTITION pn VALUES (NULL) in dbs3,

PARTITION p0 VALUES ("KS", "IL") IN dbs0,

PARTITION p1 VALUES ("CA", "OR") IN dbs1,

PARTITION p2 REMAINDER IN dbs3;

ALTER FRAGMENT ON TABLE customer DROP PARTITION p1;

ALTER FRAGMENT ON TABLE customer DROP PARTITION pn;

© 2010 IBM Corporation39

ALTER FRAGMENT – DROP exampleCREATE TABLE employee (id INTEGER, name CHAR(32), ...)FRAGMENT BY RANGE (id) INTERVAL (100) STORE IN (dbs1, dbs2, dbs3, dbs4) PARTITION p1 VALUES < 200 IN dbs1, PARTITION p2 VALUES < 400 IN dbs2; transition fragment

INSERT INTO employee VALUES(401, "Susan", ...);INSERT INTO employee VALUES(501, "Robert", ...);INSERT INTO employee VALUES(801, "David", ...);

Fragments in employee tablep1 VALUES < 200p2 VALUES < 400 transition fragment

sys_p2 VALUES >= 400 AND VALUES < 500sys_p3 VALUES >= 500 AND VALUES < 600sys_p6 VALUES >= 800 AND VALUES < 900

DELETE FROM employee where id = 401;

ALTER FRAGMENT ON TABLE employee DROP PARTITION p2; ALTER FRAGMENT ON TABLE employee DROP PARTITION sys_p3;ALTER FRAGMENT ON TABLE employee DROP INTERVAL STORE IN (dbs1, dbs3);

© 2010 IBM Corporation40

ALTER FRAGMENT - DETACH Provides a way to delete a segment of table data

rapidly.

Use to detach a table fragment from a distribution scheme and place the contents into a new non-fragmented table:– Detaching a fragment from a two fragment interval or list

table/index does not make the surviving table non-fragmented• Both interval and list fragmentation supports single fragment

tables/indexes.• For interval fragmentation, the resultant table must have at least

one range fragment.

– Detaching a fragment does not cause data to move but indexes will be rebuilt if they are detached (not fragmented same as table).

© 2010 IBM Corporation41

ALTER FRAGMENT – DETACH example

CREATE TABLE customer (id SERIAL, fname CHAR(32), lname CHAR(32), state CHAR(2), ...)

FRAGMENT BY LIST (state)

PARTITION pn VALUES (NULL) in dbs3,

PARTITION p0 VALUES ("KS", "IL") IN dbs0,

PARTITION p1 VALUES ("CA", "OR") IN dbs1,

PARTITION p2 REMAINDER IN dbs3;

ALTER FRAGMENT ON TABLE customer DETACH PARTITION p1 customer2;

ALTER FRAGMENT ON TABLE customer DETACH PARTITION pn customer3;

© 2010 IBM Corporation42

ALTER FRAGMENT – DETACH example

CREATE TABLE employee (id INTEGER, name CHAR(32), ...)

FRAGMENT BY RANGE (id)

INTERVAL (100) STORE IN (dbs1, dbs2, dbs3, dbs4)

PARTITION p1 VALUES < 200 IN dbs1,

PARTITION p2 VALUES < 400 IN dbs2; transition fragment

INSERT INTO employee VALUES(401, "Susan", ...);INSERT INTO employee VALUES(501, "Robert", ...);INSERT INTO employee VALUES(801, "David", ...);

Fragments in employee table

p1 VALUES < 200

p2 VALUES < 400 transition fragment

sys_p2 VALUES >= 400 AND VALUES < 500

sys_p3 VALUES >= 500 AND VALUES < 600

sys_p6 VALUES >= 800 AND VALUES < 900

ALTER FRAGMENT ON TABLE employee DETACH PARTITION p1 employee2;

ALTER FRAGMENT ON TABLE employee DETACH PARTITION sys_p3 employee3;

© 2010 IBM Corporation43

ALTER FRAGMENT – MODIFY (1) You can enable/disable automatic creation of interval

fragments:

ALTER FRAGMENT ON TABLE tab MODIFY INTERVAL ENABLED;

ALTER FRAGMENT ON TABLE tab MODIFY INTERVAL DISABLED;

Modify the dbspace list for interval fragments

– Replace an old STORE IN dbspace list with a new one:

ALTER FRAGMENT ON TABLE tab MODIFY INTERVAL DISABLED STORE IN (dbs1, dbs2);

– Existing fragments in the old dbspace will not be moved.

© 2010 IBM Corporation44

ALTER FRAGMENT – MODIFY (2)

Modify a fragment of an interval or list fragmented table or index:

– Rename a fragment or partition.

– Relocate a fragment from one dbspace to a different dbspace.

– Modify fragment expression• Resultant table should not have any overlaps. • Data movement possible.• For interval fragmentation

– First and intermediate range fragments expressions can be modified but new expression should not cross adjacent fragment boundaries.

– Last range fragment or transition fragment can be modified to increase the transition value only.

– Interval fragment expression cannot be modified.

© 2010 IBM Corporation45

ALTER FRAGMENT – MODIFY ExampleCREATE TABLE customer (id SERIAL, fname CHAR(32), lname CHAR(32), state

CHAR(2), ...)FRAGMENT BY LIST (state) PARTITION pn VALUES (NULL) in dbs3, PARTITION p0 VALUES ("KS", "IL") IN dbs0, PARTITION p1 VALUES ("CA", "OR") IN dbs1, PARTITION p2 REMAINDER IN dbs3;

ALTER FRAGMENT ON TABLE customer MODIFY PARTITION p1 TO PARTITION newp1, PARTITION p2 TO PARTITION newp2;

ALTER FRAGMENT ON TABLE customer MODIFY PARTITION p1 TO PARTITION newp1 IN dbs2, PARTITION p2 TO PARTITION p2 IN dbs6;

ALTER FRAGMENT ON TABLE customer MODIFY PARTITION p1 TO PARTITION p1 VALUES (“CA", “OR", “WA") IN dbs1;

ALTER FRAGMENT ON TABLE customer MODIFY PARTITION pn TO PARTITION pn VALUES (“TX“) IN dbs2;

© 2010 IBM Corporation46

Questions?

© 2010 IBM CorporationSeptember 9, 2010

Fragmentation – Interval FragmentationALTER FRAGMENT ONLINE Support

© 2010 IBM Corporation48

ALTER FRAGMENT ONLINE

The following operations can be performed ONLINE for interval fragmentation:

– ATTACH of interval fragment.

– DETACH of interval fragment.

– MODIFY interval transition value.

Using the above options, fragments of a table can be rolled-on and rolled-off ONLINE (without X-lock).

Operation is performed in the background.

Table cannot be exclusively locked at the time of the operation commencement.

ALTER FRAGMENT ONLINE FOR TABLE allows range interval fragmentation only.

© 2010 IBM Corporation49

Example – Table Schema

Table schema that will be used in the rest of the presentation:

CREATE TABLE orders (order_id INT, cust_id INT, order_date DATE, …)

FRAGMENT BY RANGE (order_date)

INTERVAL (1 UNITS YEAR) STORE IN (dbs1, dbs2, dbs3, dbs4)

PARTITION p0 VALUES < DATE (‘01/01/2005’) IN dbs0;

INSERT INTO orders VALUES (1001, 106, ’04/15/2005’, …);

INSERT INTO orders VALUES (1102, 135, ’06/19/2006’, …);

INSERT INTO orders VALUES (1148, 122, ’10/23/2007’, …);

INSERT INTO orders VALUES (1190, 108, ’02/22/2008’, …);

INSERT INTO orders VALUES (1202, 142, ’12/15/2008’, …);

INSERT INTO orders VALUES (1510, 127, ’03/12/2009’, …);

INSERT INTO orders VALUES (1611, 108, ’08/10/2009’, …);

© 2010 IBM Corporation50

Table Fragments

Fragments of the ‘orders’ table (the sys_p* fragments below automatically created after the inserts of the previous slide)

p0 < 01/01/2005 - range fragment (also the transition fragment)

sys_p1 >= 01/01/2005 AND < 01/01/2006 - interval fragment – yr 2005

sys_p2 >= 01/01/2006 AND < 01/01/2007 - interval fragment – yr 2006

sys_p3 >= 01/01/2007 AND < 01/01/2008 - interval fragment – yr 2007

sys_p4 >= 01/01/2008 AND < 01/01/2009 - interval fragment – yr 2008

sys_p5 >= 01/01/2009 AND < 01/01/2010 - interval fragment – yr 2009

© 2010 IBM Corporation51

ALTER FRAGMENT ONLINE syntax

>>-ALTER FRAGMENT ---+--------+-----ON-----------------------------> '-ONLINE-'    (1)    >--+-TABLE--surviving_table--+-| ATTACH Clause |-------------+-+-><   | | (2) | |      | +-| DETACH Clause |-------------+ |      | | (3) | |      | +-| INIT Clause |---------------+ |      | | (4) | |      | +-| ADD Clause |----------------+ |      | | (5) (6) | |      | '-----+-| DROP Clause |-------+-' |      | | (7) | |      | '-| MODIFY Clause |-----' |      | (5) (3) |      '-------INDEX--surviving_index--+-| INIT Clause |-------+---'       | (4) |        +-| ADD Clause |--------+        | (6) |        +-| DROP Clause |-------+        | (7) |        '-| MODIFY Clause |-----'    

© 2010 IBM Corporation52

ALTER FRAGMENT ONLINE – ATTACH (Roll-on) Rules (1)

Surviving table must be range interval fragmented.

Consumed table must be non-fragmented.– There is an exclusive lock on this table during the ONLINE ATTACH

operation.

Can attach interval fragments only.

If surviving table has indexes, they must be attached indexes:– i.e. fragmented same as table.

Only 1 table to be consumed may be specified within the syntax.

© 2010 IBM Corporation53

ALTER FRAGMENT ONLINE – ATTACH (Roll-on) Rules (2) For each index on the surviving table, there must be a

matching index on the consumed table:– Example: the index is on same set of columns and if

surviving table’s index is unique, then corresponding index on consumed table must be unique.

The indexes on consumed table must be detached and created in same dbspace as the table.

No data movement is allowed: – Data in the consumed table must match the expression being

attached. – Enforced by a check constraint on the consumed table.

© 2010 IBM Corporation54

ALTER FRAGMENT ONLINE – ATTACH Fragments before attach

p0 < 01/01/2005 - range fragment (also the transition fragment) sys_p1 >= 01/01/2005 AND < 01/01/2006 - interval fragment – yr 2005

sys_p2 >= 01/01/2006 AND < 01/01/2007 - interval fragment – yr 2006

sys_p3 >= 01/01/2007 AND < 01/01/2008 - interval fragment – yr 2007

sys_p4 >= 01/01/2008 AND < 01/01/2009 - interval fragment – yr 2008

sys_p5 >= 01/01/2009 AND < 01/01/2010 - interval fragment – yr 2009

CREATE TABLE orders2010 (order_id INT, cust_id INT, order_date DATE, …,

CHECK (order_date >= DATE('01/01/2010') AND

order_date < DATE('01/01/2011')));

ALTER FRAGMENT ONLINE ON TABLE orders ATTACH orders2010 AS

PARTITION p6 VALUES < DATE(‘01/01/2011’);

Fragments after attach

p0 < 01/01/2005 - range fragment (also the transition fragment)

sys_p1 >= 01/01/2005 AND < 01/01/2006 - interval fragment – yr 2005

sys_p2 >= 01/01/2006 AND < 01/01/2007 - interval fragment – yr 2006

sys_p3 >= 01/01/2007 AND < 01/01/2008 - interval fragment – yr 2007

sys_p4 >= 01/01/2008 AND < 01/01/2009 - interval fragment – yr 2008

sys_p5 >= 01/01/2009 AND < 01/01/2010 - interval fragment – yr 2009

p6 >= 01/01/2010 AND < 01/01/2011 - interval fragment – yr 2010

© 2010 IBM Corporation55

ALTER FRAGMENT ONLINE – DETACH (Roll-Off)

Surviving table must be range interval fragmented.

If surviving table has indexes, they must be attached indexes i.e. fragmented same as table.

Can detach IDS auto generated interval fragments above the initial user defined range only:

– Range fragments initially defined by the user cannot be detached online.

If there are sessions accessing the fragment being detached, it is recommended that user set lock mode to wait to prevent non-exclusive access errors:– The server will wait for the specified amount of time for

concurrent sessions to exit the partition. – New sessions will be disallowed on the fragment being

detached.

© 2010 IBM Corporation56

ALTER FRAGMENT ONLINE – DETACH Fragments before detach

p0 < 01/01/2005 - range fragment (also the transition fragment)

sys_p1 >= 01/01/2005 AND < 01/01/2006 - interval fragment – yr 2005

sys_p2 >= 01/01/2006 AND < 01/01/2007 - interval fragment – yr 2006

sys_p3 >= 01/01/2007 AND < 01/01/2008 - interval fragment – yr 2007

sys_p4 >= 01/01/2008 AND < 01/01/2009 - interval fragment – yr 2008

sys_p5 >= 01/01/2009 AND < 01/01/2010 - interval fragment – yr 2009

p6 >= 01/01/2010 AND < 01/01/2011 - interval fragment – yr 2010

ALTER FRAGMENT ONLINE ON TABLE orders DETACH PARTITION sys_p1 orders2005;

Fragments after detach

p0 < 01/01/2005 - range fragment (also the transition fragment)

sys_p2 >= 01/01/2006 AND < 01/01/2007 - interval fragment – yr 2006

sys_p3 >= 01/01/2007 AND < 01/01/2008 - interval fragment – yr 2007

sys_p4 >= 01/01/2008 AND < 01/01/2009 - interval fragment – yr 2008

sys_p5 >= 01/01/2009 AND < 01/01/2010 - interval fragment – yr 2009

p6 >= 01/01/2010 AND < 01/01/2011 - interval fragment – yr 2010

© 2010 IBM Corporation57

ALTER FRAGMENT ONLINE - MODIFY

Surviving table must be range interval fragmented.

Only the transition value can be modified online:

– The starting value for interval fragments.

Background operation if no initial errors.

Intent Exclusive Lock held on the table during the operation.

© 2010 IBM Corporation58

ALTER FRAGMENT ONLINE – MODIFY

Fragments before modify

p0 < 01/01/2005 - range fragment (also the transition fragment)

sys_p2 >= 01/01/2006 AND < 01/01/2007 - interval fragment – yr 2006

sys_p3 >= 01/01/2007 AND < 01/01/2008 - interval fragment – yr 2007

sys_p4 >= 01/01/2008 AND < 01/01/2009 - interval fragment – yr 2008

sys_p5 >= 01/01/2009 AND < 01/01/2010 - interval fragment – yr 2009

p6 >= 01/01/2010 AND < 01/01/2011 - interval fragment – yr 2010

ALTER FRAGMENT ONLINE ON TABLE orders MODIFY INTERVAL TRANSITION TO ‘01/01/2006’;

Fragments after modify

p0 < 01/01/2006 - range fragment (also the transition fragment)

sys_p2 >= 01/01/2006 AND < 01/01/2007 - interval fragment – yr 2006

sys_p3 >= 01/01/2007 AND < 01/01/2008 - interval fragment – yr 2007

sys_p4 >= 01/01/2008 AND < 01/01/2009 - interval fragment – yr 2008

sys_p5 >= 01/01/2009 AND < 01/01/2010 - interval fragment – yr 2009

p6 >= 01/01/2010 AND < 01/01/2011 - interval fragment – yr 2010

© 2010 IBM Corporation59

Questions?

© 2010 IBM CorporationSeptember 9, 2010

Scott Pickett – WW IDS Technical SalesFor questions about this presentation contact: [email protected]

© 2010 IBM Corporation61

Logo

© 2010 IBM Corporation62

Logo

© 2010 IBM Corporation63