Using DB2 For Linux, Windows, and UNIX Table Partitioning in SAP Systems
Using DB2 For Linux, Windows, and UNIX Table Partitioning in SAP Systems
Applies to:
SAP NetWeaver AS ABAP on IBM DB2 for Linux, UNIX, and Windows. For more information, visit the
Landscape Design and Architecture homepage.
Summary
Most database systems offer specific “data organization schemes” that can be used to influence the physical
representation of the table data on disk. DB2 for Linux, UNIX, and Windows offers three such schemes:
Database Partitioning (DPF), Multi-Dimensional Clustering (MDC) and – since DB2 9.1 – table partitioning.
This article explains how you can apply table partitioning for tables in an SAP system.
Author Bio
Johannes Heinrich works as a senior developer in the IBM DB2 for Linux, UNIX, and Windows development
team at SAP. He holds a degree in Computer Science from the University of Kaiserslautern, Germany and is
a IBM Certified DBA for DB2 9 on Linux, UNIX, and Windows.
He can be reached at johannes.heinrich@sap.com .
Table of Contents
Introduction ................................................................................................................................................... 3
Table Partitioning with DB2 for Linux, UNIX, and Windows ............................................................................ 4
Table Partitioning Functionality .................................................................................................................. 4
Syntax Considerations ............................................................................................................................... 5
Catalog Views for Table Partitioning .......................................................................................................... 6
Use of Table Partitioning in SAP Systems ..................................................................................................... 7
Range-Partitioned Tables and the SAP Data Dictionary ............................................................................. 7
Creating Range-Partitioned Tables in the ABAP DDIC ............................................................................... 7
Table Partitioning Examples ...................................................................................................................... 9
Tablespace Considerations ..................................................................................................................... 12
Limitations ............................................................................................................................................... 13
Reverting to a Nonpartitioned Table ......................................................................................................... 13
Combining Table Partitioning with other Data Organization Schemes....................................................... 14
Other Ways for Creating Range-Partitioned Tables .................................................................................. 15
Related Content .......................................................................................................................................... 16
Appendix A: Report to fill the CUSTOMERS table with random data ............................................................ 17
Copyright .................................................................................................................................................... 19
Introduction
Recent database systems use special techniques to improve the performance of SQL statements and
ensure scalability when working with (very) large databases. One of the ideas behind these techniques is it
to store the database data in a way so that a fast access even on large tables can be achieved. Storing the
data in such an optimized way becomes especially important in data warehouse environments like SAP
NetWeaver BW.
DB2 for Linux, UNIX, and Windows offers the following three data organization schemes to optimize data
access in large databases:
The Database Partitioning Feature (DPF), aimed primarily at large data warehouse installations,
allows the partitioning of the database into multiple partitions. Table data is distributed to different
partitions based on a distribution key. Partitions can reside on the same server (shared everything),
utilizing the multi-processor capabilities of that server, or spawn different machines (shared nothing).
As DB2‟s optimizer is DPF-aware, the primary advantage of this setup is that the incoming workload
can be processed in parallel by all partitions, each working on their own set of data. This can speed
up the execution of SQL statements tremendously. DPF is often used with SAP NetWeaver BW.
Multi-Dimensional Clustering (MDC) is a way of physically clustering table data. MDC uses blocks,
consisting of a consecutive set of disk pages, and block indexes for fast block access. The data is
organized along an ordered set of one or more columns, the so called dimensions. All records which
share the same dimension value are stored in at least one block. The primary advantage of MDC is
the improved performance of data warehouse-like queries along the dimensions. MDC is also often
used with SAP NetWeaver BW on DB2 for Linux, UNIX, and Windows.
Table partitioning, also known as range partitioning, is a new feature of DB2 V9.1. Here, a (large)
table is split into (data) partitions (also known as ranges) based on a partitioning key. Every partition
constitutes an own storage object and can be detached from (roll-out) or attached to (roll-in) the table
with minimal effort. Again, query performance may improve because DB2 only scans partitions that
are relevant to the query (data partition elimination).
Currently, SAP applications do not use range-partitioned tables. This article discusses how tables of the SAP
database can be optionally partitioned after the SAP system installation. For more information about the
other data organization schemes (DPF and MDC), see the articles on the “SAP Business Intelligence with
IBM DB2 for LUW” page in the SAP Developer Network (SDN).
Syntax Considerations
Table partitions are defined in the partitioning-clause of the CREATE TABLE statement. Since the table
partitioning syntax is rather complex and has many options, we start with the following basic example.
The partitioning-clause starts in line (1) with the keywords PARTITIONG BY RANGE (RANGE is optional and
can be omitted). The following term in braces is the so called partition expression. In our example, the
partitioning of table sales is based on the values in the sales_date column.
Note: In most cases you might want to use a time-based column type like DATE, TYPE and TIMESTAMP as partition
expression. Table partitions are often organized along years, months, weeks or something similar.
Optionally you can specify after every column in the partition expression where records that contain an SQL
NULL value in this field are stored. NULLS LAST (this is the default) means that these records belong to the
last (highest) partition, NULLS FIRST means that they belong to the first (lowest) partition. A partition
expression can consist of up to 16 columns.
After the partition expression the single partitions must be specified. Following the PART (or PARTITION)
keyword you can specify a name for each partition. If you do not specify a name DB2 will generate a name
automatically (PART0, PART1, PART2 ...). Next you need to indicate the boundaries of every partition.
Assuming that the table above contains only data from the year 2005, the table is partitioned into the four
quarters of 2005. You can use the keywords INCLUSIVE and EXCLUSIVE to specify that the boundary
values should be included in or excluded from the respective data partition.
The second example (below) shows that the upper boundary of a partition (the ending-clause) can be left
out. In this case DB2 automatically calculates the upper partition boundary. Also, you can use the keywords
MINVALUE (see line (1)) and MAXVALUE to define open-ended partitions. In our example, all records in the
sales table that have a sale_date lower than 1/1/2005 are stored in the first partition.
The example also shows that you can omit partition names.
The next example shows how you can map the partitions to different tablespaces.
Here, the regular table data, the indexes and the large object data (assuming there are long- or LOB-
columns in table sale_date) are stored in a separate tablespace for each partition. Partition 1, for example,
uses tablespace rpartd1 for its regular data, tablespace rparti1 for its local indexes and tablespace rpartl1 for
its large object data. To place a global index in a specific tablespace, you can use the INDEX IN addition of
the CREATE INDEX statement that has been available since DB2 V9.1.
All the examples above use the so called long form for the definition of the partitions. There is also a short
form where DB2 itself calculates the partition boundaries if the partition expression consists of a date, a time-
based or a numerical column. This is shown in our next example:
CREATE TABLE sales(sale_date DATE, customer INT, …)
PARTITION BY RANGE(sale_date)
(STARTING MINVALUE ENDING ’1/1/2005’,
STARTING ‘1/1/2005’ ENDING ’12/31/2005’ EVERY 3 MONTHS)
Again the table data is partitioned into the four quarters of 2005. Besides EVERY <constant> MONTHS you
can use EVERY <constant> YEARS, DAYS, HOURS, MINUTES and so on. This way you can create many
partitions with just a few lines in the CREATE TABLE statement.
You can find a good overview about the various table partition options up to DB2 V9.5 in “Table Partitioning
and Large Tablespaces in DB2 VIPER”.
Note: At the time of writing, the dictionary of the AS Java (the Java DDIC) does not support range-partitioned tables.
Problems can occur if the structure of a range-partitioned table is changed and if database specific parameters are
used.
1
Note that DB2 supports more structure changes with the ALTER TABLE command, but the other changes
place the table in a REORG_PENDING state that can currently not be handled by the ABAP data dictionary.
You can use the simple ABAP report ZJOFILLCUSTOMERS from appendix A to fill the CUSTOMER table
with some data.
Note: Before you perform these steps on a real application table in a production system you should test it with an
(empty) copy of the table.
Note: If the conversion fails, you can correct the syntax of the storage parameters and continue with the conversion.
Note: The procedure above describes how to run a conversion in dialog mode. For large tables that contain a lot of
records you need to run the conversion in batch mode (see Scheduling Jobs for Mass Processing in the SAP
Library). During the conversion the table is not accessible for applications. For an alternative procedure where the
table remains accessible to applications see section “Other Ways for Creating Range-Partitioned Tables”.
Note: The date and time types of the ABAP DDIC (DATS and TIMS) are mapped to VARCHAR on the database.
Therefore, the short syntax form of the partitioning clause (e.g. ...EVERY 3 MONTHS...) cannot be used here. To
perform a monthly partitioning of a table with a DATS field you could use for example the following partition clause:
If you entered the partitioning clause in correct syntax, you should see the message “Request for
CUSTOMERS executed successfully” in the status bar. To see the CREATE TABLE statement that was
actually assembled by the ABAP DDIC, go to the data dictionary (SAP transaction SE11), enter the table
name and F7 and choose Utilities → Activation Log from the menu. If you expand the log (F5) you can see
all statements that were generated during the conversion.
Another way to check is to go to SE14 again and look at the storage parameters of the table. This will now
look as follows on a system with DB2 9.7:
Storage
|
|-- Table
| |
| |-----TABLESPACE DD6#STABD
| |-----INDEXSPACE DD6#STABD
| |-----LONGSPACE DD6#STABD
| |-----LOCKSIZE ROW
| |-----OPTIONS PARTITION BY RANGE
| |-----OPTIONS (
| |-----OPTIONS POSTCODE
| |-----OPTIONS )
| |-----OPTIONS (
| |-----OPTIONS PARTITION "PLZ0"
| |-----OPTIONS STARTING(MINVALUE)
| |-----OPTIONS INCLUSIVE
| |-----OPTIONS ENDING(10000)
| |-----OPTIONS EXCLUSIVE
| |-----OPTIONS IN "DD6#STABD"
| |-----OPTIONS INDEX IN "DD6#STABD"
| |-----OPTIONS LONG IN "DD6#STABD",
| |-----OPTIONS PARTITION "PLZ1"
| |-----OPTIONS STARTING(10000)
| |-----OPTIONS INCLUSIVE
| |-----OPTIONS ENDING(20000)
| |-----OPTIONS EXCLUSIVE
| |-----OPTIONS IN "DD6#STABD"
| |-----OPTIONS INDEX IN "DD6#STABD"
| |-----OPTIONS LONG IN "DD6#STABD",
...
| |-----OPTIONS PARTITION "PLZ9"
| |-----OPTIONS STARTING(90000)
| |-----OPTIONS INCLUSIVE
| |-----OPTIONS ENDING(MAXVALUE)
| |-----OPTIONS INCLUSIVE
| |-----OPTIONS IN "DD6#STABD"
| |-----OPTIONS INDEX IN "DD6#STABD"
| |-----OPTIONS LONG IN "DD6#STABD"
| ------OPTIONS )
Note: The ABAP DDIC always reconstructs the full syntax of the partition clause. In the example above, a shorter syntax
was used that did not specify the end of the ranges (as already mentioned, in this case the end of the ranges is
automatically calculated by DB2). In the result shown in SE14 after the conversion, the start and the end of each
range is explicitly specified.
Here is another example which uses multiple partition expressions and different tablespaces for the
partitions:
Note: All tablespaces mentioned in the storage parameters must belong to the same database partition group.
Tablespace Considerations
To circumvent the problem that the CREATE TABLE template in the ABAP DDIC requires values in the
tablespace-clauses, tablespace setting for partitioned tables are handled as follows.
In the CREATE TABLESPACE statement the same tablespace settings as for nonpartitioned tables (derived
from the data class) are maintained. This means that even all partitioned tables are defined with the ...IN
<data-tbsp> INDEX IN <index-tbsp> LONG IN <long-tbsp> clause. However, these settings are overwritten
in the definition of the partitions of the CREATE TABLE statement and/or in the CREATE INDEX statement.
For the data and long tablespaces this is achieved by including the ..IN <data_tbsp> and LONG IN
<long_tbsp> clause in the definition of every partition.
In the example above, tablespace DD6#STABD is initially defined as the tablespace for the regular and the
large object data. However, this is overwritten so that partition PLZlower uses the tablespaces DD6#RD1
and DD6#RL1 and PLZupper uses DD6#RD2 and DD6#RL2. After the conversion, the tablespace settings of
the first partition are used to fill the tablespace options of the CRETE TABLE statement. You can see this
also in the example above, the storage parameter list shows that DD6#RD1, DD6#RI1 and DD6#RL1 are
used as TABLESPACE, INDEXSPACE and LONGSPACE.
Regarding the index tablespaces, we must distinguish between global and local indexes. The tablespace
placement of global indexes is defined in the CREATE INDEX statement in the <IN tablespace> clause. This,
again, overwrites the INDEX IN clause of the CREATE TABLE statement. The following is an example how
the storage parameters of a global index are displayed in SAP transaction SE14:
For local indexes, available with DB2 9.7, the INDEX IN clause in every partition definition is used to define
in which tablespace every local index is placed. In the example above, the local indexes of partition
PLZlower are placed in tablespace DD6#RI1 and the local indexes of partition PLZupper are placed in
DD6#RI2. If the SAP system runs on DB2 9.7, the ABAP DDIC checks for every index of a partitioned table if
it is local or global. If it is global, the …NOT PARTITIONED… clause is automatically generated for the
CREATE INDEX statement.
Limitations
The OPTIONS mechanism in SAP transaction SE14 has a shortcoming: an OPTION line can contain only up
to 79 characters. Therefore, the following additional limitations apply for range-partitioned tables in SAP
systems:
Every partition expression (“POSTCODE” in the example above) can only grow up to 79 characters.
Note that the partition expression can be followed by a NULLS FIRST and a comma (in case of
multiple partition expressions) on the same line.
The name of a partition can only grow up to 67 characters.
The definition of the start value of a partition can have a maximum of 68 characters.
The definition of the end value of a partition can have a maximum of 70 characters.
The name of a tablespace is restricted in general in all SAP system by 30 characters.
Note: Exceeding one of these limits results in the error message “Error when determining storage parameters” in the
ABAP DDIC log.
Storage
|
|-- Table
| |
| |-----TABLESPACE DD6#RD1
| |-----INDEXSPACE DD6#RI1
| |-----LONGSPACE DD6#RL1
| |-----LOCKSIZE ROW
| |-----OPTIONS ORGANIZE BY DIMENSIONS (
| |-----OPTIONS "NAME" ,
| |-----OPTIONS "POSTCODE"
| |-----OPTIONS )
| |-----OPTIONS PARTITION BY RANGE
| |-----OPTIONS (
| |-----OPTIONS POSTCODE NULLS FIRST,
| |-----OPTIONS DISCOUNT
| |-----OPTIONS )
| |-----OPTIONS (
| |-----OPTIONS PARTITION "PLZLOWER"
| |-----OPTIONS STARTING(0,'0')
| |-----OPTIONS INCLUSIVE
| |-----OPTIONS ENDING(49999,'999')
| |-----OPTIONS INCLUSIVE
| |-----OPTIONS IN "DD6#RD1"
| |-----OPTIONS INDEX IN "DD6#RI1"
| |-----OPTIONS LONG IN "DD6#RL1",
| |-----OPTIONS PARTITION "PLZUPPER"
| |-----OPTIONS STARTING(50000,'0')
| |-----OPTIONS INCLUSIVE
| |-----OPTIONS ENDING(99999,'999')
| |-----OPTIONS INCLUSIVE
| |-----OPTIONS IN "DD6#RD2"
| |-----OPTIONS INDEX IN "DD6#RI2"
| |-----OPTIONS LONG IN "DD6#RL2"
| |-----OPTIONS )
| ------OPTIONS COMPRESS YES
Related Content
SDN Page SAP on DB2 for Linux, UNIX, and Windows
SDN Page SAP Business Intelligence with IBM DB2 for LUW
IBM Presentation Table Partitioning and Large Tablespaces in DB2 VIPER
IBM Redbook Database Partitioning, Table Partitioning, and MDC for DB2 9
For more information, visit the Landscape Design and Architecture homepage.
IF ( del_data EQ 'X' ).
CALL FUNCTION 'DB_TRUNCATE_TABLE'
EXPORTING
tabname = 'CUSTOMERS'.
ENDIF.
DO num_recs TIMES.
wa_custentry-id = wa_custentry-id + 1.
counter = counter + 1.
wa_custentry-postcode = rand_num.
IF ( rand_num < 5 ).
wa_custentry-custtype = 'B'.
ELSE.
wa_custentry-custtype = 'P'.
ENDIF.
ENDDO.
Copyright
© Copyright 2009 SAP AG. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG.
The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9,
iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Serv er,
PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes,
BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX,
Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems
Incorporated in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of
Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts
Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by
Netscape.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned
herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and
other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered
trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.
All other product and service names mentioned are the trademarks of their respective companies. Data contained in this docume nt
serves informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("S AP
Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or
omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the
express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an
additional warranty.