sql: reject equal bounds in width_bucket#171264
Conversation
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. I was unable to automatically find a reviewer. You can try CCing one of the following members:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
Thanks for the review @rafiss! Could you please |
Thanks for your contribution. You need to rebase this change and resolve merge conflicts first. |
An error occurred while handling your Trunk command: |
PostgreSQL rejects width_bucket(operand, b1, b2, count) when the lower and upper bounds are equal with the message "lower bound cannot equal upper bound". CockroachDB silently returned garbage in both overloads: the helper computes width = (b2-b1)/count = 0, then casts +/-Inf or NaN to int, producing INT64_MAX, INT64_MIN, or 0 depending on the operand. Add the guard to both the numeric and int overloads, using the same pgcode (2201G) that the sibling NaN and finite-bound checks already raise. Fixes cockroachdb#171263 Release note (bug fix): width_bucket(operand, b1, b2, count) now returns an error "lower bound cannot equal upper bound" when the two bounds are equal, matching PostgreSQL.
f666f90 to
f0f6601
Compare
|
Thank you for updating your pull request. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
@rafiss rebased onto master. Resolved conflicts. Ready to retry the merge. |
|
Detected infrastructure failure (matched: self-hosted runner lost communication with the server). Automatically rerunning failed jobs. (run link) |
Fixes #171263
PostgreSQL rejects
width_bucket(operand, b1, b2, count)when the lower and upper bounds are equal with the message "lower bound cannot equal upper bound" (pgcodeinvalid_argument_for_width_bucket_function,2201G). CockroachDB silently returned garbage: the helper computeswidth = (b2 - b1) / count = 0, thenint(math.Floor(diff/0) + 1)casts+Inf,-Inf, orNaNto int, producingINT64_MAX,INT64_MIN, or0depending on operand position.This adds the guard to both the numeric and int overloads, using the same pgcode that the sibling NaN and finite-bound checks already raise. In the numeric overload, the guard is placed after the existing NaN/finite-bound guards and before the +/-Infinity operand shortcuts, matching PostgreSQL's check precedence.
This is a sibling of #171234 (
count <= 0), already addressed by #171259, but independent and self-contained.Epic: none
Release note (bug fix): width_bucket(operand, b1, b2, count) now returns "lower bound cannot equal upper bound" when the two bounds are equal, matching PostgreSQL.