Skip to content

Commit

Permalink
feat: figure out the type of weightstrings added late
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed Aug 25, 2023
1 parent 1fb2335 commit 1b56c69
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions go/test/endtoend/preparestmt/stmt_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,24 @@ func TestShowColumns(t *testing.T) {
require.Len(t, cols, 6)
require.False(t, rows.Next())
}

func TestBinaryColumn(t *testing.T) {
defer cluster.PanicHandler(t)
dbo := Connect(t, "interpolateParams=false")
defer dbo.Close()

_, err := dbo.Query(`SELECT DISTINCT
BINARY table_info.table_name AS table_name,
table_info.create_options AS create_options,
table_info.table_comment AS table_comment
FROM information_schema.tables AS table_info
JOIN information_schema.columns AS column_info
ON BINARY column_info.table_name = BINARY table_info.table_name
WHERE
table_info.table_schema = ?
AND column_info.table_schema = ?
-- Exclude views.
AND table_info.table_type = 'BASE TABLE'
ORDER BY BINARY table_info.table_name`, keyspaceName, keyspaceName)
require.NoError(t, err)
}
8 changes: 8 additions & 0 deletions go/vt/vtgate/semantics/semantic_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@ func (st *SemTable) AddExprs(tbl *sqlparser.AliasedTableExpr, cols sqlparser.Sel

// TypeForExpr returns the type of expressions in the query
func (st *SemTable) TypeForExpr(e sqlparser.Expr) (sqltypes.Type, collations.ID, bool) {
// We add a lot of WeightString() expressions to queries at late stages of the planning,
// which means that they don't have any type information. We can safely assume that they
// are VarBinary, since that's the only type that WeightString() can return.
_, isWS := e.(*sqlparser.WeightStringFuncExpr)
if isWS {
return sqltypes.VarBinary, collations.CollationBinaryID, true
}

if typ, found := st.ExprTypes[e]; found {
return typ.Type, typ.Collation, true
}
Expand Down

0 comments on commit 1b56c69

Please sign in to comment.