Skip to content

Commit

Permalink
Merge pull request #203 from wenki96/main
Browse files Browse the repository at this point in the history
[Hotfix] fix foreign key table meta
  • Loading branch information
zhiliyao-polarx authored Mar 19, 2024
2 parents 5a15e22 + f0784fa commit f92bf20
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ protected Map<String, Map<String, List<Pair<Integer, List<Object>>>>> getShardRe
String schemaName,
String tableName,
TableMeta tableMeta,
TableMeta refTableMeta,
TableMeta parentTableMeta,
List<List<Object>> values,
PhysicalPlanBuilder builder,
List<String> selectKeys,
Expand All @@ -1080,7 +1080,7 @@ protected Map<String, Map<String, List<Pair<Integer, List<Object>>>>> getShardRe
List<String> 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);
}
Expand All @@ -1094,12 +1094,14 @@ protected Map<String, Map<String, List<Pair<Integer, List<Object>>>>> 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);
Expand Down Expand Up @@ -1184,7 +1186,7 @@ protected void beforeUpdateFkCheck(TableModify tableModify, String schemaName, S
builder, null,
true, false);

List<String> sortedColumns = getSortedColumns(true, parentTableMeta, data.getValue());
List<String> sortedColumns = getSortedColumns(true, tableMeta, data.getValue());

List<List<Object>> selectValues = getSelectValues(executionContext, schemaName,
parentTableMeta, updateValueList, tableModify, memoryAllocator, builder, shardResults,
Expand Down Expand Up @@ -1260,7 +1262,7 @@ protected void beforeUpdateFkCascade(TableModify tableModify, String schemaName,
null, false);

Map<String, Map<String, List<Pair<Integer, List<Object>>>>> selectShardResults =
getShardResults(data.getValue(), schemaName, tableName, tableMeta, refTableMeta,
getShardResults(data.getValue(), schemaName, tableName, refTableMeta, tableMeta,
shardConditionValueList, builder,
null,
false, false);
Expand Down Expand Up @@ -1397,11 +1399,11 @@ protected void beforeDeleteFkCascade(LogicalModify logicalModify, String schemaN
Map<String, Map<String, List<Pair<Integer, List<Object>>>>> 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<String> sortedColumns = getSortedColumns(false, tableMeta, data.getValue());
List<String> sortedColumns = getSortedColumns(false, refTableMeta, data.getValue());

List<List<Object>> selectValues = getSelectValues(executionContext, schemaName,
refTableMeta, conditionValueList, logicalModify, memoryAllocator, builder, shardResults,
Expand Down

0 comments on commit f92bf20

Please sign in to comment.