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

release-2.1: sql/sem/tree: bugfix in handling unary negatives #39368

Merged
merged 1 commit into from Aug 7, 2019

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented Aug 6, 2019

Backport 1/2 commits from #39245.

/cc @cockroachdb/release


When performing constant folding, we will now always evaluate unary
negatives right away. To facilitate this, this commit extracts a NumExpr
interface that is implemented by *NumVal. The new interface has methods
to access the constant.Value of the *NumVal, and this accessor always
will perform the necessary unary negation operator.

This works because unary negation has high precedence (only preceded by
the typecast operation).

This change requires us to inspect the Negative flags of both the Expr
and inner Decimal value when resolving a NumExpr that contains a
Decimal, since on some operations like division, the negative value will
now get folded into the Decimal.

Tests have not been backported since there have been significant changes
in testing infrastructure.

Release note (bug fix): unary negatives in constant arithmetic expressions
are no longer ignored.

@rafiss rafiss requested a review from a team August 6, 2019 18:18
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jordanlewis
Copy link
Member

LGTM

When performing constant folding, we will now always evaluate unary
negatives right away. To facilitate this, this commit extracts a NumExpr
interface that is implemented by *NumVal. The new interface has methods
to access the constant.Value of the *NumVal, and this accessor always
will perform the necessary unary negation operator.

This works because unary negation has high precedence (only preceded by
the typecast operation).

This change requires us to inspect the Negative flags of both the Expr
and inner Decimal value when resolving a NumExpr that contains a
Decimal, since on some operations like division, the negative value will
now get folded into the Decimal.

Many eval tests are added to ensure compatibility with Postgres.

Tests are not backported since there have been significant changes in
testing infrastructure.

Release note (bug fix): unary negatives in constant arithmetic expressions
are no longer ignored.
@rafiss rafiss merged commit 1051f37 into cockroachdb:release-2.1 Aug 7, 2019
@rafiss rafiss deleted the backport2.1-39245 branch August 7, 2019 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants