diff --git a/go/test/endtoend/preparestmt/stmt_methods_test.go b/go/test/endtoend/preparestmt/stmt_methods_test.go index 21369ea4d3a..24fb58bff81 100644 --- a/go/test/endtoend/preparestmt/stmt_methods_test.go +++ b/go/test/endtoend/preparestmt/stmt_methods_test.go @@ -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) +} diff --git a/go/vt/vtgate/semantics/semantic_state.go b/go/vt/vtgate/semantics/semantic_state.go index 3058f0608cc..aaffce06bed 100644 --- a/go/vt/vtgate/semantics/semantic_state.go +++ b/go/vt/vtgate/semantics/semantic_state.go @@ -260,6 +260,15 @@ func (st *SemTable) TypeForExpr(e sqlparser.Expr) (sqltypes.Type, collations.ID, if typ, found := st.ExprTypes[e]; found { return typ.Type, typ.Collation, true } + + // 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 + } + return sqltypes.Unknown, collations.Unknown, false }