Skip to content
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
20 changes: 10 additions & 10 deletions enginetest/queries/query_plans.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions sql/plan/str_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plan

import (
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/expression"
"github.com/dolthub/go-mysql-server/sql/transform"
)

Expand All @@ -20,6 +21,14 @@ func AliasSubqueryString(e sql.Expression) string {
if err != nil {
panic(err)
}

// String literal values are quoted when their String() method is called, so to avoid that, we
// check if we're dealing with a string literal and use it's raw value if so.
if literal, ok := e.(*expression.Literal); ok {
if s, ok := literal.Value().(string); ok {
return s
}
}
return e.String()
}

Expand Down
14 changes: 13 additions & 1 deletion sql/planbuilder/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ func selectExprNeedsAlias(e *ast.AliasedExpr, expr sql.Expression) bool {
return true
}
})
if complex {
return true
}

// If the expression's string representation is quoted, trim the quotes before comparing it to the input expression.
// InputExpression is assigned in the Vitess layer, and it always trims quotes at that time, too.
exprString := expr.String()
if strings.HasPrefix(exprString, "'") && strings.HasSuffix(exprString, "'") {
exprString = exprString[1 : len(exprString)-1]
}

return complex || e.InputExpression != expr.String()
// If the expression's input value does not match expr.String(), then we know that it is not
// referenceable and will need an alias.
return e.InputExpression != exprString
}
3 changes: 2 additions & 1 deletion sql/types/typecheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ package types
import (
"testing"

"github.com/dolthub/go-mysql-server/sql"
"github.com/stretchr/testify/assert"

"github.com/dolthub/go-mysql-server/sql"
)

func TestIsGeometry(t *testing.T) {
Expand Down