Skip to content

sql: add precision support for TIMESTAMP/TIMESTAMPTZ (v2)#42580

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
otan-cockroach:otan-precision_v2
Nov 21, 2019
Merged

sql: add precision support for TIMESTAMP/TIMESTAMPTZ (v2)#42580
craig[bot] merged 1 commit intocockroachdb:masterfrom
otan-cockroach:otan-precision_v2

Conversation

@otan
Copy link
Copy Markdown
Contributor

@otan otan commented Nov 19, 2019

Refs #32098
Alternative to #42552


Add precision support for TIMESTAMP/TIMESTAMPTZ, supporting precisions
from 0 to 6 inclusive.

When storing this in the type proto, we introduce a TimePrecisionIsSet
variable, which is used to differentiate 0 (unset) or 0 (explicitly set)
for time related protos. This is abstracted away in the Precision()
function which returns the correct precision (unset => 6) for time. This
allows forwards and backwards compatibility.

Note Time will come later, as it involves a bit more plumbing to the
base library.

Release note (sql change): Introduces precision support for TIMESTAMP
and TIMESTAMPTZ, supporting precisions from 0 to 6 inclusive. Previous
versions of TIMESTAMP and TIMESTAMPTZ will default to 6 units of
precision. Note that if anyone downgrades whilst having precision set,
they will have full precision (6) again, but if they re-upgrade they
will find their precisions truncated again.

@otan otan requested review from a team, rohany and solongordon November 19, 2019 22:26
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@otan otan force-pushed the otan-precision_v2 branch 2 times, most recently from 7b15353 to 58237f4 Compare November 19, 2019 23:28
@otan otan requested a review from a team as a code owner November 19, 2019 23:28
@otan otan force-pushed the otan-precision_v2 branch 2 times, most recently from acba26b to 9834dca Compare November 20, 2019 17:35
Copy link
Copy Markdown
Contributor

@solongordon solongordon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits but generally looks great!

Reviewed 19 of 19 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @otan and @rohany)


pkg/sql/sem/tree/datum.go, line 2118 at r1 (raw file):

}

// Round returns a new DTimestampTZ to the specified precision.

Nit: DTimestamp


pkg/sql/sem/tree/time_test.go, line 21 at r1 (raw file):

)

func TestPrecisionToTruncDuration(t *testing.T) {

Nit: misnamed?


pkg/sql/types/types.go, line 701 at r1 (raw file):

// the given number of fractional second digits.
//
// If precision is -1, it will return the default precision.

I may be missing something but what is the purpose of accepting -1? Seems like it is only passed by tests, which could just use Timestamp instead.


pkg/sql/types/types.go, line 720 at r1 (raw file):

// most the given number of fractional second digits.
//
// If precision is -1, it will return the default precision.

Same question about accepting -1.


pkg/sql/types/types.proto, line 408 at r1 (raw file):

    //   * If Precision is 0, it will default to 6 if TimePrecisionIsSet is false
    //    (for compatibility reasons).
    //   * Otherwise, the precision is 6.

Did you mean 0?

@solongordon
Copy link
Copy Markdown
Contributor

One more thought: when we discovered that the previous implementation of this was not backward compatible, @andy-kimball highlighted that we have Marshal and Unmarshal functions in types.go intended for managing backward compatibility between protobuf versions. I think it's unnecessary to modify those here because your changes are already backward compatible, but perhaps worth a look to double-check.

Copy link
Copy Markdown
Contributor Author

@otan otan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that would've been useful as well, but I think with the way this is done we don't have to bother with doing that.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rohany and @solongordon)


pkg/sql/types/types.go, line 701 at r1 (raw file):

Previously, solongordon (Solon) wrote…

I may be missing something but what is the purpose of accepting -1? Seems like it is only passed by tests, which could just use Timestamp instead.

Yeah I think that's cleaner. changing!


pkg/sql/types/types.go, line 720 at r1 (raw file):

Previously, solongordon (Solon) wrote…

Same question about accepting -1.

Done.


pkg/sql/types/types.proto, line 408 at r1 (raw file):

Previously, solongordon (Solon) wrote…

Did you mean 0?

Yes. Fixed!

