[fix](agg) fix be crash when double type be key in agg table#61798
[fix](agg) fix be crash when double type be key in agg table#61798yiguolei merged 1 commit intoapache:branch-2.1from
Conversation
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
|
run buildall |
| } | ||
| for (ColumnDef colDef : columnDefs) { | ||
| if (tableName != null) { | ||
| Table table = Env.getCurrentInternalCatalog().getDbOrAnalysisException(tableName.getDb()) |
There was a problem hiding this comment.
Is this problem only exist in 2.1? what about 3.1 4.0 4.1?
There was a problem hiding this comment.
all branch are exists, I'll backport others branch
|
/review |
There was a problem hiding this comment.
Code Review Summary
This PR adds logic to AddColumnsClause.analyze() to automatically mark columns as key columns in AGG_KEYS tables when no aggregate type is specified, mirroring existing logic in AddColumnClause. While the intent is correct (fixing a BE crash), the implementation has two issues that need to be addressed:
Critical Issues
-
Missing
setKeysType()call (Bug): BothAddColumnClause(line 83-85) andModifyColumnClause(line 83) callcolDef.setKeysType(((OlapTable) table).getKeysType())after thesetIsKey()block. This PR omits this call. ThekeysTypefield inColumnDefis used duringanalyze()(line 361) to validate complex types (BITMAP, HLL, QUANTILE_STATE). Without setting it,keysTyperemainsnull, which causes the conditionkeysType == null || keysType == KeysType.AGG_KEYSto always be true, potentially producing incorrect validation errors for non-AGG_KEYS tables. -
Table lookup inside the loop (Performance): The
Env.getCurrentInternalCatalog().getDbOrAnalysisException(...).getTableOrAnalysisException(...)call is placed inside theforloop, causing a redundant database+table lookup for every column in the list. This should be hoisted before the loop sincetableNameis invariant across iterations.
Minor Issues
-
Inconsistent exception method: Uses
getDbOrAnalysisException/getTableOrAnalysisExceptionwhile the sibling classes (AddColumnClause,ModifyColumnClause) usegetDbOrDdlException/getTableOrDdlException. -
Missing regression test: The PR description checks the "Regression test" box but no test file is included in the changeset.
Checklist
- Correctness: Issues found (missing
setKeysType, table lookup in loop) - Performance: Table lookup should be moved outside the loop
- Test coverage: Missing despite checkbox being ticked
| import org.apache.doris.alter.AlterOpType; | ||
| import org.apache.doris.catalog.Column; | ||
| import org.apache.doris.catalog.Env; | ||
| import org.apache.doris.catalog.KeysType; |
There was a problem hiding this comment.
Bug: Missing setKeysType() call + Performance: Table lookup should be outside the loop.
Comparing with AddColumnClause.analyze() (lines 76-86), there are two problems:
-
Missing
setKeysType():AddColumnClauseandModifyColumnClauseboth callcolDef.setKeysType(((OlapTable) table).getKeysType())after thesetIsKey()block. Without this,ColumnDef.keysTyperemainsnull, which affects the validation atColumnDef.java:361wherekeysType == nullis treated the same asAGG_KEYS, potentially causing incorrect errors for complex types in non-AGG tables. -
Table lookup in loop: The table lookup is inside the
forloop buttableNamedoesn't change between iterations. This causes redundant DB+table lookups for each column.
Suggested fix:
if (tableName != null) {
Table table = Env.getCurrentInternalCatalog().getDbOrAnalysisException(tableName.getDb())
.getTableOrAnalysisException(tableName.getTbl());
if (table instanceof OlapTable) {
OlapTable olapTable = (OlapTable) table;
for (ColumnDef colDef : columnDefs) {
if (olapTable.getKeysType() == KeysType.AGG_KEYS
&& colDef.getAggregateType() == null) {
colDef.setIsKey(true);
}
colDef.setKeysType(olapTable.getKeysType());
}
}
}
for (ColumnDef colDef : columnDefs) {
colDef.analyze(true);
...
}Or alternatively, keep the single loop but move the table lookup before it.
|
skip buildall |
|
PR approved by at least one committer and no changes requested. |
|
PR approved by anyone and no changes requested. |
What problem does this PR solve?
Issue Number: close #61797
Related PR: #xxx
Problem Summary:
be crash when double type be key in agg table
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)