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

sql: internal error: (-0E-2019):::DECIMAL: could not evaluate -0E-2019 as Datum type DDecimal from string "0E-2019": could not parse "0E-2019" as type decimal #40929

Closed
maddyblue opened this issue Sep 19, 2019 · 7 comments · Fixed by #106472
Assignees
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. C-test-failure Broken test (automatically or manually discovered). O-sqlsmith S-3-erroneous-edge-case Database produces or stores erroneous data without visible error/warning, in rare edge cases. T-sql-queries SQL Queries Team

Comments

@maddyblue
Copy link
Contributor

maddyblue commented Sep 19, 2019

CREATE TABLE IF NOT EXISTS tab_orig AS
	SELECT g FROM generate_series(NULL, NULL) AS g;

SELECT 0 / '-Infinity'::DECIMAL FROM tab_orig;
stack trace:
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/expr.go:78: processExpression()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/expr.go:161: Init()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:145: Init()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:776: InitWithEvalCtx()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:752: Init()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/rowexec/tablereader.go:92: newTableReader()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/rowexec/processors.go:138: NewProcessor()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/rowflow/row_based_flow.go:165: makeProcessor()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/rowflow/row_based_flow.go:65: setupProcessors()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/rowflow/row_based_flow.go:48: Setup()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql/server.go:331: setupFlow()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql/server.go:404: SetupLocalSyncFlow()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:241: setupFlows()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:330: Run()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:966: PlanAndRun()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:826: execWithDistSQLEngine()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:718: dispatchToExecutionEngine()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:417: execStmtInOpenState()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:98: execStmt()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1238: execCmd()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1167: run()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:444: ServeConn()
/home/mjibson/go/src/github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:584: func1()
runtime/asm_amd64.s:1337: goexit()

Jira issue: CRDB-5499

@maddyblue maddyblue added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sqlsmith labels Sep 19, 2019
@rafiss
Copy link
Collaborator

rafiss commented Sep 23, 2019

This started happening because of the change made in #40327

That PR changes func (d *DDecimal) SetString(s string) error in datum.go so that it uses ExactCtx instead of HighPrecisionCtx.

I think the issue is that the division is performed using DecimalCtx, which results in a value of 0E-2019, but ExactCtx is not able to handle that value.

@rafiss rafiss added the S-3-erroneous-edge-case Database produces or stores erroneous data without visible error/warning, in rare edge cases. label Sep 24, 2019
@maddyblue
Copy link
Contributor Author

The postgres spec for decimals is "up to 131072 digits before the decimal point; up to 16383 digits after the decimal point" (used when there is no user-specified precision) and "the maximum allowed precision when explicitly specified in the type declaration is 1000".

We could constrain our decimal use to those specs, and in addition remove our support for infinity, which is not supported by postgres decimals (and thus has no binary encoding).

@maddyblue
Copy link
Contributor Author

As a side effect of not having infinity, the above query will stop failing for this reason.

