diff --git a/go/test/endtoend/vtgate/queries/aggregation/aggregation_test.go b/go/test/endtoend/vtgate/queries/aggregation/aggregation_test.go index a714550fb50..fd8353a585e 100644 --- a/go/test/endtoend/vtgate/queries/aggregation/aggregation_test.go +++ b/go/test/endtoend/vtgate/queries/aggregation/aggregation_test.go @@ -371,6 +371,9 @@ func TestAggregateRandom(t *testing.T) { mcmp.Exec("insert into t2(id, shardKey) values (1, 10), (2, 20)") mcmp.AssertMatches("SELECT /*vt+ PLANNER=gen4 */ t1.shardKey, t1.name, count(t2.id) FROM t1 JOIN t2 ON t1.value != t2.shardKey GROUP BY t1.t1_id", `[[INT64(1) VARCHAR("name 1") INT64(2)] [INT64(2) VARCHAR("name 2") INT64(2)]]`) + + mcmp.Exec("set sql_mode=''") + mcmp.AssertMatches("select /*vt+ PLANNER=Gen4 */ tbl0.comm, count(*) from emp as tbl0, emp as tbl1 where tbl0.empno = tbl1.deptno", `[[NULL INT64(0)]]`) } // TestAggregateLeftJoin tests that aggregates work with left joins and does not ignore the count when column value does not match the right side table. diff --git a/go/test/endtoend/vtgate/queries/aggregation/schema.sql b/go/test/endtoend/vtgate/queries/aggregation/schema.sql index 0375bdb8499..e1489b4bd21 100644 --- a/go/test/endtoend/vtgate/queries/aggregation/schema.sql +++ b/go/test/endtoend/vtgate/queries/aggregation/schema.sql @@ -75,4 +75,25 @@ CREATE TABLE t10 ( k BIGINT PRIMARY KEY, a INT, b INT -); \ No newline at end of file +); + +CREATE TABLE emp ( + empno bigint NOT NULL, + ename VARCHAR(10), + job VARCHAR(9), + mgr bigint, + hiredate DATE, + sal bigint, + comm bigint, + deptno bigint, + PRIMARY KEY (empno) +) Engine = InnoDB + COLLATE = utf8mb4_general_ci; + +CREATE TABLE dept ( + deptno bigint, + dname VARCHAR(14), + loc VARCHAR(13), + PRIMARY KEY (deptno) +) Engine = InnoDB + COLLATE = utf8mb4_general_ci; \ No newline at end of file diff --git a/go/test/endtoend/vtgate/queries/aggregation/vschema.json b/go/test/endtoend/vtgate/queries/aggregation/vschema.json index 4d1623d5633..050202aed81 100644 --- a/go/test/endtoend/vtgate/queries/aggregation/vschema.json +++ b/go/test/endtoend/vtgate/queries/aggregation/vschema.json @@ -131,6 +131,22 @@ "name": "hash" } ] + }, + "emp": { + "column_vindexes": [ + { + "column": "deptno", + "name": "hash" + } + ] + }, + "dept": { + "column_vindexes": [ + { + "column": "deptno", + "name": "hash" + } + ] } } } \ No newline at end of file diff --git a/go/vt/vtgate/engine/scalar_aggregation.go b/go/vt/vtgate/engine/scalar_aggregation.go index 7e3e5a391eb..51e13aac8be 100644 --- a/go/vt/vtgate/engine/scalar_aggregation.go +++ b/go/vt/vtgate/engine/scalar_aggregation.go @@ -209,7 +209,8 @@ func createEmptyValueFor(opcode AggregateOpcode) (sqltypes.Value, error) { AggregateSumDistinct, AggregateSum, AggregateMin, - AggregateMax: + AggregateMax, + AggregateRandom: return sqltypes.NULL, nil }