IDEMPIERE-5943 Implement table partitioning support (#2151)

* IDEMPIERE-5943 Implement table partitioning support

* - make it compatible with user preference Use Similar To
This commit is contained in:
Carlos Ruiz 2023-12-20 23:41:11 +01:00 committed by GitHub
parent 7878721bf3
commit 3f912767a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 13 deletions

View File

@ -25,7 +25,7 @@ INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,Cr
;
-- Dec 4, 2023, 3:53:10 PM MYT
INSERT INTO AD_Reference (AD_Reference_ID,Name,ValidationType,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,EntityType,IsOrderByValue,AD_Reference_UU,ShowInactive) VALUES (200261,'AD_Table PartitioningMethod','L',0,0,'Y',TO_TIMESTAMP('2023-12-04 15:53:09','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-12-04 15:53:09','YYYY-MM-DD HH24:MI:SS'),100,'D','N','81b6431b-0afa-49bc-b5fe-be9a7b2481cf','N')
INSERT INTO AD_Reference (AD_Reference_ID,Name,ValidationType,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,EntityType,IsOrderByValue,AD_Reference_UU,ShowInactive) VALUES (200261,'AD_Column PartitioningMethod','L',0,0,'Y',TO_TIMESTAMP('2023-12-04 15:53:09','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-12-04 15:53:09','YYYY-MM-DD HH24:MI:SS'),100,'D','N','81b6431b-0afa-49bc-b5fe-be9a7b2481cf','N')
;
-- Dec 4, 2023, 3:53:22 PM MYT

View File

@ -31,6 +31,7 @@ import java.util.StringTokenizer;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.DBException;
import org.compiere.db.DB_PostgreSQL;
import org.compiere.db.partition.ITablePartitionService;
import org.compiere.db.partition.RangePartitionColumn;
import org.compiere.db.partition.RangePartitionInterval;
@ -457,8 +458,8 @@ public class TablePartitionService implements ITablePartitionService {
if (partition != null)
{
StringBuilder createStmt = new StringBuilder();
createStmt.append("CREATE TABLE " + partition.getName() + " (LIKE ");
createStmt.append(getDefaultPartitionName(table) + " INCLUDING ALL)");
createStmt.append("CREATE TABLE ").append(partition.getName()).append(" (").append(DB_PostgreSQL.NATIVE_MARKER).append("LIKE ");
createStmt.append(getDefaultPartitionName(table)).append(" INCLUDING ALL)");
int no = DB.executeUpdateEx(createStmt.toString(), trxName);
if (pi != null)
pi.addLog(0, null, null, no + " " + createStmt.toString());
@ -472,7 +473,7 @@ public class TablePartitionService implements ITablePartitionService {
updateStmt.append("TO_DATE(").append(rangePartitionInterval.getFrom()).append(",'yyyy-MM-dd') ");
else
updateStmt.append(rangePartitionInterval.getFrom()).append(" ");
updateStmt.append("AND " + partitionKeyColumn.getColumnName()).append(" < ");
updateStmt.append("AND ").append(partitionKeyColumn.getColumnName()).append(" < ");
if (DisplayType.isDate(partitionKeyColumn.getAD_Reference_ID()) || DisplayType.isTimestampWithTimeZone(partitionKeyColumn.getAD_Reference_ID()))
updateStmt.append("TO_DATE(").append(rangePartitionInterval.getTo()).append(",'yyyy-MM-dd') ");
else
@ -486,8 +487,8 @@ public class TablePartitionService implements ITablePartitionService {
pi.addLog(0, null, null, no + " " + updateStmt.toString());
StringBuilder alterStmt = new StringBuilder();
alterStmt.append("ALTER TABLE " + table.getTableName() + " ");
alterStmt.append("ATTACH PARTITION " + partition.getName() + " " + partition.getExpressionPartition());
alterStmt.append("ALTER TABLE ").append(table.getTableName()).append(" ");
alterStmt.append("ATTACH PARTITION ").append(partition.getName()).append(" ").append(partition.getExpressionPartition());
no = DB.executeUpdateEx(alterStmt.toString(), trxName);
if (pi != null)
pi.addLog(0, null, null, no + " " + alterStmt.toString());
@ -545,8 +546,8 @@ public class TablePartitionService implements ITablePartitionService {
Object value = columnValues.get(partition.getName());
StringBuilder createStmt = new StringBuilder();
createStmt.append("CREATE TABLE " + partition.getName() + " (LIKE ");
createStmt.append(getDefaultPartitionName(table) + " INCLUDING ALL)");
createStmt.append("CREATE TABLE ").append(partition.getName()).append(" (").append(DB_PostgreSQL.NATIVE_MARKER).append("LIKE ");
createStmt.append(getDefaultPartitionName(table)).append(" INCLUDING ALL)");
int no = DB.executeUpdateEx(createStmt.toString(), trxName);
if (pi != null)
pi.addLog(0, null, null, no + " " + createStmt.toString());
@ -571,8 +572,8 @@ public class TablePartitionService implements ITablePartitionService {
pi.addLog(0, null, null, no + " " + updateStmt.toString());
StringBuilder alterStmt = new StringBuilder();
alterStmt.append("ALTER TABLE " + table.getTableName() + " ");
alterStmt.append("ATTACH PARTITION " + partition.getName() + " " + partition.getExpressionPartition());
alterStmt.append("ALTER TABLE ").append(table.getTableName()).append(" ");
alterStmt.append("ATTACH PARTITION ").append(partition.getName()).append(" ").append(partition.getExpressionPartition());
no = DB.executeUpdateEx(alterStmt.toString(), trxName);
if (pi != null)
pi.addLog(0, null, null, no + " " + alterStmt.toString());
@ -585,7 +586,7 @@ public class TablePartitionService implements ITablePartitionService {
@Override
public boolean runPostPartitionProcess(MTable table, String trxName, ProcessInfo processInfo) {
StringBuilder stmt = new StringBuilder();
stmt.append("VACUUM ANALYZE " + table.getTableName());
stmt.append("VACUUM ANALYZE ").append(table.getTableName());
int no = DB.executeUpdateEx(stmt.toString(), trxName);
if (processInfo != null)
processInfo.addLog(0, null, null, no + " " + stmt.toString());

View File

@ -136,7 +136,7 @@ public class DB_PostgreSQL implements AdempiereDatabase
/** Logger */
private static final CLogger log = CLogger.getCLogger (DB_PostgreSQL.class);
private static final String NATIVE_MARKER = "NATIVE_"+Database.DB_POSTGRESQL+"_KEYWORK";
public static final String NATIVE_MARKER = "NATIVE_"+Database.DB_POSTGRESQL+"_KEYWORK";
private CCache<String, String> convertCache = new CCache<String, String>(null, "DB_PostgreSQL_Convert_Cache", 1000, CCache.DEFAULT_EXPIRE_MINUTE, false);

View File

@ -99,6 +99,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
statement = convertSysDate(statement);
statement = convertSimilarTo(statement);
statement = DB_PostgreSQL.removeNativeKeyworkMarker(statement);
} else {

View File

@ -420,9 +420,10 @@
<setEntry value="org.compiere.db.oracle.provider@default:default"/>
<setEntry value="org.compiere.db.postgresql.provider@default:default"/>
<setEntry value="org.idempiere.hazelcast.service@default:default"/>
<setEntry value="org.idempiere.tablepartition@default:default"/>
<setEntry value="org.idempiere.test@default:default"/>
<setEntry value="org.idempiere.webservices@default:default"/>
<setEntry value="org.idempiere.webservices.resources@default:default"/>
<setEntry value="org.idempiere.webservices@default:default"/>
<setEntry value="org.idempiere.zk.billboard.chart@default:default"/>
<setEntry value="org.idempiere.zk.billboard@default:default"/>
<setEntry value="org.idempiere.zk.extra@default:default"/>