@rafiss rafiss removed their assignment Jan 28, 2020
yuzefovich added a commit to yuzefovich/cockroach that referenced this issue Mar 22, 2021
This commit skips failing `sqlsmith` roachtest because of a known issue
(cockroachdb#40929) in order to avoid unnecessary noise.

Release note: None
yuzefovich added a commit to yuzefovich/cockroach that referenced this issue Mar 23, 2021
This commit makes `sqlsmith` roachtest not fail on one known issue (cockroachdb#40929)
in order to avoid unnecessary noise.

Release note: None
@otan
Copy link
Contributor

otan commented May 22, 2023

this no longer panics, but produces an incorrect result. marking as duplicate of #103633

@otan otan closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2023
@yuzefovich
Copy link
Member

It's still reproducible in distributed setting (as Rafi pointed out above).

@yuzefovich yuzefovich reopened this May 30, 2023
@yuzefovich yuzefovich added the C-test-failure Broken test (automatically or manually discovered). label Jul 6, 2023
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Jul 8, 2023
Previously, the logic for decimal and float division, floor division
and mod operators was incorrect for a few edge cases involving `NaN`
or `Infinity` values. For example, `'NaN'::DECIMAL / 0` would throw
a division-by-zero error when it should evaluate to `NaN` and
`0/'inf'::DECIMAL` returned `0E-2019` instead of just `0`.

This patch updates the special-case logic to mirror that of postgres,
so division-by-zero errors always check the `NaN` case and the division
by infinity case returns a `0` without extra digits.

Fixes cockroachdb#40929
Fixes cockroachdb#103633

Release note (bug fix): Fixed edge cases in decimal and float evaluation
for division operators. `'NaN'::DECIMAL / 0` will now return `NaN` instead
of a division-by-zero error, and `0 / 'inf'::DECIMAL` will return `0`
instead of `0E-2019`.
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Jul 10, 2023
Previously, the logic for decimal and float division, floor division
and mod operators was incorrect for a few edge cases involving `NaN`
or `Infinity` values. For example, `'NaN'::DECIMAL / 0` would throw
a division-by-zero error when it should evaluate to `NaN` and
`0/'inf'::DECIMAL` returned `0E-2019` instead of just `0`.

This patch updates the special-case logic to mirror that of postgres,
so division-by-zero errors always check the `NaN` case and the division
by infinity case returns a `0` without extra digits.

Fixes cockroachdb#40929
Fixes cockroachdb#103633

Release note (bug fix): Fixed edge cases in decimal and float evaluation
for division operators. `'NaN'::DECIMAL / 0` will now return `NaN` instead
of a division-by-zero error, and `0 / 'inf'::DECIMAL` will return `0`
instead of `0E-2019`.
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Jul 10, 2023
Previously, the logic for decimal and float division, floor division
and mod operators was incorrect for a few edge cases involving `NaN`
or `Infinity` values. For example, `'NaN'::DECIMAL / 0` would throw
a division-by-zero error when it should evaluate to `NaN` and
`0/'inf'::DECIMAL` returned `0E-2019` instead of just `0`.

This patch updates the special-case logic to mirror that of postgres,
so division-by-zero errors always check the `NaN` case and the division
by infinity case returns a `0` without extra digits.

Fixes cockroachdb#40929
Fixes cockroachdb#103633

Release note (bug fix): Fixed edge cases in decimal and float evaluation
for division operators. `'NaN'::DECIMAL / 0` will now return `NaN` instead
of a division-by-zero error, and `0 / 'inf'::DECIMAL` will return `0`
instead of `0E-2019`.
@DrewKimball DrewKimball self-assigned this Jul 11, 2023
craig bot pushed a commit that referenced this issue Jul 13, 2023
106472: sql: fix decimal evaluation edge cases r=DrewKimball a=DrewKimball

Previously, the logic for decimal and float division, floor division and mod operators was incorrect for a few edge cases involving `NaN` or `Infinity` values. For example, `'NaN'::DECIMAL / 0` would throw a division-by-zero error when it should evaluate to `NaN` and `0/'inf'::DECIMAL` returned `0E-2019` instead of just `0`.

This patch updates the special-case logic to mirror that of postgres, so division-by-zero errors always check the `NaN` case and the division by infinity case returns a `0` without extra digits.

Fixes #40929
Fixes #103633

Release note (bug fix): Fixed edge cases in decimal and float evaluation for division operators. `'NaN'::DECIMAL / 0` will now return `NaN` instead of a division-by-zero error, and `0 / 'inf'::DECIMAL` will return `0` instead of `0E-2019`.

106790: tree: fix statement tag for tree.ShowSequences r=knz,rafiss a=andyyang890

Epic: None

Release note (bug fix): The statement tag for `SHOW SEQUENCES` is now
corrected to be `SHOW SEQUENCES` instead of `SHOW SCHEMAS`.

Co-authored-by: Drew Kimball <[email protected]>
Co-authored-by: Andy Yang <[email protected]>
@craig craig bot closed this as completed in a8b42c9 Jul 14, 2023
@mgartner mgartner moved this to Done in SQL Queries Jul 24, 2023
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Sep 9, 2023
Previously, the logic for decimal and float division, floor division
and mod operators was incorrect for a few edge cases involving `NaN`
or `Infinity` values. For example, `'NaN'::DECIMAL / 0` would throw
a division-by-zero error when it should evaluate to `NaN` and
`0/'inf'::DECIMAL` returned `0E-2019` instead of just `0`.

This patch updates the special-case logic to mirror that of postgres,
so division-by-zero errors always check the `NaN` case and the division
by infinity case returns a `0` without extra digits.

Fixes cockroachdb#40929
Fixes cockroachdb#103633

Release note (bug fix): Fixed edge cases in decimal and float evaluation
for division operators. `'NaN'::DECIMAL / 0` will now return `NaN` instead
of a division-by-zero error, and `0 / 'inf'::DECIMAL` will return `0`
instead of `0E-2019`.
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Sep 12, 2023
Previously, the logic for decimal and float division, floor division
and mod operators was incorrect for a few edge cases involving `NaN`
or `Infinity` values. For example, `'NaN'::DECIMAL / 0` would throw
a division-by-zero error when it should evaluate to `NaN` and
`0/'inf'::DECIMAL` returned `0E-2019` instead of just `0`.

This patch updates the special-case logic to mirror that of postgres,
so division-by-zero errors always check the `NaN` case and the division
by infinity case returns a `0` without extra digits.

Fixes cockroachdb#40929
Fixes cockroachdb#103633

Release note (bug fix): Fixed edge cases in decimal and float evaluation
for division operators. `'NaN'::DECIMAL / 0` will now return `NaN` instead
of a division-by-zero error, and `0 / 'inf'::DECIMAL` will return `0`
instead of `0E-2019`.
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Sep 12, 2023
Previously, the logic for decimal and float division, floor division
and mod operators was incorrect for a few edge cases involving `NaN`
or `Infinity` values. For example, `'NaN'::DECIMAL / 0` would throw
a division-by-zero error when it should evaluate to `NaN` and
`0/'inf'::DECIMAL` returned `0E-2019` instead of just `0`.

This patch updates the special-case logic to mirror that of postgres,
so division-by-zero errors always check the `NaN` case and the division
by infinity case returns a `0` without extra digits.

Fixes cockroachdb#40929
Fixes cockroachdb#103633

Release note (bug fix): Fixed edge cases in decimal and float evaluation
for division operators. `'NaN'::DECIMAL / 0` will now return `NaN` instead
of a division-by-zero error, and `0 / 'inf'::DECIMAL` will return `0`
instead of `0E-2019`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. C-test-failure Broken test (automatically or manually discovered). O-sqlsmith S-3-erroneous-edge-case Database produces or stores erroneous data without visible error/warning, in rare edge cases. T-sql-queries SQL Queries Team
Projects
Archived in project
6 participants