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-19.1: opt: nil presentation should not equal the 0-column presentation #41667

Merged
Merged
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
12 changes: 8 additions & 4 deletions pkg/sql/opt/memo/interner.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,14 @@ func (h *hasher) HashTupleOrdinal(val TupleOrdinal) {
}

func (h *hasher) HashPhysProps(val *physical.Required) {
for i := range val.Presentation {
col := &val.Presentation[i]
h.HashString(col.Alias)
h.HashColumnID(col.ID)
// Note: the Any presentation is not the same as the 0-column presentation.
if !val.Presentation.Any() {
h.HashInt(len(val.Presentation))
for i := range val.Presentation {
col := &val.Presentation[i]
h.HashString(col.Alias)
h.HashColumnID(col.ID)
}
}
h.HashOrderingChoice(val.Ordering)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/opt/props/physical/required.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ func (p Presentation) Any() bool {
// Equals returns true iff this presentation exactly matches the given
// presentation.
func (p Presentation) Equals(rhs Presentation) bool {
// The 0 column presentation is not the same as the nil presentation.
if p.Any() != rhs.Any() {
return false
}
if len(p) != len(rhs) {
return false
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/sql/opt/props/physical/required_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ func TestRequiredProps(t *testing.T) {
t.Error("presentation should equal itself")
}

if presentation.Equals(physical.Presentation{}) {
if presentation.Equals(physical.Presentation(nil)) {
t.Error("presentation should not equal the empty presentation")
}

if presentation.Equals(physical.Presentation{}) {
t.Error("presentation should not equal the 0 column presentation")
}

if (physical.Presentation{}).Equals(physical.Presentation(nil)) {
t.Error("0 column presentation should not equal the empty presentation")
}

// Add ordering props.
ordering := physical.ParseOrderingChoice("+1,+5")
phys.Ordering = ordering
Expand Down