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: change volatility of timezone with TIME and TIMETZ to stable #51037

Merged
merged 1 commit into from
Jul 7, 2020

Conversation

mgartner
Copy link
Collaborator

@mgartner mgartner commented Jul 7, 2020

sql: change volatility of timezone with TIME and TIMETZ to stable

The timezone(STRING, TIME) and timezone(STRING, TIMETZ) function
overloads were originally marked as volatile to copy Postgres's
volatility for the timezone(STRING, TIMETZ) overload (Postgres does
not implement timezone (STRING, TIME).

Postgres's volatility settings for all overloads of timezone are
below.

   Name   |          Argument data types          | Volatility
----------+---------------------------------------+------------------
 timezone | interval, time with time zone         | immutable   zone
 timezone | interval, timestamp with time zone    | immutable
 timezone | interval, timestamp without time zone | immutable
 timezone | text, time with time zone             | volatile    zone
 timezone | text, timestamp with time zone        | immutable
 timezone | text, timestamp without time zone     | immutable

This single overload is singled out as volatile by Postgres because it
is dependent on C's time(NULL). See the Postgres commit originally
marking this overload volatility, and the lines of code showing the
dependence:

postgres/postgres@35979e6
https://github.com/postgres/postgres/blob/ac3a4866c0bf1d7a14009f18d3b42ffcb063a7e9/src/backend/utils/adt/date.c#L2816

CRDB does not have the same issue. All timezone overloads have the
same volatility, stable. This commit marks them as such.

Additional context: #48756 (comment)

This commit also moves the IgnoreVolatilityCheck field from function
definitions to overloads. This allows overloads of the same function to
be ignored when asserting that the volalitity of an overload matches
Postgres's assigned volatility.

Release note: None

@mgartner mgartner requested review from otan and RaduBerinde July 7, 2020 00:35
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@mgartner mgartner force-pushed the timetz-volatility branch from 6a3c80e to 68d7bd2 Compare July 7, 2020 00:36
@@ -2407,7 +2407,8 @@ may increase either contention or retry errors, or both.`,
),

// https://www.postgresql.org/docs/9.6/functions-datetime.html
"timezone": makeBuiltin(defProps(),
"timezone": makeBuiltin(
tree.FunctionProperties{IgnoreVolatilityCheck: true},
Copy link
Contributor

@otan otan Jul 7, 2020

Choose a reason for hiding this comment

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

do you mind adding a comment linking to the issue here so it's easier to reconcile the justification?
also wondering if this ignore should be at the overload level, leave that up to you though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ya I think it should be at the overload level because that's where volatility is defined. I'll make the change.

The `timezone(STRING, TIME)` and `timezone(STRING, TIMETZ)` function
overloads were originally marked as volatile to copy Postgres's
volatility for the `timezone(STRING, TIMETZ)` overload (Postgres does
not implement `timezone (STRING, TIME)`.

Postgres's volatility settings for all overloads of `timezone` are
below.

       Name   |          Argument data types          | Volatility
    ----------+---------------------------------------+------------------
     timezone | interval, time with time zone         | immutable   zone
     timezone | interval, timestamp with time zone    | immutable
     timezone | interval, timestamp without time zone | immutable
     timezone | text, time with time zone             | volatile    zone
     timezone | text, timestamp with time zone        | immutable
     timezone | text, timestamp without time zone     | immutable

This single overload is singled out as volatile by Postgres because it
is dependent on C's `time(NULL)`. See the Postgres commit originally
marking this overload volatility, and the lines of code showing the
dependence:

postgres/postgres@35979e6
https://github.com/postgres/postgres/blob/ac3a4866c0bf1d7a14009f18d3b42ffcb063a7e9/src/backend/utils/adt/date.c#L2816

CRDB does not have the same issue. All `timezone` overloads have the
same volatility, stable. This commit marks them as such.

Additional context: cockroachdb#48756 (comment)

This commit also moves the `IgnoreVolatilityCheck` field from function
definitions to overloads. This allows overloads of the same function to
be ignored when asserting that the volalitity of an overload matches
Postgres's assigned volatility.

Release note: None
@mgartner mgartner force-pushed the timetz-volatility branch from 68d7bd2 to f949158 Compare July 7, 2020 17:06
@blathers-crl blathers-crl bot requested a review from otan July 7, 2020 17:06
Copy link
Contributor

@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.

looks lgtm to me

@mgartner
Copy link
Collaborator Author

mgartner commented Jul 7, 2020

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 7, 2020

Build failed (retrying...)

@craig
Copy link
Contributor

craig bot commented Jul 7, 2020

Build succeeded

@craig craig bot merged commit 6893785 into cockroachdb:master Jul 7, 2020
@mgartner mgartner deleted the timetz-volatility branch July 7, 2020 22:38
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.

4 participants