Skip to content

Commit

Permalink
Merge pull request #132493 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-24.2-129711

release-24.2: opt: relax assertion for lookup join columns
  • Loading branch information
DrewKimball authored Oct 14, 2024
2 parents d48843d + 876c064 commit 6a59d1d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/sql/opt/memo/check_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,8 @@ func (m *Memo) CheckExpr(e opt.Expr) {
if t.Cols.SubsetOf(t.Input.Relational().OutputCols) {
panic(errors.AssertionFailedf("lookup join with no lookup columns"))
}
switch t.JoinType {
case opt.AntiJoinOp:
if len(t.RemoteLookupExpr) > 0 {
panic(errors.AssertionFailedf("anti join with a non-empty RemoteLookupExpr"))
}
if t.JoinType == opt.AntiJoinOp && len(t.RemoteLookupExpr) > 0 {
panic(errors.AssertionFailedf("anti join with a non-empty RemoteLookupExpr"))
}
var requiredCols opt.ColSet
requiredCols.UnionWith(t.Relational().OutputCols)
Expand All @@ -239,10 +236,17 @@ func (m *Memo) CheckExpr(e opt.Expr) {
for i := range t.KeyCols {
requiredCols.Add(t.Table.ColumnID(idx.Column(i).Ordinal()))
}
if !t.Cols.SubsetOf(requiredCols) {
projectedCols := t.Cols
if t.JoinType == opt.SemiJoinOp || t.JoinType == opt.AntiJoinOp {
// Semi and anti joins have an implicit projection that removes the
// columns from the right side. Therefore, we're not strict about removing
// right-side columns from t.Cols.
projectedCols = t.Cols.Intersection(t.Input.Relational().OutputCols)
}
if !projectedCols.SubsetOf(requiredCols) {
panic(errors.AssertionFailedf(
"lookup join with columns %s that are not required; required: %s",
t.Cols, requiredCols,
projectedCols, requiredCols,
))
}
if t.IsFirstJoinInPairedJoiner {
Expand Down

0 comments on commit 6a59d1d

Please sign in to comment.