[fix](fe) Suppress invalid unique constraints in scan FD derivation - #66801
Open
englefly wants to merge 1 commit into
Open
[fix](fe) Suppress invalid unique constraints in scan FD derivation#66801englefly wants to merge 1 commit into
englefly wants to merge 1 commit into
Conversation
### What problem does this PR solve?
Problem Summary:
LogicalCatalogRelation.computeUnique() registered a PARTIAL unique key when
the scan output did not contain every constrained column: findSlotsByColumn()
returned outputSet ∩ columns, so a non-base index covering only (a, c) of a
table-level UNIQUE(a, b) constraint advertised {a} as unique. The FD a -> c
derived from it then let EliminateGroupByKey drop c from GROUP BY (wrapping it
with any_value), merging distinct groups such as (1,'x') and (1,'y').
LogicalOlapScan.computeUnique() imported table-level constraints via
super.computeUnique() BEFORE its raw-version guards ran. For MOR unique-key
tables read as DUP (read_mor_as_dup_tables, or skipDeleteBitmap), the read
exposes every version, e.g. (1,10),(1,20),(1,30), so the unique key k is not
unique in the data; the early return still left the superclass constraint
registered and the k -> v FD could collapse those three groups into one.
Fix:
- findSlotsByColumn() now requires every constrained column to be present in
the scan output; when any is missing it returns an empty set, so a partial
constraint is never registered (both Logical and Physical catalog relations).
- LogicalOlapScan.computeUnique() checks the raw-version read conditions
(skipDeleteBitmap / read_mor_as_dup_tables) before super.computeUnique()
so the table constraint is not imported for data whose uniqueness does not
hold; the redundant inner guards were removed.
### Release note
None
### Check List (For Author)
- Test: Unit Test
- FdTest.testScanOutputMissingConstraintColumns: scan output missing a
constrained column must not register the partial key as unique.
- FdTest.testMorReadAsDupSuppressesUniqueConstraint: MOR table read as DUP
must not keep the k unique constraint.
- Both fail on the old code and pass with the fix; full FdTest class green.
- Behavior changed: Yes. Fixes wrong query results (merged groups) for the two
scan shapes above; no intended plan-shape or performance change otherwise.
- Does this need documentation: No
englefly
requested review from
924060929,
morrySnow and
starocean999
as code owners
August 16, 2026 03:31
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
Author
|
run buildall |
16 tasks
Contributor
TPC-H: Total hot run time: 17634 ms |
Contributor
TPC-DS: Total hot run time: 85395 ms |
Contributor
ClickBench: Total hot run time: 14.65 s |
Contributor
FE UT Coverage ReportIncrement line coverage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Problem Summary:
LogicalCatalogRelation.computeUnique()registered a partial unique key when the scan output did not contain every constrained column:findSlotsByColumn()returnedoutputSet ∩ columns, so a non-base index covering only(a, c)of a table-levelUNIQUE(a, b)constraint advertised{a}as unique. The FDa -> cderived from it then letEliminateGroupByKeydropcfromGROUP BY(wrapping it withany_value), merging distinct groups such as(1,'x')and(1,'y').LogicalOlapScan.computeUnique()imported table-level constraints viasuper.computeUnique()before its raw-version guards ran. For MOR unique-key tables read as DUP (read_mor_as_dup_tables, orskipDeleteBitmap), the read exposes every version, e.g.(1,10),(1,20),(1,30), so the unique keykis not unique in the data; the earlyreturnstill left the superclass constraint registered, and thek -> vFD could collapse those three groups into one.Fix:
findSlotsByColumn()now requires every constrained column to be present in the scan output; when any is missing it returns an empty set, so a partial constraint is never registered (bothLogicalCatalogRelationandPhysicalCatalogRelation).LogicalOlapScan.computeUnique()checks the raw-version read conditions (skipDeleteBitmap/read_mor_as_dup_tables) beforesuper.computeUnique(), so the table constraint is not imported for data whose uniqueness does not hold; the redundant inner guards were removed.Release note
None
Check List (For Author)
Test
FdTest.testScanOutputMissingConstraintColumns: scan output missing a constrained column must not register the partial key as unique.FdTest.testMorReadAsDupSuppressesUniqueConstraint: MOR table read as DUP must not keep thekunique constraint.FdTestclass is green.Behavior changed:
Fixes wrong query results (merged groups) for the two scan shapes above; no intended plan-shape or performance change otherwise.
Does this need documentation?
Check List (For Reviewer who merge this PR)