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 e12bb8ba6..7aa569f30 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 @@ -1069,7 +1069,7 @@ protected Map>>>> getShardRe String schemaName, String tableName, TableMeta tableMeta, - TableMeta refTableMeta, + TableMeta parentTableMeta, List> values, PhysicalPlanBuilder builder, List selectKeys, @@ -1080,7 +1080,7 @@ protected Map>>>> getShardRe List sortedColumns; if (!isInsert) { sortedColumns = - isFront ? getSortedColumns(true, refTableMeta, data) : getSortedColumns(false, tableMeta, data); + isFront ? getSortedColumns(true, tableMeta, data) : getSortedColumns(false, parentTableMeta, data); } else { sortedColumns = new ArrayList<>(columns); } @@ -1094,12 +1094,14 @@ protected Map>>>> getShardRe final boolean singleOrBroadcast = Optional.ofNullable(oc.getRuleManager()).map(rule -> !rule.isShard(tableName)).orElse(true); + TableMeta currentTableMeta = isFront ? parentTableMeta : tableMeta; + boolean fullTableScan = - singleOrBroadcast || !GlobalIndexMeta.isEveryUkContainsTablePartitionKey(refTableMeta, tarCols); + singleOrBroadcast || !GlobalIndexMeta.isEveryUkContainsTablePartitionKey(currentTableMeta, tarCols); return fullTableScan ? - builder.getShardResultsFullTableScan(refTableMeta, values.size()) : - builder.getShardResults(refTableMeta, values, sortedColumns.stream() + builder.getShardResultsFullTableScan(currentTableMeta, values.size()) : + builder.getShardResults(currentTableMeta, values, sortedColumns.stream() .map(String::toUpperCase) .collect(Collectors.toList()), false); @@ -1184,7 +1186,7 @@ protected void beforeUpdateFkCheck(TableModify tableModify, String schemaName, S builder, null, true, false); - List sortedColumns = getSortedColumns(true, parentTableMeta, data.getValue()); + List sortedColumns = getSortedColumns(true, tableMeta, data.getValue()); List> selectValues = getSelectValues(executionContext, schemaName, parentTableMeta, updateValueList, tableModify, memoryAllocator, builder, shardResults, @@ -1260,7 +1262,7 @@ protected void beforeUpdateFkCascade(TableModify tableModify, String schemaName, null, false); Map>>>> selectShardResults = - getShardResults(data.getValue(), schemaName, tableName, tableMeta, refTableMeta, + getShardResults(data.getValue(), schemaName, tableName, refTableMeta, tableMeta, shardConditionValueList, builder, null, false, false); @@ -1397,11 +1399,11 @@ protected void beforeDeleteFkCascade(LogicalModify logicalModify, String schemaN Map>>>> shardResults = isBroadcast ? BuildPlanUtils.buildResultForBroadcastTable(schemaName, tableName, conditionValueList, null, executionContext, false) : - getShardResults(data.getValue(), schemaName, tableName, tableMeta, refTableMeta, conditionValueList, + getShardResults(data.getValue(), schemaName, tableName, refTableMeta, tableMeta, conditionValueList, builder, null, false, false); - List sortedColumns = getSortedColumns(false, tableMeta, data.getValue()); + List sortedColumns = getSortedColumns(false, refTableMeta, data.getValue()); List> selectValues = getSelectValues(executionContext, schemaName, refTableMeta, conditionValueList, logicalModify, memoryAllocator, builder, shardResults,