Repository navigation
Conversation
Propagate column-level C collation through the full ORCA pipeline so that sort, comparison, and aggregate operations produce correct results matching the PostgreSQL planner. Key changes: 1. Query->DXL (CTranslatorUtils::GetTableDescr): pass md_col->Collation() when creating CDXLColDescr for table columns - this was the root cause of collation being lost at the very start of the pipeline. 2. Expr->DXL (CTranslatorExprToDXL::MakeDXLTableDescr, PdxlnCTAS): pass CColumnDescriptor collation to CDXLColDescr. 3. DXL->PlStmt (CMappingColIdVarPlStmt::VarFromDXLNodeScId): when the CDXLScalarIdent has no explicit collation (e.g., partial aggregate output columns), fall back to the child TargetEntry expression's collation. This fixes Finalize Aggregate inheriting the correct collation from Partial Aggregate. 4. Aggregate collation (CTranslatorDXLToScalar): set aggcollid from inputcollid instead of TypeCollation, so min/max/string_agg use the correct column collation. 5. Expression-level COLLATE "C" fallback (walkers.c): detect when RelabelType overrides collation (from fold_constants converting CollateExpr to RelabelType) and trigger fallback to PostgreSQL planner, since ORCA does not yet handle expression-level COLLATE. The existing collation infrastructure (CMDColumn, CColumnDescriptor, CColRef, CDXLColRef, CDXLScalarIdent) was already in place but the entry point in CTranslatorUtils was not passing collation, causing all downstream stages to see collation=0. fix regress
With column-level COLLATE "C" supported, ORCA could return wrong results in three ways: 1. Contradiction detection and range constraints. CDefaultComparator compares datums by evaluating "const op const", and the constants carry the type's default collation. For a column whose collation differs from it, e.g. text COLLATE "C", the derived ranges are ordered wrongly: "name > 'Z' AND name < 'a'" was turned into One-Time Filter: false, although 'Zz' satisfies it under C. 2. Static partition pruning uses the same comparator, so partitions of a COLLATE "C" range partition key could be pruned wrongly. 3. ORCA does not track index collations, so an index whose key collation differs from the column's (e.g. CREATE INDEX ON t (c COLLATE "C") on a default collation column, or the other way round) was used for range predicates and orderings it cannot answer. This one also happens without this branch's changes. For 1 and 2, add the type's default collation to the type metadata (IMDType::TypeCollation, serialized as an optional DXL attribute), and don't derive intervals from range comparisons on a column whose collation differs from its type's. Equality based comparisons only produce points, whose intersections and unions don't depend on the sort order, so they are still used. Columns of type name, whose type collation is C, are not affected. Range partitioned tables with a COLLATE "C" text key lose static partition pruning for now; that needs a collation aware comparator. For 3, hide indexes whose key collation differs from the indexed column's from ORCA.
yjhjstz
force-pushed
the
orca_collation
branch
from
November 4, 2026 18:25
ddacdd4 to
eae5f56
Compare
yjhjstz
marked this pull request as ready for review
November 4, 2026 20:48
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.
Fixes #717
What does this PR do?
Type of Change
Breaking Changes
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelImpact
Performance:
User-facing changes:
Dependencies:
Checklist
Additional Context
CI Skip Instructions