Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-22.1: sql/opt: fix "no output column" internal error #98141

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/sql/opt/ordering/ordering.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,15 @@ func remapProvided(provided opt.Ordering, fds *props.FuncDepSet, outCols opt.Col
}
} else {
equivCols := fds.ComputeEquivClosure(opt.MakeColSet(col))
remappedCol, ok := equivCols.Intersection(outCols).Next(0)
remappedCol, ok := equivCols.Next(0)
if !ok {
panic(errors.AssertionFailedf("no output column equivalent to %d", redact.Safe(col)))
}
// If the column is in the output use that.
remappedColFromOutput, ok := equivCols.Intersection(outCols).Next(0)
if ok {
remappedCol = remappedColFromOutput
}
if result == nil {
result = make(opt.Ordering, i, len(provided))
copy(result, provided)
Expand Down
32 changes: 32 additions & 0 deletions pkg/sql/opt/xform/testdata/physprops/ordering
Original file line number Diff line number Diff line change
Expand Up @@ -2741,3 +2741,35 @@ project
│ └── bool_and
└── projections
└── NULL

# Regression test for #96288
exec-ddl
CREATE TABLE v0 (c1 BYTES PRIMARY KEY, c2 TIMESTAMP, INDEX i3(c2))
----

opt
SELECT * FROM v0 WHERE (c1 = c1 AND c2 = '01-31-2023 00:00:00'::TIMESTAMP) OR (c1 = b'00' AND c1 = b'0') OR (c1 IS NULL AND c2 IS NULL)
----
distinct-on
├── columns: c1:1!null c2:2
├── grouping columns: c1:1!null
├── internal-ordering: +1
├── key: (1)
├── fd: (1)-->(2)
├── project
│ ├── columns: c1:1!null c2:2
│ ├── key: (1)
│ ├── fd: (1)-->(2)
│ ├── ordering: +1 [actual: +2,+1]
│ ├── scan v0@i3
│ │ ├── columns: c1:5!null c2:6
│ │ ├── constraint: /6/5: [/'2023-01-31 00:00:00' - /'2023-01-31 00:00:00']
│ │ ├── key: (5)
│ │ ├── fd: (5)-->(6)
│ │ └── ordering: +5 [actual: +6,+5]
│ └── projections
│ ├── c1:5 [as=c1:1, outer=(5)]
│ └── c2:6 [as=c2:2, outer=(6)]
└── aggregations
└── const-agg [as=c2:2, outer=(2)]
└── c2:2