diff --git a/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt b/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt index 26779921712..e6e6c5d9624 100644 --- a/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt @@ -3116,3 +3116,25 @@ Gen4 plan same as above ] } } + +"select count(distinct user_id, name) from unsharded" +{ + "QueryType": "SELECT", + "Original": "select count(distinct user_id, name) from unsharded", + "Instructions": { + "OperatorType": "Route", + "Variant": "Unsharded", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select count(distinct user_id, `name`) from unsharded where 1 != 1", + "Query": "select count(distinct user_id, `name`) from unsharded", + "Table": "unsharded" + } +} +Gen4 plan same as above + +"select count(distinct user_id, name) from user" +"unsupported: only one expression allowed inside aggregates: count(distinct user_id, `name`)" +Gen4 error: aggregate functions take a single argument 'count(distinct user_id, `name`)' diff --git a/go/vt/vtgate/semantics/analyzer.go b/go/vt/vtgate/semantics/analyzer.go index d5b1fd16c0e..39d48326101 100644 --- a/go/vt/vtgate/semantics/analyzer.go +++ b/go/vt/vtgate/semantics/analyzer.go @@ -289,7 +289,7 @@ func (a *analyzer) checkForInvalidConstructs(cursor *sqlparser.Cursor) error { if node.Distinct { err := vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "syntax error: %s", sqlparser.String(node)) - if len(node.Exprs) != 1 { + if len(node.Exprs) < 1 { return err } else if _, ok := node.Exprs[0].(*sqlparser.AliasedExpr); !ok { return err