Skip to content

Commit

Permalink
coexec: normalize the timestamp subtraction like postgres
Browse files Browse the repository at this point in the history
This commit fixes an oversight of #56667 (which fixed the normalization
of the timestamp subtraction) where we forgot to update the vectorized
code path as well. The regression tests added in that PR happened to be
complex enough so that the vectorized engine would fall back to wrapping
a row-by-row processor, so they didn't catch this.

Release note (bug fix): CockroachDB previously would not normalize
`timestamp/timestamptz - timestamp/timestamptz` like Postgres does in
some cases (depending on the query), and this is now fixed.
  • Loading branch information
yuzefovich committed Jul 6, 2022
1 parent 7cfa5d4 commit 52737fb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
8 changes: 4 additions & 4 deletions pkg/sql/colexec/colexecproj/proj_non_const_ops.eg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/sql/colexec/colexecprojconst/proj_const_left_ops.eg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/sql/colexec/colexecprojconst/proj_const_right_ops.eg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/sql/colexec/execgen/cmd/execgen/overloads_bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func (c timestampCustomizer) getBinOpAssignFunc() assignFunc {
case treebin.Minus:
return fmt.Sprintf(`
nanos := %[2]s.Sub(%[3]s).Nanoseconds()
%[1]s = duration.MakeDuration(nanos, 0, 0)
%[1]s = duration.MakeDurationJustifyHours(nanos, 0, 0)
`,
targetElem, leftElem, rightElem)
default:
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/timestamp
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,14 @@ query T
SELECT to_timestamp(NULL)
----
NULL

# Regression test for #83094 (vectorized engine incorrectly formatting an
# interval).
statement ok
CREATE TABLE t (t1 timestamptz, t2 timestamptz);
INSERT INTO t VALUES ('2022-01-01 00:00:00.000000+00:00', '2022-01-02 00:00:00.000000+00:00');

query T
SELECT (t2 - t1) FROM t
----
1 day

0 comments on commit 52737fb

Please sign in to comment.