Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report: query result based on cross shard aggregation is bad #12540

Closed
eseokoh opened this issue Mar 2, 2023 · 1 comment · Fixed by #12607
Closed

Bug Report: query result based on cross shard aggregation is bad #12540

eseokoh opened this issue Mar 2, 2023 · 1 comment · Fixed by #12607

Comments

@eseokoh
Copy link

eseokoh commented Mar 2, 2023

Overview of the Issue

Sometimes query based on a cross shard aggregation shows a bad result, where not all shards are hit.

Reproduction Steps

  1. Prepare for a keyspace with 2 shards

  2. Deploy the following vschema:

alter vschema on aggt0 add vindex xxhash (shardkey) using xxhash;
  1. Deploy the following schema:
 create table aggt0 (
 shardkey bigint primary key,
 a int,
 b int
);

insert into aggt0 (shardkey, a, b) values (0, 100, 10), (10, 200, 20);

Please notice that shardkey of 0 goes to 80- shard and that of 10 does to -80.

  1. Run Query
mysql> select A.a, A.b, (A.a / A.b) as d from (select sum(a) as a, sum(b) as b from aggt0) A;
+------+------+---------+
| a    | b    | d       |
+------+------+---------+
|  300 |   30 | 10.0000 |
+------+------+---------+
1 row in set (0.13 sec)

This is absolutely good.

However, when the subquery hit not both but one shard, it may show a bad result.
Please repeat the query until you have the bad result.

  • the expected result
mysql> select A.a, A.b, (A.a / A.b) as d from (select sum(a) as a, sum(b) as b from aggt0 where a = 100) A;
+------+------+---------+
| a    | b    | d       |
+------+------+---------+
|  100 |   10 | 10.0000 |
+------+------+---------+
1 row in set (0.00 sec)
  • the unexpected result
mysql> select A.a, A.b, (A.a / A.b) as d from (select sum(a) as a, sum(b) as b from aggt0 where a = 100) A;
+------+------+------+
| a    | b    | d    |
+------+------+------+
|  100 |   10 | NULL |
+------+------+------+
1 row in set (0.01 sec)

Binary Version

14.0.4

Operating System and Environment details

unrelated

Log Fragments

N/A
@eseokoh eseokoh added Needs Triage This issue needs to be correctly labelled and triaged Type: Bug labels Mar 2, 2023
@deepthi deepthi added this to v17.0.0 Mar 2, 2023
@deepthi deepthi moved this to Backlog in v17.0.0 Mar 2, 2023
@deepthi deepthi removed the Needs Triage This issue needs to be correctly labelled and triaged label Mar 2, 2023
@frouioui frouioui self-assigned this Mar 10, 2023
@frouioui frouioui moved this from Backlog to In Progress in v17.0.0 Mar 10, 2023
@frouioui
Copy link
Member

Hey @eseokoh, thank you for reporting this issue. I opened #12607 to fix it.

@github-project-automation github-project-automation bot moved this from In Progress to Done in v17.0.0 Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants