33
Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies. 1 DB2 Version 8 Partitioning Changes Phil Grainger, Computer Associates

DB2 Version 8 Partitioning Changes

  • Upload
    tomas

  • View
    33

  • Download
    0

Embed Size (px)

DESCRIPTION

DB2 Version 8 Partitioning Changes. Phil Grainger, Computer Associates. Disclaimer. This presentation has been written from documentation from IBM that existed in May 2003 and also takes some examples from early experiences with Version 8 itself - PowerPoint PPT Presentation

Citation preview

Page 1: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

1

DB2 Version 8Partitioning Changes

Phil Grainger, Computer Associates

Page 2: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Disclaimer

This presentation has been written from documentation from IBM that existed in May 2003 and also takes some examples from early experiences with Version 8 itself

Neither of these sources of information is guaranteed to be consistent with the final Generally Available version of Version 8

To quote IBM “this information will …..become progressively less correct as time goes by”!

And there are already changes in DB2 that differ from this presentation!

Page 3: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Disclaimer (2)

Also….

At the time this presentation was written, not all of the promised functionality had yet been delivered

So, some of the examples have NOT actually been tried against a real Version 8 subsystem

(And those that have been tried didn’t all work!)

Page 4: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Agenda

Increased Number of Partitions What is Table Based Partitioning? Data Partitioned Secondary Indexes Adding Partitions Rolling Partitions Questions?

Page 5: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Increased number of partitions

Now up to a potential maximum of 4,096 partitions

However, actual maximum depends on page size And also on DSSIZE

Page 6: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Increased number of partitions

DSSIZE 4K pages 8K pages 16K pages 32K pages1-4 Gb 4,096 4,096 4,096 4,0968Gb 2,048 4,096 4,096 4,09616Gb 1,024 2,048 4,096 4,09632Gb 512 1,024 2,048 4,09664Gb 256 512 1,024 2,048

Page 7: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Increased number of partitions

However, how does the VSAM cluster naming convention work?

A001-A999 for partitions 1-999 B000-B999 for partitions 1000-1999 C000-C999 for partitions 2000-2999 D000-D999 for partitions 3000-3999 E000-E096 for partitions 4000-4096

Page 8: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Increased number of partitions

Also be careful of the limit to the number of objects in a database….– Still 65,535

A 4,096 partition tablespace with LOB columns needs:– 4,096 tablespace objects– And (4,096 LOB tablespace, aux table and aux index =

12,288) objects per LOB column– So only room for FOUR LOB columns

NOT the FIVE that the IBM doc states – they seem to have forgotten the base tablespace objects

Page 9: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Table Based Partitioning

Before we can look at DPSIs, ROLLING and ADDing partitions

Version 8 introduced TABLE BASED PARTITIONING

What we had before was INDEX BASED PARTITIONING

Version 8 will support BOTH– But can almost invisibly switch form index-based to

table-based…..

Page 10: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Table Based Partitioning

A partitioned table NO LONGER needs a partitioning index

The table itself is defined as partitioned with the relevant key ranges– Note that the tablespace in which the table will reside

must also have the same number of partitions

CREATE TABLE table_name (col1, col2, col3),PATITION BY (col1, col2),( PART 1 VALUES (aaa,xxx),

PART n VALUES (yyy,zzz);

Page 11: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Table Based Partitioning

Notice also, that because partitioning does not use an index, CLUSTERing is not related to PARTITIONing any more

Conversion happens when ANY ALTER is issued that is valid for table based partitioning– ALTER INDEX NOT CLUSTER for the partitioning index

– ALTER TABLE ADD PART

– CREATE INDEX PARTITIONED

– Etc.

IBM suggest CREATE a PARTITIONED SECONDARY INDEX (DPSI) with the DEFINE NO, DEFER YES keywords– This does no work really and does not affect availability

And then DROP it

Page 12: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Table Based Partitioning

With INDEX BASED partitioning all secondary indexes could contain keys for any partition– This severely affects availability and operation of

utilities

With TABLE BASED partitioning secondary indexes can also be partitioned on the same keys– However they can NOT be UNIQUE…..

Page 13: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Table Based Partitioning

Time for some pictures……

Page 14: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

101

102

103

104

105

201

202

203

204

205

301

302

303

304

305

101

102

103

104

105

201

202

203

204

205

301

302

303

304

305

IL AK

AK

OR

IL AK

LA NV

IL OR

AK

IL NV

AK

TX

AK

AK

AK

AK

AK

IL IL IL IL LA

NV

NV

OR

OR

TX

102

103

201

301

304

101

105

204

302

202

203

303

104

205

305

Partitionedby customernumber

Thereforealso clusteredby customernumber

Secondaryindex onstate

Version 7 partitioned table

Page 15: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

101

102

103

104

105

201

202

203

204

205

301

302

303

304

305

IL AK

AK

OR

IL AK

LA NV

IL OR

AK

IL NV

AK

TX

Version 8 partitioned table

Still partitionedby customernumber, andclustered likewise

NOTENo partitioningindex

Page 16: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Version 8 partitioned table

Still partitionedby customernumber, nowclustered bystate!

102

103

101

105

104

201

204

202

203

205

301

304

302

303

305

AK

AK

IL IL OR

AK

IL LA NV

OR

AK

AK

IL NV

TX

NOTENo partitioningindex

To be clustered on state there must also be anIndex on state – this is omitted for clarity

Page 17: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Version 8 partitioned table

Still partitionedby customernumber, nowclustered bystate!

102

103

101

105

104

201

204

202

203

205

301

304

302

303

305

AK

AK

IL IL OR

AK

IL LA NV

OR

AK

AK

IL NV

TX

101

102

103

104

105

201

202

203

204

205

301

302

303

304

305

With apartitionedindex oncustomer

Any index that has the SAME columns in the SAMEsequence as the partitioning key is called a PARTITIONING

index. Partitioning indexes can be unique or non-unique

Page 18: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Version 8 partitioned table

Still partitionedby customernumber, nowclustered bystate!

102

103

101

105

104

201

204

202

203

205

301

304

302

303

305

AK

AK

IL IL OR

AK

IL LA NV

OR

AK

AK

IL NV

TX

101

102

103

104

105

201

202

203

204

205

301

302

303

304

305

With apartitionedindex oncustomer

AK

AK

IL IL OR

AK

IL LA

NV

OR

AK

AK

IL NV

TX

102

103

101

105

104

201

204

202

203

205

301

304

302

303

305

DPSI onstate,customer

Data Partitioned Secondary Indexes are physically partitioned in the same ranges as

the table, but MUST be non-unique

Page 19: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Version 8 partitioned table

Still partitionedby customernumber, nowclustered bystate!

102

103

101

105

104

201

204

202

203

205

301

304

302

303

305

AK

AK

IL IL OR

AK

IL LA NV

OR

AK

AK

IL NV

TX

101

102

103

104

105

201

202

203

204

205

301

302

303

304

305

With apartitionedindex oncustomer

If your secondary index has to be unique then itCANNOT be a DPSI – it’s a traditional NPI

TraditionalNPI

AK

AK

AK

AK

AK

IL IL IL IL LA

NV

NV

OR

OR

TX

102

103

201

301

304

101

105

204

302

202

203

303

104

205

305

Page 20: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Data Partitioned secondary indexes

A Data Partitioned Secondary Index (DPSI) then– Is an index on a partitioned table which is also physically

partitioned– It MUST be non-unique as potential duplicates could be in any

one of 4,095 other DPSI partitions– If you need a Unique secondary index then it can’t be partitioned– DPSIs may not be ideal for access paths requiring a sequential

index scan In our example, a SELECT of all customers in “AK” for example DB2 would have to scan ALL partitions of the DPSI, despite STATE

being the high order key column A traditional NPI would be better

Page 21: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Data Partitioned secondary indexes

On the other hand, DPSIs are great for utility concurrency

All utilities can run at partition level with no nasties like the NPI BUILD2 phase in V7

Page 22: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Adding Partitons

A partition can be added at the end of an existing partitioned table

But only up to the maximum number of partitions (see earlier)

The partition number itself is not specified– It is chosen by DB2

But the partition keys must, of course, be specified

Page 23: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Adding Partitions

For STOGROUP defined objects, DB2 will automatically define the relevant pagesets– For the tablespace and for all partitioned indexes– DB2 uses the allocation quantities for the immediately

preceding partition This is NOT on-line as the tablespace and

indexes must be STOPPED However as soon as the partition is added, it is

immediately available when the pagesets are restarted

Page 24: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Adding Partitions

All plans, packages and cached dynamic SQL statements are invalidated

Only ONE partition can be added in a single unit of work We now need to be aware of a VERY subtle difference

between LOGICAL parititon number and PHYSICAL partition number

LOGICAL refers to the partition number of the TABLE (effectively)

PHYSICAL refers to the Annn node of the pageset name

Page 25: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Adding Partitions

For example, if we start with a 10 partition table The table will have 10 partitions(!) The underlying tablespace will also have 10

partitions– They will be named A001 – A010

So far so good…..– But what happens when we MOVE partitions…?

Page 26: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Rolling Partitions

DB2 Version 8 also allows partition ROLLING This is where the partition that is currently the

“first” (the one with the lowest keys) is rolled to become the “last” (which will now contain the highest keys)

All rows will be deleted from the rolled partition– And all SYSCOPY & SYSLGRNX rows for it will be

purged Also, the new limit keys for the “new” partition will

be specified on the ROLL statement

Page 27: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Rolling Partitions

When we roll FIRST to LAST, we effectively remove the old first partition and what was the SECOND one now becomes the first

Remember, partition keys are only specified ONCE for each partition– We list the HIGHEST key that can reside in any

partition So, after ROLLING a row that would have been

placed into PART 1 will now be placed into PART 2 instead!

Page 28: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Rolling Partitions

Remember that logical vs physical bit a few pages back? Now we start with the same 10 partition table

– That has physical datasets A001 – A010

Now we “ROLL FIRST TO LAST”– Logically we still have partitions 1-10 (it’s just that the old part 2 is

now part 1 etc)– BUT DB2 doesn’t rename the pagsets– So logical partition 1 is now physical pageset A002– Logical partition 9 is now physical pageset A010– And logical partition 10 is physical pageset A001(!)

Page 29: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Rolling AND Adding

This is where it will get messy Start

– with Parts 1-10 (A001-A010)

Roll first to last – Now we have A002-A010 followed by A001

Add a partition– Now there’s A002-A010, then A001, finally A011

Got all that??? LOGICAL and PHYSICAL partition numbers are no longer

guaranteed to be the same….

Page 30: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

REORG enhancements

REORG can now be used to rebalance partitions The rows in the selected (or all) partitions will be

redistributed in equal measure across the partititons– Eg REORG TABLESPACE dbname.tsname PART 12:16

REBALANCE– Will rebalance partitions 12 through 16– However, this CANNOT be done as a SHRLEVEL CHANGE (on-

line) REORG– If the clustering key is NOT the partitioning key, REORG must be

run twice Once to rebalance and once to sort into clustering sequence within

partition!

Page 31: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

REORG Enhancements

There is no BUILD2 phase for DPSIs SHRLEVEL CHANGE and DISCARD can now be

specified together– BUT if any discarded rows are modified during the

reorg, then the reorganisation will abend

Page 32: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Phew

Any questions…..

Page 33: DB2 Version 8 Partitioning Changes

© 2003 Computer Associates International, Inc. (CA). All trademarks, trade names, services marks and logos referenced herein belong to their respective companies.

Bibliography

Keep up to date with the IBM web site Also the Version 8 Technical Preview (SG24-

6871)