Partiton RDBMS ( DB2 ) table data either by SQL query or Java

五迷三道 提交于 2020-01-17 07:31:27

问题


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.

来源:https://stackoverflow.com/questions/43269325/partiton-rdbms-db2-table-data-either-by-sql-query-or-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!