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: don't use the grammar to enforce expression const-ness in AOST #27206

Merged
merged 1 commit into from
Jul 10, 2018

Conversation

knz
Copy link
Contributor

@knz knz commented Jul 5, 2018

Fixes #26976.

Prior to this patch, AS OF SYSTEM TIME relied on the grammar to
restrict its operand to just constants. This was an unfortunate
approach because it prevented other constant expressions like ('a' || 'b')::INTERVAL (or, encountered during tests, '1ms':::INTERVAL).

This patch corrects this situation by relaxing the grammar constraint
and instead verifying the const-ness of the expression after type
checking.

Release note (sql change): AS OF SYSTEM TIME can now use some more
complex expressions to compute the desired time stamp.

@knz knz requested review from maddyblue and justinj July 5, 2018 10:35
@knz knz requested review from a team July 5, 2018 10:35
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@knz knz force-pushed the 20180705-simplify branch from 35a8995 to 167624d Compare July 5, 2018 10:37
@knz knz force-pushed the 20180705-simplify branch from 167624d to 705ee00 Compare July 5, 2018 13:32
@knz knz requested a review from a team July 5, 2018 13:32
@knz knz changed the title sql: don't use the grammar to enforce expression const-ness sql: don't use the grammar to enforce expression const-ness in AOST Jul 5, 2018
@knz knz force-pushed the 20180705-simplify branch from 705ee00 to b2f3f9d Compare July 5, 2018 13:33
@knz knz added the docs-todo label Jul 5, 2018
@@ -23,6 +23,15 @@ SELECT * FROM t AS OF SYSTEM TIME INTERVAL '-1ns'
----
2

# Verify that we can use computed expressions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Add another test with AOST now() to verify non-constant expressions don't work.

@maddyblue
Copy link
Contributor

Also could you remove the restriction in

if strings.Contains(strings.ToUpper(sql), "AS OF SYSTEM TIME") {
to make sure this fixes the pretty print round trip tests?

craig bot pushed a commit that referenced this pull request Jul 9, 2018
27212: server: clarify TestReportUsage r=knz a=knz

Needed to clarify this and remove the magic constant "16" while working on #27206.

Release note: None

Co-authored-by: Raphael 'kena' Poss <[email protected]>
@knz knz force-pushed the 20180705-simplify branch from b2f3f9d to 4deaceb Compare July 9, 2018 07:21
Copy link
Contributor Author

@knz knz left a comment

Choose a reason for hiding this comment

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

Also could you remove the restriction in cockroach/pkg/testutils/sqlutils/pretty.go Line 30 in ca89c4f

Done

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained


pkg/sql/logictest/testdata/logic_test/as_of, line 26 at r1 (raw file):

Previously, mjibson (Matt Jibson) wrote…

Add another test with AOST now() to verify non-constant expressions don't work.

Done.

Copy link
Contributor

@maddyblue maddyblue left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)

@knz
Copy link
Contributor Author

knz commented Jul 9, 2018 via email

@craig
Copy link
Contributor

craig bot commented Jul 9, 2018

Merge conflict

Prior to this patch, AS OF SYSTEM TIME relied on the grammar to
restrict its operand to just constants. This was an unfortunate
approach because it prevented other constant expressions like `('a' ||
'b')::INTERVAL` (or, encountered during tests, `'1ms':::INTERVAL`).

This patch corrects this situation by relaxing the grammar constraint
and instead verifying the const-ness of the expression after type
checking.

Release note (sql change): AS OF SYSTEM TIME can now use some more
complex expressions to compute the desired time stamp.
@knz knz force-pushed the 20180705-simplify branch from 4deaceb to eb329a4 Compare July 10, 2018 10:16
@knz
Copy link
Contributor Author

knz commented Jul 10, 2018

bors r+

craig bot pushed a commit that referenced this pull request Jul 10, 2018
27206: sql: don't use the grammar to enforce expression const-ness in AOST r=knz a=knz

Fixes  #26976.

Prior to this patch, AS OF SYSTEM TIME relied on the grammar to
restrict its operand to just constants. This was an unfortunate
approach because it prevented other constant expressions like `('a' ||
'b')::INTERVAL` (or, encountered during tests, `'1ms':::INTERVAL`).

This patch corrects this situation by relaxing the grammar constraint
and instead verifying the const-ness of the expression after type
checking.

Release note (sql change): AS OF SYSTEM TIME can now use some more
complex expressions to compute the desired time stamp.

Co-authored-by: Raphael 'kena' Poss <[email protected]>
@craig
Copy link
Contributor

craig bot commented Jul 10, 2018

Build succeeded

@craig craig bot merged commit eb329a4 into cockroachdb:master Jul 10, 2018
@knz knz deleted the 20180705-simplify branch July 10, 2018 11:20
craig bot pushed a commit that referenced this pull request Jul 12, 2018
27214:  sql/parser: remove the now-unused a_expr_const non-terminal  r=knz a=knz

First 3 commits from  #27212, #27206 and  #27213

27434: roachtest: skip tests run on expired clusters r=benesch a=petermattis

Check to see if the cluster is expired before starting a test. Tests are
skipped if the cluster is expired which prevents 1 timed out test from
causing a cascade of issues to be posted for subsequent subtests.

Fixes #27166

Release note: None

Co-authored-by: Raphael 'kena' Poss <[email protected]>
Co-authored-by: Peter Mattis <[email protected]>
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.

3 participants