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

docs: RFC for better staleness read syntax. #22506

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions docs/design/2021-01-24-staleness-read-syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Proposal: Change timestamp bounds read syntax for read only transaction

- Author(s): [Xiaoguang Sun](https://github.com/sunxiaoguang)
- Last updated: 2021-01-24
- Discussion at: https://github.com/pingcap/tidb/issues/22505

## Abstract

This proposal proposes new syntax to staleness read and deprecates existing timestamp bounds read SQL syntax which is over complicate.

## Background

Existing timestamp bound read SQL syntax is verbose and complicate.

```sql
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND STRONG
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND MAX STALENESS '00:00:10'
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND EXACT STALENESS '00:00:05'
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND READ TIMESTAMP '2019-11-04 00:00:00'
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND MIN READ TIMESTAMP '2019-11-04 00:00:00'
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND MIN TIMESTAMP '2019-11-04 00:00:00'
```

Since timestamp bounds read feature is never implemented on TiDB, it is a good time to fix it with a better design and make it more ergonomics.

## Proposal

Make it clear that staleness read can be used only when transaction is read-only. If the transaction contains any writes an error will be returned. Therefore ```READ ONLY``` and ```TIMESTAMP BOUND``` are unnecessary and can be removed. The new statements will become shorter:

```sql
START TRANSACTION WITH MAX STALENESS '00:00:10'
START TRANSACTION WITH EXACT STALENESS '00:00:05'
START TRANSACTION WITH TIMESTAMP '2019-11-04 00:00:00'
```


## Rationale

```sql
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND STRONG
```

These statements are equivalent to START TRANSACTION READ ONLY, therefore can be removed.

```sql
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND MAX STALENESS '00:00:10'
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND EXACT STALENESS '00:00:05'
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND READ TIMESTAMP '2019-11-04 00:00:00'
```

The redundant words ```READ ONLY``` and ```TIMESTAMP BOUND``` as well as ```READ``` are removed for clarity.
Copy link
Member

Choose a reason for hiding this comment

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

I think READ ONLY warnings the txn must be a read-only transaction, rather than the user may do write operator in the transaction.


```sql
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND MIN READ TIMESTAMP '2019-11-04 00:00:00'
START TRANSACTION READ ONLY WITH TIMESTAMP BOUND MIN TIMESTAMP '2019-11-04 00:00:00'
```

These statements are removed as they are obscured and useless.

## Compatibility and Mirgration Plan
Since existing syntax is never implemented on TiDB, it is unlikely to be used by anyone. We can simply remove current syntax and only support the new syntax.