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: allow relative AS OF queries with a negative interval #24768

Merged
merged 1 commit into from
Apr 15, 2018
Merged

sql: allow relative AS OF queries with a negative interval #24768

merged 1 commit into from
Apr 15, 2018

Conversation

maddyblue
Copy link
Contributor

@maddyblue maddyblue commented Apr 13, 2018

Accept an interval type or a string with a valid interval. The interval
is added to the statement's statement_timestamp() time. This can be
used to run relative AOST queries without calculating the time in
the constant.

Fixes #16424

Release note: AS OF SYSTEM TIME queries now accept a negative interval
to produce a relative time from the statement's statement_timestamp()
time.

@maddyblue maddyblue requested review from knz and a team April 13, 2018 08:30
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@knz
Copy link
Contributor

knz commented Apr 13, 2018

The code is OK but the commit message is incorrect: you are using a computation relative to statement_timestamp(), not now. (now is the txn timestamp).

I say "the code is OK" but did you have any reason to use the statement timestamp instead of the node's current HLC timestamp? They are not the same and I think we must use the HLC timestamp if we want to enable clients to guarantee to be able to read their own writes by other txns.

Beyond that a question not related to this PR: does this make sense to allow any arbitrary ASOT timestamp? It seems to me that it's only meaningful if the ts is in the past and at least MaxOffset old?

Also nit: place the text "Fixes #..." above the release not -- everything after the "release note" prefix goes into the release note.


Reviewed 3 of 3 files at r1.
Review status: all files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@maddyblue
Copy link
Contributor Author

I changed the code to use the hlc Clock.Now() instead of the statement_timestamp() and it broke because when verifying that the timestamp was ok in the planner.getTimestamp func. This happens because the hlc clock is called during the verification of the AOST timestamp and then later when creating the txn. The hlc clock moves since it is called twice and so fails the call. During prepared and not prepared statements the txn timestamp is set differently, and I didn't see an easy way to correctly set this time to be something that wouldn't change. So I think it's ok to use the statement_timestamp time from the evalCtx.

I agree about your assessment about appropriate times, but don't know what to do about it.


Review status: 2 of 3 files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@knz
Copy link
Contributor

knz commented Apr 14, 2018

Ok then you can keep the code as-is but please correct the commit message to mention the statement timestamp. LGTM after that.

Accept an interval type or a string with a valid interval. The interval
is added to the statement's statement_timestamp() time. This can be
used to run relative AOST queries without calculating the time in
the constant.

Fixes #16424

Release note: AS OF SYSTEM TIME queries now accept a negative interval
to produce a relative time from the statement's statement_timestamp()
time.
@maddyblue
Copy link
Contributor Author

bors r+

craig bot pushed a commit that referenced this pull request Apr 15, 2018
24768: sql: allow relative AS OF queries with a negative interval r=mjibson a=mjibson

Accept an interval type or a string with a valid interval. The interval
is added to the statement's statement_timestamp() time. This can be
used to run relative AOST queries without calculating the time in
the constant.

Fixes #16424

Release note: AS OF SYSTEM TIME queries now accept a negative interval
to produce a relative time from the statement's statement_timestamp()
time.

Co-authored-by: Matt Jibson <matt.jibson@gmail.com>
@craig
Copy link
Contributor

craig bot commented Apr 15, 2018

Build succeeded

@craig craig bot merged commit 2e6f4f5 into cockroachdb:master Apr 15, 2018
@danhhz
Copy link
Contributor

danhhz commented Apr 16, 2018

Nice, does this also work with BACKUP? If so, we should probably add it to the docs, since it's currently quite manual to construct the timestamp from 10 seconds ag" that we recommend: https://www.cockroachlabs.com/docs/stable/backup.html#performance

@maddyblue maddyblue deleted the asof-interval branch April 16, 2018 17:51
@maddyblue
Copy link
Contributor Author

Yes, it should work with backup.

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

Successfully merging this pull request may close these issues.

None yet

4 participants