From 3f912767a36efed5059a97ed2574b04702d2b587 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 20 Dec 2023 23:41:11 +0100 Subject: [PATCH] IDEMPIERE-5943 Implement table partitioning support (#2151) * IDEMPIERE-5943 Implement table partitioning support * - make it compatible with user preference Use Similar To --- .../oracle/202312041549_IDEMPIERE-5943.sql | 2 +- .../partition/TablePartitionService.java | 21 ++++++++++--------- .../src/org/compiere/db/DB_PostgreSQL.java | 2 +- .../compiere/dbPort/Convert_PostgreSQL.java | 1 + .../idempiere.unit.test.parallel.launch | 3 ++- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/migration/iD11/oracle/202312041549_IDEMPIERE-5943.sql b/migration/iD11/oracle/202312041549_IDEMPIERE-5943.sql index 3727e0e9c9..7f25305b27 100644 --- a/migration/iD11/oracle/202312041549_IDEMPIERE-5943.sql +++ b/migration/iD11/oracle/202312041549_IDEMPIERE-5943.sql @@ -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 diff --git a/org.compiere.db.postgresql.provider/src/org/adempiere/db/postgresql/partition/TablePartitionService.java b/org.compiere.db.postgresql.provider/src/org/adempiere/db/postgresql/partition/TablePartitionService.java index 6591e5db76..52bca8f8b1 100644 --- a/org.compiere.db.postgresql.provider/src/org/adempiere/db/postgresql/partition/TablePartitionService.java +++ b/org.compiere.db.postgresql.provider/src/org/adempiere/db/postgresql/partition/TablePartitionService.java @@ -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()); diff --git a/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java b/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java index ffb7893336..e41300713a 100755 --- a/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java +++ b/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java @@ -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 convertCache = new CCache(null, "DB_PostgreSQL_Convert_Cache", 1000, CCache.DEFAULT_EXPIRE_MINUTE, false); diff --git a/org.compiere.db.postgresql.provider/src/org/compiere/dbPort/Convert_PostgreSQL.java b/org.compiere.db.postgresql.provider/src/org/compiere/dbPort/Convert_PostgreSQL.java index bbda66e0bd..d40ff07f88 100644 --- a/org.compiere.db.postgresql.provider/src/org/compiere/dbPort/Convert_PostgreSQL.java +++ b/org.compiere.db.postgresql.provider/src/org/compiere/dbPort/Convert_PostgreSQL.java @@ -99,6 +99,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 { statement = convertSysDate(statement); statement = convertSimilarTo(statement); + statement = DB_PostgreSQL.removeNativeKeyworkMarker(statement); } else { diff --git a/org.idempiere.test/idempiere.unit.test.parallel.launch b/org.idempiere.test/idempiere.unit.test.parallel.launch index f7a2ae53da..80694c766f 100644 --- a/org.idempiere.test/idempiere.unit.test.parallel.launch +++ b/org.idempiere.test/idempiere.unit.test.parallel.launch @@ -420,9 +420,10 @@ + - +