Partiton RDBMS ( DB2 ) table data either by SQL qu

2019-09-16 19:12发布

I have to implement a partitioning for the column data ( Column Name : ID ) for a very large database table ( DB2 ). Table has more than a billion rows and keeps growing.

Partitioning has to be implemented like illustrated here i.e. I have to calculate minId & maxId for a specified range.

ID column values are unique but not sequential so simple approach as illustrated in above link will not work - i.e. starting from an ID then keep adding range.

WITH ROWNUMTAB AS ( 
 SELECT ROWNUM, ID FROM ( 
   SELECT rownumber() over (order by ID) as ROWNUM, ID 
   FROM IDTABLE  
 ) 
 WHERE mod(ROWNUM,1000)=0 OR mod(ROWNUM,1000)=1  WITH UR  
)  
SELECT T1.ID AS MIN_ID  , T2.ID AS MAX_ID 
FROM ROWNUMTAB T1 
INNER JOIN ROWNUMTAB T2 
  ON T1.ROWNUM+999=T2.ROWNUM 
WITH UR;

This above query gives me MIN_ID,MAX_ID for a particular range - 1000.

This query works for small tables but for a very large table having few billion rows, assigning a row number to each row is not completing in realistic time.

Any alternate suggestions to achieve this kind of partitioning?

Challenge is described here too.

Reading all ID values into memory then doing Java manipulation is not a feasible option either.

Please suggest.

0条回答
登录 后发表回答