[branch-2.1] Picks "[fix](delete) Fix delete stmt on MOW table doesn't use partial update in Nereids planner #38751" (#39214)

## Proposed changes

picks https://github.com/apache/doris/pull/38751
This commit is contained in:
bobhan1
2024-08-12 17:02:48 +08:00
committed by GitHub
parent 01c39d73c2
commit c2044409da
27 changed files with 184 additions and 127 deletions

View File

@ -399,26 +399,32 @@ public class DeleteFromCommand extends Command implements ForwardWithSync, Expla
List<String> cols = Lists.newArrayList();
boolean isMow = targetTable.getEnableUniqueKeyMergeOnWrite();
String tableName = tableAlias != null ? tableAlias : targetTable.getName();
boolean hasClusterKey = targetTable.getBaseSchema().stream().anyMatch(Column::isClusterKey);
// currently cluster key doesn't support partial update, so we can't convert
// a delete stmt to partial update load if the table has cluster key
for (Column column : targetTable.getFullSchema()) {
NamedExpression expr = null;
if (column.getName().equalsIgnoreCase(Column.DELETE_SIGN)) {
selectLists.add(new UnboundAlias(new TinyIntLiteral(((byte) 1)), Column.DELETE_SIGN));
expr = new UnboundAlias(new TinyIntLiteral(((byte) 1)), Column.DELETE_SIGN);
} else if (column.getName().equalsIgnoreCase(Column.SEQUENCE_COL)
&& targetTable.getSequenceMapCol() != null) {
selectLists.add(new UnboundSlot(tableName, targetTable.getSequenceMapCol()));
expr = new UnboundSlot(tableName, targetTable.getSequenceMapCol());
} else if (column.isKey()) {
selectLists.add(new UnboundSlot(tableName, column.getName()));
expr = new UnboundSlot(tableName, column.getName());
} else if (!isMow && (!column.isVisible() || (!column.isAllowNull() && !column.hasDefaultValue()))) {
selectLists.add(new UnboundSlot(tableName, column.getName()));
expr = new UnboundSlot(tableName, column.getName());
} else if (hasClusterKey) {
expr = new UnboundSlot(tableName, column.getName());
} else {
selectLists.add(new UnboundSlot(tableName, column.getName()));
continue;
}
selectLists.add(expr);
cols.add(column.getName());
}
logicalQuery = new LogicalProject<>(selectLists, logicalQuery);
boolean isPartialUpdate = targetTable.getEnableUniqueKeyMergeOnWrite()
&& cols.size() < targetTable.getColumns().size();
boolean isPartialUpdate = isMow && !hasClusterKey && cols.size() < targetTable.getColumns().size();
logicalQuery = handleCte(logicalQuery);
// make UnboundTableSink
return UnboundTableSinkCreator.createUnboundTableSink(nameParts, cols, ImmutableList.of(),

View File

@ -231,6 +231,7 @@ public class OlapTableSink extends DataSink {
}
strBuilder.append(prefix + " TUPLE ID: " + tupleDescriptor.getId() + "\n");
strBuilder.append(prefix + " " + DataPartition.RANDOM.getExplainString(explainLevel));
strBuilder.append(prefix + " IS_PARTIAL_UPDATE: " + isPartialUpdate);
return strBuilder.toString();
}