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

opt: nil presentation should not equal the 0-column presentation #39818

Merged
merged 2 commits into from
Aug 23, 2019
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
7 changes: 7 additions & 0 deletions pkg/sql/apply_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ func (a *applyJoinNode) Next(params runParams) (bool, error) {
eb.DisableTelemetry()
p, err := eb.Build()
if err != nil {
if errors.IsAssertionFailure(err) {
// Enhance the error with the EXPLAIN (OPT, VERBOSE) of the inner
// expression.
fmtFlags := memo.ExprFmtHideQualifications | memo.ExprFmtHideScalars | memo.ExprFmtHideTypes
explainOpt := memo.FormatExpr(newRightSide, fmtFlags, nil /* catalog */)
err = errors.WithDetailf(err, "newRightSide:\n%s", explainOpt)
}
return false, err
}
plan := p.(*planTop)
Expand Down
12 changes: 8 additions & 4 deletions pkg/sql/opt/memo/interner.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,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 @@ -115,6 +115,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 @@ -42,10 +42,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