-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[17.0] Fix and Make aggregation planner handle aggregation functions …
…better and handle Distinct in operator (#13277) * Handle DISTINCT with the new operators (#13201) * handle distinct with the new operators Signed-off-by: Andres Taylor <andres@planetscale.com> * feat: do not fail limit when offsets are present Signed-off-by: Manan Gupta <manan@planetscale.com> * test: add more DISTINCT end to end tests Signed-off-by: Andres Taylor <andres@planetscale.com> * remove limitation around aggregation and distinct Signed-off-by: Andres Taylor <andres@planetscale.com> --------- Signed-off-by: Andres Taylor <andres@planetscale.com> Signed-off-by: Manan Gupta <manan@planetscale.com> Co-authored-by: Manan Gupta <manan@planetscale.com> * Fix and Make aggregation planner handle aggregation functions better (#13228) * handle unpushed aggregation better Signed-off-by: Andres Taylor <andres@planetscale.com> * distinct on aggregator and changed distinct engine primitive to take offset than truncate bool Signed-off-by: Harshit Gangal <harshit@planetscale.com> * handle SUM with the new operator horizon planning Signed-off-by: Andres Taylor <andres@planetscale.com> * empty t10 after running tests Signed-off-by: Andres Taylor <andres@planetscale.com> * add collations and weight_string for aggregations where engine primitive is supported Signed-off-by: Harshit Gangal <harshit@planetscale.com> * compare columns using semantic equality Signed-off-by: Andres Taylor <andres@planetscale.com> * handle grouping expressions that are returned in multiple columns Signed-off-by: Andres Taylor <andres@planetscale.com> * add end2end test to show that query works Signed-off-by: Andres Taylor <andres@planetscale.com> * on aggregate count and sum splittling create new aggr and update the column offset based on where it is pushed Signed-off-by: Harshit Gangal <harshit@planetscale.com> * add waitForAuthoritative for last insert id test Signed-off-by: Harshit Gangal <harshit@planetscale.com> * fix: push nil for min max cases for other side Signed-off-by: Harshit Gangal <harshit@planetscale.com> * saves vtgate startup time as most of the test only have primary Signed-off-by: Harshit Gangal <harshit@planetscale.com> * allow min/max without weight_string, projection to be created always on aggregation pushing with join, compact done later Signed-off-by: Harshit Gangal <harshit@planetscale.com> --------- Signed-off-by: Andres Taylor <andres@planetscale.com> Signed-off-by: Harshit Gangal <harshit@planetscale.com> Co-authored-by: Andres Taylor <andres@planetscale.com> --------- Signed-off-by: Andres Taylor <andres@planetscale.com> Signed-off-by: Manan Gupta <manan@planetscale.com> Signed-off-by: Harshit Gangal <harshit@planetscale.com> Co-authored-by: Andres Taylor <andres@planetscale.com> Co-authored-by: Manan Gupta <manan@planetscale.com>
- Loading branch information
1 parent
bb113c4
commit 3e74b02
Showing
32 changed files
with
1,608 additions
and
795 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
go/test/endtoend/vtgate/queries/aggregation/distinct_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2023 The Vitess Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package aggregation | ||
|
||
import ( | ||
"testing" | ||
|
||
"vitess.io/vitess/go/test/endtoend/utils" | ||
) | ||
|
||
func TestDistinct(t *testing.T) { | ||
mcmp, closer := start(t) | ||
defer closer() | ||
mcmp.Exec("insert into t3(id5,id6,id7) values(1,3,3), (2,3,4), (3,3,6), (4,5,7), (5,5,6)") | ||
mcmp.Exec("insert into t7_xxhash(uid,phone) values('1',4), ('2',4), ('3',3), ('4',1), ('5',1)") | ||
mcmp.Exec("insert into aggr_test(id, val1, val2) values(1,'a',1), (2,'A',1), (3,'b',1), (4,'c',3), (5,'c',4)") | ||
mcmp.Exec("insert into aggr_test(id, val1, val2) values(6,'d',null), (7,'e',null), (8,'E',1)") | ||
mcmp.AssertMatches("select distinct val2, count(*) from aggr_test group by val2", `[[NULL INT64(2)] [INT64(1) INT64(4)] [INT64(3) INT64(1)] [INT64(4) INT64(1)]]`) | ||
mcmp.AssertMatches("select distinct id6 from t3 join t7_xxhash on t3.id5 = t7_xxhash.phone", `[[INT64(3)] [INT64(5)]]`) | ||
} | ||
|
||
func TestDistinctIt(t *testing.T) { | ||
// tests more variations of DISTINCT | ||
mcmp, closer := start(t) | ||
defer closer() | ||
|
||
mcmp.Exec("insert into aggr_test(id, val1, val2) values(1,'a',1), (2,'A',1), (3,'b',1), (4,'c',3), (5,'c',4)") | ||
mcmp.Exec("insert into aggr_test(id, val1, val2) values(6,'d',null), (7,'e',null), (8,'E',1)") | ||
|
||
mcmp.AssertMatchesNoOrder("select distinct val1 from aggr_test", `[[VARCHAR("c")] [VARCHAR("d")] [VARCHAR("e")] [VARCHAR("a")] [VARCHAR("b")]]`) | ||
mcmp.AssertMatchesNoOrder("select distinct val2 from aggr_test", `[[INT64(1)] [INT64(4)] [INT64(3)] [NULL]]`) | ||
mcmp.AssertMatchesNoOrder("select distinct id from aggr_test", `[[INT64(1)] [INT64(2)] [INT64(3)] [INT64(5)] [INT64(4)] [INT64(6)] [INT64(7)] [INT64(8)]]`) | ||
|
||
if utils.BinaryIsAtVersion(17, "vtgate") { | ||
mcmp.AssertMatches("select /*vt+ PLANNER=Gen4 */ distinct val1 from aggr_test order by val1 desc", `[[VARCHAR("e")] [VARCHAR("d")] [VARCHAR("c")] [VARCHAR("b")] [VARCHAR("a")]]`) | ||
mcmp.AssertMatchesNoOrder("select /*vt+ PLANNER=Gen4 */ distinct val1, count(*) from aggr_test group by val1", `[[VARCHAR("a") INT64(2)] [VARCHAR("b") INT64(1)] [VARCHAR("c") INT64(2)] [VARCHAR("d") INT64(1)] [VARCHAR("e") INT64(2)]]`) | ||
mcmp.AssertMatchesNoOrder("select /*vt+ PLANNER=Gen4 */ distinct val1+val2 from aggr_test", `[[NULL] [FLOAT64(1)] [FLOAT64(3)] [FLOAT64(4)]]`) | ||
mcmp.AssertMatchesNoOrder("select /*vt+ PLANNER=Gen4 */ distinct count(*) from aggr_test group by val1", `[[INT64(2)] [INT64(1)]]`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
create table t1( | ||
id1 bigint, | ||
id2 bigint, | ||
primary key(id1) | ||
) Engine=InnoDB; | ||
|
||
create table t1_copy_basic( | ||
id1 bigint, | ||
id2 bigint, | ||
primary key(id1) | ||
) Engine=InnoDB; | ||
|
||
create table t1_copy_all( | ||
id1 bigint, | ||
id2 bigint, | ||
primary key(id1) | ||
) Engine=InnoDB; | ||
|
||
create table t1_copy_resume( | ||
id1 bigint, | ||
id2 bigint, | ||
primary key(id1) | ||
) Engine=InnoDB; | ||
|
||
create table t1_id2_idx( | ||
id2 bigint, | ||
keyspace_id varbinary(10), | ||
primary key(id2) | ||
) Engine=InnoDB; | ||
|
||
create table vstream_test( | ||
id bigint, | ||
val bigint, | ||
primary key(id) | ||
) Engine=InnoDB; | ||
|
||
create table aggr_test( | ||
id bigint, | ||
val1 varchar(16), | ||
val2 bigint, | ||
primary key(id) | ||
) Engine=InnoDB; | ||
|
||
create table t2( | ||
id3 bigint, | ||
id4 bigint, | ||
primary key(id3) | ||
) Engine=InnoDB; | ||
|
||
create table t2_id4_idx( | ||
id bigint not null auto_increment, | ||
id4 bigint, | ||
id3 bigint, | ||
primary key(id), | ||
key idx_id4(id4) | ||
) Engine=InnoDB; | ||
|
||
create table t1_last_insert_id( | ||
id bigint not null auto_increment, | ||
id1 bigint, | ||
primary key(id) | ||
) Engine=InnoDB; | ||
|
||
create table t1_row_count( | ||
id bigint not null, | ||
id1 bigint, | ||
primary key(id) | ||
) Engine=InnoDB; | ||
|
||
create table t1_sharded( | ||
id1 bigint, | ||
id2 bigint, | ||
primary key(id1) | ||
) Engine=InnoDB; |
Oops, something went wrong.