From f130e25fea694fb28cad9e5afb33cbecd388a8c9 Mon Sep 17 00:00:00 2001 From: "wuwenqi.wwq" Date: Thu, 19 Sep 2024 16:32:49 +0800 Subject: [PATCH] 5.4.19-20240919 fix --- .../executor/handler/HandlerCommon.java | 35 +++++++++++++++---- .../mysql/handler/LogicalInsertHandler.java | 4 +-- .../optimizer/utils/ForeignKeyUtils.java | 2 +- .../com/alibaba/polardbx/cdc/CdcManager.java | 6 ++++ .../auto/basecrud/ForeignKeyCascadeTest.java | 10 ++++++ .../basecrud/ForeignKeyCascadeTest.java | 10 ++++++ .../qatest/util/ConnectionManager.java | 4 +++ .../statistics/dump/mergeindexV2.yml | 0 pom.xml | 2 +- 9 files changed, 63 insertions(+), 10 deletions(-) delete mode 100644 polardbx-test/src/test/resources/statistics/dump/mergeindexV2.yml diff --git a/polardbx-executor/src/main/java/com/alibaba/polardbx/executor/handler/HandlerCommon.java b/polardbx-executor/src/main/java/com/alibaba/polardbx/executor/handler/HandlerCommon.java index ef12f1973..e60b1f4f4 100644 --- a/polardbx-executor/src/main/java/com/alibaba/polardbx/executor/handler/HandlerCommon.java +++ b/polardbx-executor/src/main/java/com/alibaba/polardbx/executor/handler/HandlerCommon.java @@ -1096,6 +1096,23 @@ protected List getSortedColumns(boolean isFront, TableMeta tableMeta, Fo return sortedColumns; } + protected List getUpdateSortedColumns(TableMeta tableMeta, ForeignKeyData data, + List updateColumns) { + Map columnMap = + IntStream.range(0, data.columns.size()).collect(TreeMaps::caseInsensitiveMap, + (m, i) -> m.put(data.columns.get(i), data.refColumns.get(i)), Map::putAll); + + List sortedColumns = new ArrayList<>(); + tableMeta.getAllColumns().forEach(c -> { + if (data.columns.stream().anyMatch(c.getName()::equalsIgnoreCase) && + updateColumns.stream().anyMatch(c.getName()::equalsIgnoreCase)) { + sortedColumns.add(columnMap.get(c.getName())); + } + }); + + return sortedColumns; + } + protected Map>>>> getShardResults(ForeignKeyData data, String schemaName, String tableName, @@ -1104,12 +1121,17 @@ protected Map>>>> getShardRe List> values, PhysicalPlanBuilder builder, List selectKeys, + List updateColumns, boolean isFront, - boolean isInsert) { + boolean isInsert, + boolean isUpdateCheck) { List columns = isInsert ? selectKeys : isFront ? data.refColumns : data.columns; List sortedColumns; - if (!isInsert) { + if (isUpdateCheck) { + sortedColumns = getUpdateSortedColumns(tableMeta, data, updateColumns); + columns = sortedColumns; + } else if (!isInsert) { sortedColumns = isFront ? getSortedColumns(true, tableMeta, data) : getSortedColumns(false, parentTableMeta, data); } else { @@ -1216,9 +1238,10 @@ protected void beforeUpdateFkCheck(TableModify tableModify, String schemaName, S Map>>>> shardResults = getShardResults(data.getValue(), schemaName, tableName, tableMeta, parentTableMeta, updateValueList, builder, null, - true, false); + tableModify.getUpdateColumnList(), true, false, true); - List sortedColumns = getSortedColumns(true, tableMeta, data.getValue()); + List sortedColumns = + getUpdateSortedColumns(tableMeta, data.getValue(), tableModify.getUpdateColumnList()); ExecutionContext selectEc = executionContext.copy(); selectEc.setParams(new Parameters(selectEc.getParams().getCurrentParameter(), false)); @@ -1315,7 +1338,7 @@ protected void beforeUpdateFkCascade(TableModify tableModify, String schemaName, getShardResults(data.getValue(), schemaName, tableName, refTableMeta, tableMeta, shardConditionValueList, builder, null, - false, false); + null, false, false, false); columnMap = IntStream.range(0, data.getValue().columns.size()).collect(TreeMaps::caseInsensitiveMap, (m, i) -> m.put(data.getValue().refColumns.get(i), data.getValue().columns.get(i)), @@ -1454,7 +1477,7 @@ protected void beforeDeleteFkCascade(TableModify logicalModify, String schemaNam executionContext, false) : getShardResults(data.getValue(), schemaName, tableName, refTableMeta, tableMeta, conditionValueList, builder, null, - false, false); + null, false, false, false); List sortedColumns = getSortedColumns(false, tableMeta, data.getValue()); diff --git a/polardbx-executor/src/main/java/com/alibaba/polardbx/repo/mysql/handler/LogicalInsertHandler.java b/polardbx-executor/src/main/java/com/alibaba/polardbx/repo/mysql/handler/LogicalInsertHandler.java index c931e4df8..966084bfd 100644 --- a/polardbx-executor/src/main/java/com/alibaba/polardbx/repo/mysql/handler/LogicalInsertHandler.java +++ b/polardbx-executor/src/main/java/com/alibaba/polardbx/repo/mysql/handler/LogicalInsertHandler.java @@ -428,7 +428,7 @@ protected void beforeInsertFkCheck(LogicalInsert logicalInsert, String targetTab Map>>>> shardResults = getShardResults(data.getValue(), schemaName, tableName, tableMeta, parentTableMeta, conditionValueList, - builder, sortedColumns, true, true); + builder, sortedColumns, null, true, true, false); conditionValueList = conditionValueList.stream().distinct().collect(Collectors.toList()); @@ -519,7 +519,7 @@ protected List> beforeInsertFkCheckIgnore(Logical Map>>>> shardResults = getShardResults(data.getValue(), schemaName, tableName, tableMeta, parentTableMeta, conditionValueList, - builder, sortedColumns, true, true); + builder, sortedColumns, null, true, true, false); List> selectValues = getSelectValues(selectEc, schemaName, parentTableMeta, conditionValueList, logicalInsert, memoryAllocator, builder, shardResults, diff --git a/polardbx-optimizer/src/main/java/com/alibaba/polardbx/optimizer/utils/ForeignKeyUtils.java b/polardbx-optimizer/src/main/java/com/alibaba/polardbx/optimizer/utils/ForeignKeyUtils.java index 2a7406a8e..81b4f0df2 100644 --- a/polardbx-optimizer/src/main/java/com/alibaba/polardbx/optimizer/utils/ForeignKeyUtils.java +++ b/polardbx-optimizer/src/main/java/com/alibaba/polardbx/optimizer/utils/ForeignKeyUtils.java @@ -456,7 +456,7 @@ public static List> getUpdateValueList(ForeignKeyData data, List row : values) { List updateValue = new ArrayList<>(); for (Integer colIndex : refColIndex) { diff --git a/polardbx-server/src/main/java/com/alibaba/polardbx/cdc/CdcManager.java b/polardbx-server/src/main/java/com/alibaba/polardbx/cdc/CdcManager.java index ed22d2d82..f23e3a0f6 100644 --- a/polardbx-server/src/main/java/com/alibaba/polardbx/cdc/CdcManager.java +++ b/polardbx-server/src/main/java/com/alibaba/polardbx/cdc/CdcManager.java @@ -453,6 +453,12 @@ private boolean checkDdl(String schemaName, String ddlSql, CdcDDLContext cdcDDLC return false; } + // 针对mysql系统库,过滤 + if (StringUtils.equalsIgnoreCase(schemaName, "mysql") && StringUtils.equalsIgnoreCase("DROP_DATABASE", + sqlKind.toString())) { + return false; + } + return true; } diff --git a/polardbx-test/src/test/java/com/alibaba/polardbx/qatest/dml/auto/basecrud/ForeignKeyCascadeTest.java b/polardbx-test/src/test/java/com/alibaba/polardbx/qatest/dml/auto/basecrud/ForeignKeyCascadeTest.java index 7c8dd4938..81df0a2fd 100644 --- a/polardbx-test/src/test/java/com/alibaba/polardbx/qatest/dml/auto/basecrud/ForeignKeyCascadeTest.java +++ b/polardbx-test/src/test/java/com/alibaba/polardbx/qatest/dml/auto/basecrud/ForeignKeyCascadeTest.java @@ -771,6 +771,11 @@ public void testFkUpdateCascade() throws SQLException { JdbcUtil.executeQuerySuccess(tddlConnection, String.format("select * from %s", tableName3)); Assert.assertTrue(rs.next()); assertEquals(rs.getLong(3), 9); + + // update one column on child table + sql = String.format("update %s set c = 9 where b = 7", tableName3); + JdbcUtil.executeUpdateSuccess(tddlConnection, hint + sql); + break; case "RESTRICT": case "NO ACTION": @@ -863,6 +868,11 @@ public void testFkUpdateCascade() throws SQLException { // update one of referenced columns sql = String.format("update %s set b = 9 where c = 3", tableName1); JdbcUtil.executeUpdateFailed(tddlConnection, hint + sql, ""); + + // update one column on child table + sql = String.format("update %s set b = 2 where c = 1", tableName3); + JdbcUtil.executeUpdateSuccess(tddlConnection, hint + sql); + break; case "SET NULL": diff --git a/polardbx-test/src/test/java/com/alibaba/polardbx/qatest/dml/sharding/basecrud/ForeignKeyCascadeTest.java b/polardbx-test/src/test/java/com/alibaba/polardbx/qatest/dml/sharding/basecrud/ForeignKeyCascadeTest.java index d0f0a63bf..8fefbd615 100644 --- a/polardbx-test/src/test/java/com/alibaba/polardbx/qatest/dml/sharding/basecrud/ForeignKeyCascadeTest.java +++ b/polardbx-test/src/test/java/com/alibaba/polardbx/qatest/dml/sharding/basecrud/ForeignKeyCascadeTest.java @@ -759,6 +759,11 @@ public void testFkUpdateCascade() throws SQLException { JdbcUtil.executeQuerySuccess(tddlConnection, String.format("select * from %s", tableName3)); Assert.assertTrue(rs.next()); assertEquals(rs.getLong(3), 9); + + // update one column on child table + sql = String.format("update %s set c = 9 where b = 7", tableName3); + JdbcUtil.executeUpdateSuccess(tddlConnection, hint + sql); + break; case "RESTRICT": case "NO ACTION": @@ -851,6 +856,11 @@ public void testFkUpdateCascade() throws SQLException { // update one of referenced columns sql = String.format("update %s set b = 9 where c = 3", tableName1); JdbcUtil.executeUpdateFailed(tddlConnection, hint + sql, ""); + + // update one column on child table + sql = String.format("update %s set b = 2 where c = 1", tableName3); + JdbcUtil.executeUpdateSuccess(tddlConnection, hint + sql); + break; case "SET NULL": diff --git a/polardbx-test/src/test/java/com/alibaba/polardbx/qatest/util/ConnectionManager.java b/polardbx-test/src/test/java/com/alibaba/polardbx/qatest/util/ConnectionManager.java index a147a8eb7..b508e1357 100644 --- a/polardbx-test/src/test/java/com/alibaba/polardbx/qatest/util/ConnectionManager.java +++ b/polardbx-test/src/test/java/com/alibaba/polardbx/qatest/util/ConnectionManager.java @@ -21,6 +21,7 @@ import com.alibaba.polardbx.gms.util.JdbcUtil; import com.alibaba.polardbx.gms.util.PasswdUtil; import com.alibaba.polardbx.qatest.constant.ConfigConstant; +import com.alibaba.polardbx.qatest.privileges.encdb.EncdbTestBase; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assert; @@ -208,6 +209,9 @@ private void init() { //ignore } + //remove encdb jdbc8 driver + EncdbTestBase.cleanJDBC8Driver(); + } catch (Throwable t) { log.error(this.toString(), t); throw new RuntimeException(t); diff --git a/polardbx-test/src/test/resources/statistics/dump/mergeindexV2.yml b/polardbx-test/src/test/resources/statistics/dump/mergeindexV2.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/pom.xml b/pom.xml index 9f90d76d7..b70150ea7 100644 --- a/pom.xml +++ b/pom.xml @@ -159,7 +159,7 @@ 2.7 1.6 30.1.1-jre - 1.2.67 + 1.2.83 1.2.8 3.1 2.0.2