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

Support AS OF SYSTEM TIME syntax #11703

Closed
shenli opened this issue Aug 9, 2019 · 5 comments
Closed

Support AS OF SYSTEM TIME syntax #11703

shenli opened this issue Aug 9, 2019 · 5 comments
Labels
duplicate Issues or pull requests already exists. feature/accepted This feature request is accepted by product managers type/enhancement The issue or PR belongs to an enhancement. type/feature-request Categorizes issue or PR as related to a new feature.

Comments

@shenli
Copy link
Member

shenli commented Aug 9, 2019

Feature Request

Is your feature request related to a problem? Please describe:
Reading historical data requires setting a system variable. This has two problems:

  1. It is not convenient to use a separate SET statement to set the snapshot version.
  2. Session context is weird in go - since the SQL driver will pool connections unless you start an explicit transaction.

Describe the feature you'd like:
Support the AS OF SYSTEM TIME syntax like sql-server.
CockroachDB and BigQuery also supports syntax like that.

Describe alternatives you've considered:
No

Teachability, Documentation, Adoption, Migration Strategy:
No

@shenli shenli added the type/enhancement The issue or PR belongs to an enhancement. label Aug 9, 2019
@shenli shenli added this to the v5.0-alpha.1 milestone Jun 29, 2020
@wwar
Copy link

wwar commented Jun 30, 2020

CockroachDB also has a handy helper-function: experimental_follower_read_timestamp().

This automatically enables follower reads, up to the most recent point possible. I think it's a lot more convenient than explicitly enabling follower reads.

@scsldb scsldb modified the milestones: v5.0.0-alpha.1-tmp, pools Jul 15, 2020
@kennytm
Copy link
Contributor

kennytm commented Jul 17, 2020

If we support MySQL 8.0's SET_VAR optimizer hint (#7968), we could have the following alternative syntax:

SELECT /*+ SET_VAR(tidb_snapshot = 1234567890) */ * FROM t;

@zz-jason
Copy link
Member

If we support MySQL 8.0's SET_VAR optimizer hint (#7968), we could have the following alternative syntax:

SELECT /*+ SET_VAR(tidb_snapshot = 1234567890) */ * FROM t;

We can regard this hint as a workaround temporally. The AS OF SYSTEM TIME syntax can be supported in non-DML or DQL statements. For example, in AS OF SYSTEM TIME - CockroachDB:

The AS OF SYSTEM TIME clause is supported in multiple SQL contexts, including but not limited to:

In SELECT clauses, at the very end of the FROM sub-clause.
In BACKUP, after the parameters of the TO sub-clause.
In RESTORE, after the parameters of the FROM sub-clause.
In BEGIN, after the BEGIN keyword.
In SET, after the SET TRANSACTION keyword.

In BigQuery, it is FOR SYSTEM_TIME AS OF. From the SQL Syntax, seems it's only supported in the SELECT statements, can only appear after the FROM sub-clause:

from_item: {
    table_name [ [ AS ] alias ] [ FOR SYSTEM_TIME AS OF timestamp_expression ]  |
    join |
    ( query_expr ) [ [ AS ] alias ] |
    field_path |
    { UNNEST( array_expression ) | UNNEST( array_path ) | array_path }
        [ [ AS ] alias ] [ WITH OFFSET [ [ AS ] alias ] ] |
    with_query_name [ [ AS ] alias ]
}

@ghost
Copy link

ghost commented Jul 26, 2020

Another potential behavior difference between dedicated syntax and hints, is that hints typically only generate warnings at most. If using AS OF SYSTEM TIME, I think it would be appropriate to generate an error if the snapshot time can not be provided.

@zz-jason zz-jason added the feature/reviewing This feature request is reviewing by product managers label Aug 6, 2020
@ghost ghost added the type/feature-request Categorizes issue or PR as related to a new feature. label Aug 6, 2020
@zz-jason zz-jason added feature/discussing This feature request is discussing among product managers and removed feature/reviewing This feature request is reviewing by product managers labels Aug 10, 2020
@zz-jason zz-jason removed their assignment Aug 28, 2020
@zz-jason zz-jason added feature/accepted This feature request is accepted by product managers and removed feature/discussing This feature request is discussing among product managers labels Aug 28, 2020
@scsldb
Copy link

scsldb commented Sep 4, 2020

duplicate #18672

@scsldb scsldb closed this as completed Sep 4, 2020
@scsldb scsldb removed this from the Requirement pool milestone Sep 4, 2020
@ghost ghost added the duplicate Issues or pull requests already exists. label Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues or pull requests already exists. feature/accepted This feature request is accepted by product managers type/enhancement The issue or PR belongs to an enhancement. type/feature-request Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

5 participants