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: overflow during Encode during insert of large interval #45993

Open
jordanlewis opened this issue Mar 11, 2020 · 7 comments
Open

sql: overflow during Encode during insert of large interval #45993

jordanlewis opened this issue Mar 11, 2020 · 7 comments
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. 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

@jordanlewis
Copy link
Member

jordanlewis commented Mar 11, 2020

The following scenario demonstrates an unusual error:

root@127.0.0.1:55413/defaultdb> create table a (a interval);
CREATE TABLE
root@127.0.0.1:58949/defaultdb> select '40000y'::interval;
   interval
---------------
  40000 years
(1 row)
root@127.0.0.1:55413/defaultdb> insert into a select '40000y'::interval;
ERROR: overflow during Encode
SQLSTATE: 22015

I'd expect this to not fail, or fail in a saner way. Might relate to #26932.

Jira issue: CRDB-5110

@jordanlewis jordanlewis added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. S-3-erroneous-edge-case Database produces or stores erroneous data without visible error/warning, in rare edge cases. labels Mar 11, 2020
@jordanlewis
Copy link
Member Author

@rohany could you take a quick look at this please?

@rohany
Copy link
Contributor

rohany commented Mar 11, 2020

Based on

	// Used in overflow calculations.
	maxYearsInDuration = math.MaxInt64 / nanosInMonth
	minYearsInDuration = math.MinInt64 / nanosInMonth

in pkg/util/duration/duration.go, the max amount of years in a duration is 3558. Since this is larger, it throws an error. We could improve the message though.

@jordanlewis
Copy link
Member Author

Should select '40000y'::interval; be allowed? It works fine at the moment...

@rohany
Copy link
Contributor

rohany commented Mar 11, 2020

We don't have to encode the interval in that case though, so I guess it works.

@jordanlewis
Copy link
Member Author

It works, but... should it be allowed!

@rohany
Copy link
Contributor

rohany commented Mar 11, 2020

Hmm, it seems to me more like a limitation with how we encode intervals (using 3 ints). Perhaps a new encoding scheme wouldn't have these limitations.

@mgartner
Copy link
Collaborator

This is related to #84078.

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. 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
Status: Backlog
SQL Queries
Backlog (DO NOT ADD NEW ISSUES)
Development

No branches or pull requests

4 participants