Skip to content

Commit

Permalink
Merge pull request #204 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 20, 2024
2 parents f92bf20 + 8e9937e commit 9545695
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ protected List<List<Object>> getConditionValueList(ForeignKeyData data, TableMet
return conditionValueList;
}

// when check front, tableMeta is child table, check back, tableMeta is parent table
protected List<String> getSortedColumns(boolean isFront, TableMeta tableMeta, ForeignKeyData data) {
Map<String, String> columnMap = isFront ?
IntStream.range(0, data.columns.size()).collect(TreeMaps::caseInsensitiveMap,
Expand Down Expand Up @@ -1167,6 +1168,7 @@ protected void beforeUpdateFkCheck(TableModify tableModify, String schemaName, S

PhysicalPlanBuilder builder = new PhysicalPlanBuilder(schemaName, executionContext);

// parent table
final TableMeta parentTableMeta = executionContext.getSchemaManager(schemaName).getTableWithNull(tableName);
if (parentTableMeta == null) {
throw new TddlRuntimeException(ErrorCode.ERR_ADD_UPDATE_FK_CONSTRAINT, schemaName, tableName,
Expand Down Expand Up @@ -1386,6 +1388,7 @@ protected void beforeDeleteFkCascade(LogicalModify logicalModify, String schemaN

PhysicalPlanBuilder builder = new PhysicalPlanBuilder(schemaName, executionContext);

// child table
final TableMeta refTableMeta = executionContext.getSchemaManager(schemaName).getTable(tableName);

// get select condition values
Expand All @@ -1403,7 +1406,7 @@ protected void beforeDeleteFkCascade(LogicalModify logicalModify, String schemaN
builder, null,
false, false);

List<String> sortedColumns = getSortedColumns(false, refTableMeta, data.getValue());
List<String> sortedColumns = getSortedColumns(false, tableMeta, data.getValue());

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

0 comments on commit 9545695

Please sign in to comment.