@otan otan force-pushed the otan-precision_v2 branch from 9834dca to 8d8e303 Compare November 20, 2019 23:12
@otan otan requested a review from solongordon November 20, 2019 23:12
Copy link
Copy Markdown
Contributor

@solongordon solongordon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Your commit message still references the -1 business.

:lgtm: modulo a couple nits!

Reviewed 2 of 6 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @otan, @rohany, and @solongordon)


pkg/sql/types/types.go, line 711 at r2 (raw file):

// most the given number of fractional second digits.
//
// To use the default, use the `Timestamp` variable.

Nit: TimestampTZ

Copy link
Copy Markdown
Contributor

@solongordon solongordon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I believe the intention is to backport this fix to the release-19.2 branch. (See https://github.com/benesch/backport to make this process easy.)

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @otan, @rohany, and @solongordon)

@otan otan force-pushed the otan-precision_v2 branch from 8d8e303 to 1b5668d Compare November 20, 2019 23:31
Add precision support for TIMESTAMP/TIMESTAMPTZ, supporting precisions
from 0 to 6 inclusive.

When storing this in the type proto, we introduce a `TimePrecisionIsSet`
variable, which is used to differentiate 0 (unset) or 0 (explicitly set)
for time related protos. This is abstracted away in the `Precision()`
function which returns the correct precision (unset => 6) for time. This
allows forwards and backwards compatibility.

Note Time will come later, as it involves a bit more plumbing to the
base library.

Release note (sql change): Introduces precision support for TIMESTAMP
and TIMESTAMPTZ, supporting precisions from 0 to 6 inclusive. Previous
versions of TIMESTAMP and TIMESTAMPTZ will default to 6 units of
precision. Note that if anyone downgrades whilst having precision set,
they will have full precision (6) again, but if they re-upgrade they
will find their precisions truncated again.
@otan otan force-pushed the otan-precision_v2 branch from 1b5668d to a8994c9 Compare November 20, 2019 23:32
Copy link
Copy Markdown
Contributor Author

@otan otan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure about backporting this? Seems like a strictly new feature instead of a bug fix?

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @rohany and @solongordon)

@otan
Copy link
Copy Markdown
Contributor Author

otan commented Nov 20, 2019

we can discuss the backporting afterwards - thanks for the review!

bors r+

craig bot pushed a commit that referenced this pull request Nov 21, 2019
41788: storage/rangefeed: push rangefeed.Filter into Raft processing goroutine r=danhhz a=nvanbenschoten

This commit creates a `rangefeed.Filter` object, which informs the producer of logical operations of the information that a `rangefeed.Processor` is interested in, given its current set of registrations. It can be used to avoid performing extra work to provide the Processor with information which will be ignored.

This is an important optimization for single-key or small key span rangefeeds, as it avoids some extraneous work for the key spans not being watched.

For now, this extra work is just fetching the post-operation value for `MVCCWriteValueOp` and `MVCCCommitIntentOp` operations, but this can be extended in the future to include the pre-operation value as well. This will be important to avoid any perf regression when addressing #28666.

42580: sql: add precision support for TIMESTAMP/TIMESTAMPTZ (v2) r=otan a=otan

Refs #32098
Alternative to #42552

----

Add precision support for TIMESTAMP/TIMESTAMPTZ, supporting precisions
from 0 to 6 inclusive.

When storing this in the type proto, we introduce a `TimePrecisionIsSet`
variable, which is used to differentiate 0 (unset) or 0 (explicitly set)
for time related protos. This is abstracted away in the `Precision()`
function which returns the correct precision (unset => 6) for time. This
allows forwards and backwards compatibility.

Note Time will come later, as it involves a bit more plumbing to the
base library.

Release note (sql change): Introduces precision support for TIMESTAMP
and TIMESTAMPTZ, supporting precisions from 0 to 6 inclusive. Previous
versions of TIMESTAMP and TIMESTAMPTZ will default to 6 units of
precision. Note that if anyone downgrades whilst having precision set,
they will have full precision (6) again, but if they re-upgrade they
will find their precisions truncated again.

Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
Co-authored-by: Oliver Tan <otan@cockroachlabs.com>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Nov 21, 2019

Build succeeded

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.

3 participants