Skip to content

[Bug] width_bucket returns 0 when num_buckets > (max_value - min_value) #68222

Description

@yy782

Search before asking

  • I had searched in the issues and found no similar issues.

Version

master
CommitID: 979e053

What's Wrong?

mysql> select width_bucket (9, 0, 10, 20);
+-----------------------------+
| width_bucket (9, 0, 10, 20) |
+-----------------------------+
| 0 |
+-----------------------------+
1 row in set (0.02 sec)

mysql> select width_bucket (3, 0, 10, 20);
+-----------------------------+
| width_bucket (3, 0, 10, 20) |
+-----------------------------+
| 0 |
+-----------------------------+
1 row in set (0.02 sec)

mysql> select width_bucket (1, 0, 2, 5);
+---------------------------+
| width_bucket (1, 0, 2, 5) |
+---------------------------+
| 0 |
+---------------------------+
1 row in set (0.01 sec)

mysql> select width_bucket (0, 0, 10, 20);
+-----------------------------+
| width_bucket (0, 0, 10, 20) |
+-----------------------------+
| 0 |
+-----------------------------+
1 row in set (0.02 sec)

What You Expected?

mysql> select width_bucket (9, 0, 10, 20);
+-----------------------------+
| width_bucket (9, 0, 10, 20) |
+-----------------------------+
| 19 |
+-----------------------------+
1 row in set (0.02 sec)

mysql> select width_bucket (3, 0, 10, 20);
+-----------------------------+
| width_bucket (3, 0, 10, 20) |
+-----------------------------+
| 7 |
+-----------------------------+
1 row in set (0.02 sec)

mysql> select width_bucket (1, 0, 2, 5);
+---------------------------+
| width_bucket (1, 0, 2, 5) |
+---------------------------+
| 3 |
+---------------------------+
1 row in set (0.01 sec)

mysql> select width_bucket (0, 0, 10, 20);
+-----------------------------+
| width_bucket (0, 0, 10, 20) |
+-----------------------------+
| 1 |
+-----------------------------+
1 row in set (0.02 sec)

How to Reproduce?

Run the following SQL directly (no table required):

select width_bucket(9, 0, 10, 20); -- returns 0
select width_bucket(3, 0, 10, 20); -- returns 0
select width_bucket(1, 0, 2, 5); -- returns 0

All three should return 19 / 7 / 3 respectively.

Anything Else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions