You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While doing cross keyspace query, vitess generates corrupted results if SQL statement not fulfill full group by constraint.
Reproduction Steps
Assume we have 2 keyspaces called commerce and meta
Running following sql will reproduce this issue.
I think vitess should either raise a error for non-full group by queries if the ONLY_FULL_GROUP_BY sql mode option is on.
Or just return the results as same as mysql default behavior do.
-- create table for commerce.ordersDROPTABLE IF EXISTS commerce.orders;
CREATETABLEcommerce.orders (
id INTEGER(10) NOT NULL,
buyer INTEGER(10) NOT NULL,
total DECIMAL(10, 2) NOT NULL,
created DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(id)
);
-- create table for meta.usersDROPTABLE IF EXISTS meta.users;
CREATETABLEmeta.users (
id INTEGER(10) NOT NULL,
name VARCHAR(64) NOT NULL,
created DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(id)
);
-- create table for commerce.users, this table has the same schema with meta.users tableDROPTABLE IF EXISTS commerce.users;
CREATETABLEcommerce.users (
id INTEGER(10) NOT NULL,
name VARCHAR(64) NOT NULL,
created DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(id)
);
-- insert some order into commerce.ordersinsert intocommerce.orders (id, buyer, total) VALUES(1, 1, 100);
insert intocommerce.orders (id, buyer, total) VALUES(2, 1, 200);
insert intocommerce.orders (id, buyer, total) VALUES(3, 1, 300);
insert intocommerce.orders (id, buyer, total) VALUES(4, 2, 111);
insert intocommerce.orders (id, buyer, total) VALUES(5, 2, 222);
insert intocommerce.orders (id, buyer, total) VALUES(6, 2, 333);
-- insert some user into meta.usersinsert intometa.users (id, name) VALUES(1, 'user 1');
insert intometa.users (id, name) VALUES(2, 'user 2');
-- insert some user into commerce.users-- now you have 2 users table with same data in both commerce and meta keyspaceinsert intocommerce.users (id, name) VALUES(1, 'user 1');
insert intocommerce.users (id, name) VALUES(2, 'user 2');
-- cross keyspace join with non full group by-- this query will generated corrupted results---- | id | name | sum(o.total) | created |-- |----|------|--------------|---------|-- | 1 | 0 | 600.00 | 2022 |-- | 2 | 0 | 666.00 | 2022 |SELECTu.id,
u.name,
sum(o.total),
o.createdFROMcommerce.ordersAS o
JOINmeta.usersAS u ONo.buyer=u.idGROUP BYu.id;
-- the same non full group by query, but this time we join tables from the same keyspce-- this is mysql default behavior---- | id | name | sum(o.total) | created |-- |----|--------|--------------|---------------------|-- | 1 | user 1 | 600.00 | 2022-10-31 16:39:12 |-- | 2 | user 2 | 666.00 | 2022-10-31 16:39:51 |SELECTu.id,
u.name,
sum(o.total),
o.createdFROMcommerce.ordersAS o
JOINcommerce.usersAS u ONo.buyer=u.idGROUP BYu.id;
-- fixed query with full group by + proper aggregation statement (min)---- | id | name | sum(o.total) | created |-- |----|--------|--------------|---------------------|-- | 1 | user 1 | 600.00 | 2022-10-31 16:39:12 |-- | 2 | user 2 | 666.00 | 2022-10-31 16:39:51 |SELECTu.id,
u.name,
sum(o.total),
min(o.created)
FROMcommerce.ordersAS o
JOINmeta.usersAS u ONo.buyer=u.idGROUP BYu.id, u.name;
Binary Version
This issue has been tested with
v14.0.1
v14.0.3
v15.0.0
All above versions have the same behavior
Operating System and Environment details
vitess was setup by vitess k8s operator.
We're using AWS x86_64 ec2 instance with ubuntu 20.20 as k8s worker nodes.
Log Fragments
No response
The text was updated successfully, but these errors were encountered:
Hello @tokikanno, thank you for finding and detailing this issue. This is really helpful. This is indeed a bug that was introduced when we added the "random" aggregation used on non full group by queries.
I have opened a Pull Request to fix the issue you're describing: #11633. This Pull Request will be backported to the release branches 14 and 15. Do you need a patch release for this bug?
Overview of the Issue
While doing cross keyspace query, vitess generates corrupted results if SQL statement not fulfill full group by constraint.
Reproduction Steps
Assume we have 2 keyspaces called
commerce
andmeta
Running following sql will reproduce this issue.
I think vitess should either raise a error for non-full group by queries if the ONLY_FULL_GROUP_BY sql mode option is on.
Or just return the results as same as mysql default behavior do.
Binary Version
Operating System and Environment details
vitess was setup by vitess k8s operator. We're using AWS x86_64 ec2 instance with ubuntu 20.20 as k8s worker nodes.
Log Fragments
No response
The text was updated successfully, but these errors were encountered: