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

Provide same results for date arithmetics when date is changed by values near +/-max(bigint) [CORE6504] #6734

Closed
firebird-automations opened this issue Mar 5, 2021 · 13 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @pavel-zotov

Attachments:
date-arithmetic-with-changing-date-for-power_2_63-days_-_overall-results-for-FB-3.x-and-4.x.xlsx

Ticked was created after discuss results of test for CORE624 with Alex and Vlad.

Following statements show different results on FB 3.x and 4.x when date is decremented by values = ~2^63.
See also attached .xlsx with overall results in one table.

Database and client dialect = 3.

#⁠#⁠#⁠ A. DECREMENT date #⁠#⁠#⁠

Linux

1) LI-V4.0.0.2379

echo "set heading off; select date '01.02.2020' + -9223372036854775807 from rdb\$database;" | /var/tmp/fb40tmp/bin/isql employee
Statement failed, SQLSTATE = 22008
value exceeds the range for valid dates

echo "set heading off; select date '01.02.2020' + -9223372036854775808 from rdb\$database;" | /var/tmp/fb40tmp/bin/isql employee
2020-02-01

--------------------------------------------

2) LI-V3.0.8.33415

echo "set heading off; select date '01.02.2020' + -9223372036854775807 from rdb\$database;" | /var/tmp/fb30tmp/bin/isql employee -z
2020-02-02

echo "set heading off; select date '01.02.2020' + -9223372036854775808 from rdb\$database;" | /var/tmp/fb30tmp/bin/isql employee -z
2020-02-01

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Windows

1) WI-V4.0.0.2377

C:\FB\40SS>echo set heading off; select date '01.02.2020' - +9223372036854775807 from rdb$database; | isql employee
Statement failed, SQLSTATE = 22008
value exceeds the range for valid dates

C:\FB\40SS>echo set heading off; select date '01.02.2020' + -9223372036854775808 from rdb$database; | isql /:employee
Statement failed, SQLSTATE = 22008
value exceeds the range for valid dates

--------------------------------------------

2) WI-V3.0.8.33423

C:\FB\30SS>echo set heading off; select date '01.02.2020' - -9223372036854775807 from rdb$database; | isql employee -z
2020-01-31

SQL>
C:\FB\30SS>echo set heading off; select date '01.02.2020' - -9223372036854775808 from rdb$database; | isql employee -z
2020-02-01

#⁠#⁠#⁠ B. INCREMENT date #⁠#⁠#⁠

Linux

1)build LI-V4.0.0.2379

echo "set heading off; select date '01.02.2020' + 9223372036854775807 from rdb\$database;" | /var/tmp/fb40tmp/bin/isql employee -z
Statement failed, SQLSTATE = 22008
value exceeds the range for valid dates

echo "set heading off; select date '01.02.2020' - (-9223372036854775808) from rdb\$database;" | /var/tmp/fb40tmp/bin/isql employee -z
2020-02-01

--------------------------------------------

2) LI-V3.0.8.33415

echo "set heading off; select date '01.02.2020' + 9223372036854775807 from rdb\$database;" | /var/tmp/fb30tmp/bin/isql employee -z
2020-01-31

echo "set heading off; select date '01.02.2020' - (-9223372036854775808) from rdb\$database;" | /var/tmp/fb30tmp/bin/isql employee -z
2020-02-01

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Windows

1) WI-V4.0.0.2377

C:\FB\40SS>echo set heading off; select date '01.02.2020' + 9223372036854775807 from rdb$database; | isql employee -z
Statement failed, SQLSTATE = 22008
value exceeds the range for valid dates

C:\FB\40SS>echo set heading off; select date '01.02.2020' - (-9223372036854775808) from rdb$database; | isql employee -z
Statement failed, SQLSTATE = 22008
value exceeds the range for valid dates

2) WI-V3.0.8.33423

C:\FB\30SS>echo set heading off; select date '01.02.2020' + 9223372036854775807 from rdb$database; | isql employee -z
2020-01-31

SQL>
C:\FB\30SS>echo set heading off; select date '01.02.2020' - (-9223372036854775808) from rdb$database; | isql employee -z
2020-02-01

Commits: 7d2b34e

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

priority: Major [ 3 ] => Minor [ 4 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

Attachment: date-arithmetic-with-changing-date-for-power_2_63-days_-_overall-results-for-FB-3.x-and-4.x.xlsx [ 13553 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

What is the problem with FB 4?

Why it's not correct raising error?

You probably wanted to mention another ticket as CORE624 has nothing to do with this.

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

> What is the problem with FB 4?
> Why it's not correct raising error?

IMO, raising error is exactly what must be done.

But FB 4.x allows this:
echo "set heading off; select date '01.02.2020' + -9223372036854775808 from rdb\$database;" | /var/tmp/fb40tmp/bin/isql employee
(output will be 2020-02-01)

> You probably wanted to mention another ticket as CORE624 has nothing to do with thi

Yes, sorry for unprinted character: I meant CORE6241.
This is the only ticket which .fbt test has different results on Windows vs Linux for FB 4.x (passes on Windows but fails on Linux).

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

Pavel, are you sure?

I've tested this command in v4 RC1, master and 4.0.0.2379 (all in Linux - with gcc and clang) and in all versions it raises an error.

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

Alex, official Linux binaries presents this problem (no error is raised), while my own binaries and one download from github action raises error.

May be we're having a compiler problem?

We're talking about ExprNodes.cpp:

	d1 = MOV\_get\_int64\(tdbb, &value\-\>vlu\_desc, 0\);

	if \(fb\_utils::abs64Compare\(d1, TimeStamp::MAX\_DATE \- TimeStamp::MIN\_DATE\) \> 0\)
		ERR\_post\(Arg::Gds\(isc\_date\_range\_exceeded\)\);

And utils_proto.h:

// Compare the absolute value of two SINT64 numbers\.
// Return 0 if they are equal, <0 if n1 < n2 and \>0 if n1 \> n2\.
inline int abs64Compare\(SINT64 n1, SINT64 n2\)
\{
	n1 = n1 \> 0 ? \-n1 : n1;
	n2 = n2 \> 0 ? \-n2 : n2;
	return n1 == n2 ? 0 : n1 < n2 ? 1 : \-1;
\}

The code does not appear for me to have undefined behaviors.

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

assignee: Alexander Peshkov [ alexpeshkoff ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @AlexPeshkoff

Definitely compiler issue, moreover - optimization issue, in DEV_BUILD error is raised.

@firebird-automations
Copy link
Collaborator Author

Commented by: @AlexPeshkoff

Very old and long-existed bug, was fixed only in gcc10 (i.e. gcc 6, 7, 8, 9 are vulnerable). Luckily installing gcc10 does not require upgrade of glibc & binutils.

@firebird-automations
Copy link
Collaborator Author

Commented by: @AlexPeshkoff

Added check for values causing buggy result in a case when compiler has that bug

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 4.0.0 [ 10931 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Resolved [ 5 ]

QA Status: No test => Done successfully

Test Specifics: [Platform (Windows/Linux) specific]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Closed [ 6 ]

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

No branches or pull requests

2 participants