tencent cloud

TDSQL Boundless

Release Notes
Product Introduction
Overview
Scenarios
Product Architecture
Instance Types
Compatibility Notes
Kernel Features
Kernel Overview
Kernel Version Release Notes
Functionality Features
Performance Features
Billing
Billing Overview
Purchase Method
Pricing Details
Renewal
Overdue Payments
Refund
Getting Started
Creating an Instance
Connect to Instances
User Guide
Data Migration
Data Subscription
Instance Management
Configuration Change
Parameter Configuration
Account Management
Security Group
Backup and Restoration
Database Auditing
Tag Management
Use Cases
Technical Evolution and Usage Practices of Online DDL
Lock Mechanism Analysis and Troubleshooting Practices
Data Intelligent Scheduling and Related Practices for Performance Optimization
TDSQL Boundless Selection Guide and Practical Tutorial
Developer Guide
Developer Guide (MySQL Compatibility Mode)
Developer Guide (HBase Compatibility Mode)
Performance Tuning
Performance Tuning Overview
SQL Tuning
DDL Tuning
Performance White Paper
Performance Overview
TPC-C Test
Sysbench Test
API Documentation
History
Introduction
API Category
Making API Requests
Instance APIs
Security Group APIs
Task APIs
Backup APIs
Rollback APIs
Parameter APIs
Database APIs
Data Types
Error Codes
General Reference
System Architecture
SQL Reference
Database Parameter Description
TPC-H benchmark data model reference
Error Code Information
Security and Compliance
FAQs
Agreements
Service Level Agreement
Terms of Service
Privacy Policy
Data Processing And Security Agreement
Contact Us
Glossary

Flashback Read and Standby Read

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-02-10 11:05:59

Overview

Flashback Read and Standby Read are mechanisms in database systems for reading historical data versions. Users can specify a particular historical point in time or a time interval from the current time to obtain a data snapshot of the database at a specific point in the past.
Flashback Query: When a misoperation occurs (such as UPDATE or DELETE of incorrect data), users can query the point in time before the misoperation to quickly retrieve historical data, significantly simplifying the data recovery process. TDSQL Boundless provides functionality for statement-level flashback query.
Stale Read: In read-intensive business scenarios where data real-time requirements are not high, read requests can be forwarded to Follower nodes. This sacrifices second-level data real-time, effectively sharing the read pressure on the Leader, reducing read latency, and improving the overall resource utilization and throughput of the system. TDSQL Boundless provides three levels of Stale Read features: statement level, transaction level, and session level, and allows users to select the replica role for reading data based on business needs.

Supported Versions

Flashback Query supports version 17.0.0 and above.
Stale Read supports version 20.0.0 and above.

Use Limits

The Flashback Query feature is used to quickly retrieve historical data before misoperations during database Ops. Note the following points when using this feature:
1. Limitations of the Storage Engine
Only supports physical tables with the RocksDB engine.
Does not support views or tables with other engines.
Does not support functions such as last_insert_id() that do not correspond to actual columns.
2. Way to Specify Point-in-Time
Timestamp of the Hybrid Logical Clock (GTS): Precisely locates specific snapshot data, such as SQL specifying GTS 29610460101738510.
Second-Level Flashback Query: Queries the latest data written within specified seconds, equivalent to a timestamp of the hybrid logical clock with all ones in the logical part. For example, SQL specifies the point in time 2025-01-01 12:00:00.
Does not support specifying future time (returns error Can't stale read from the future).
3. Operation Limits
A single SQL statement supports only one flashback snapshot, meaning all subqueries share the same flashback point in time and cannot be specified separately.
Only supports lock-free read-only queries with autocommit. Does not support locking queries such as SELECT FOR UPDATE, FOR SHARE, LOCK IN SHARE MODE; does not support INSERT...SELECT statements; does not support BEGIN; SELECT... syntax.
DDL operations are not supported. If the table structure changes, you must restore both the table structure and data through the Recycle Bin. The behavior and data of flashback queries depend on the specific form of DDL, and results may vary.
4. Limitation of Data Scope
Data earlier than the global earliest snapshot (GES) cannot be queried.
GES is controlled by the MC parameter advance-global-earliest-snapshot-delay. Enabling the flashback feature delays GES advancement, which may increase storage usage and query latency.

Usage Instructions

Preparations

-- Enable the flashback query feature.
SET persist tdsql_enable_stale_read = ON;

Guide for Flashback Query Usage

Syntax

Flashback query introduces a brand new AS OF syntax to query data at a specified point in time.
SELECT ... FROM <table_name> [ AS OF {TIMESTAMP timestamp_option | GTS gts_option} ]
Types Supported for timestamp_option
Any expression that can be get_date can be used as timestamp_option, including but not limited to:
time literal: '2023-09-05 12:00:00'
Time functions: NOW(), SYSDATE(), UTC_TIMESTAMP()
User variables: SELECT NOW() INTO @time1
Expressions for Time Arithmetic: NOW + INTERVAL 1 SECOND, @time1 - INTERVAL 1 YEAR
Types Supported for gts_option
Any expression that can be evaluated as an integer can be used as gts_option, including but not limited to:
integer literal: 29610460101738510
Functions and arithmetic expressions: ((UNIX_TIMESTAMP(@time1) << 24) | 0xFFFFFF)
User variables: @gts1

Example

-- Create a test table.
CREATE TABLE t1(a INT PRIMARY KEY, b INT);

SELECT sleep(3);

-- Record the initial timestamp.
SELECT NOW() INTO @time0;
SELECT ((UNIX_TIMESTAMP(@time0) << 24) | 0xFFFFFF) INTO @gts0;

SELECT sleep(3);

-- Insert test data.
INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(4,4),(5,5),(6,1),(7,2),(8,3),(9,4),(10,5);

SELECT sleep(3);

-- Record the timestamp after data insertion.
SELECT NOW() INTO @time1;
SELECT ((UNIX_TIMESTAMP(@time1) << 24) | 0xFFFFFF) INTO @gts1;

SELECT sleep(3);

-- Update data.
UPDATE t1 SET b=b*10;

-- Query for current data
SELECT * FROM t1 ORDER BY a;
a»b
1»10
2»20
3»30
4»40
5»50
6»10
7»20
8»30
9»40
10»■50

-- Flashback query to the initial state (empty table).
SELECT * FROM t1 ORDER BY a AS OF TIMESTAMP @time0;
a»b
SELECT * FROM t1 ORDER BY a AS OF GTS @gts0;
a»b

-- Flashback query to the state after data insertion.
SELECT * FROM t1 ORDER BY a AS OF TIMESTAMP @time1;
a»b
1»1
2»2
3»3
4»4
5»5
6»1
7»2
8»3
9»4
10»■5


SELECT * FROM t1 ORDER BY a AS OF GTS @gts1;
a»b
1»1
2»2
3»3
4»4
5»5
6»1
7»2
8»3
9»4
10»■5

Usage Instructions for Stale Read

Set Read Nodes

-- 0: Leader node, 1: Follower node.
SET persist tdsql_stale_read_role=1;

Statement-Level Stale Read

The operation is identical to that of a statement-level flashback query.

Session-Level/Transaction-Level Stale Read

Provides the session variable tdsql_read_staleness_t, supporting queries at the session level and transaction level.
-- Query current data.
+----+-----+
| id | num |
+----+-----+
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| 4 | 40 |
+----+-----+

set tdsql_read_staleness_t='-10'; #Read data from 10 seconds ago.

-- Insert new data.
insert into t1 values (5,50);

-- Check the current time.
select now();
+---------------------+
| now() |
+---------------------+
| 2025-02-16 17:57:50 |
+---------------------+

-- Query current data.
select * from t1; # Return historical data.
+----+-----+
| id | num |
+----+-----+
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| 4 | 40 |
+----+-----+

-- Wait for some time.
-- Check the current time.
select now();
+---------------------+
| now() |
+---------------------+
| 2025-02-16 17:58:01 |
+---------------------+

-- Query current data again.
select * from t1; # Return new data.
+----+-----+
| id | num |
+----+-----+
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| 4 | 40 |
| 5 | 50 |
+----+-----+
After tdsql_read_staleness_t is set, you can also begin transaction queries on data.
-- Query current data.
select * from t1;
+----+-----+
| id | num |
+----+-----+
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| 4 | 40 |
| 5 | 50 |
+----+-----+

-- Insert new data.
insert into t1 values (6,60);

-- Begin transaction.
begin;
select * from t1; # Return historical data.
+----+-----+
| id | num |
+----+-----+
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| 4 | 40 |
| 5 | 50 |
+----+-----+
select sum(num) as total_num from t1;
+-----------+
| total_num |
+-----------+
| 150 |
+-----------+
rollback;

-- Wait for some time.
-- Begin transaction.
begin;
select * from t1; # Return new data.
+----+-----+
| id | num |
+----+-----+
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| 4 | 40 |
| 5 | 50 |
| 6 | 60 |
+----+-----+
select sum(num) as total_num from t1;
+-----------+
| total_num |
+-----------+
| 210 |
+-----------+
rollback;

Relevant parameters

Parameter Name
Valid Value/Value Range
Type
Default Value
Value Range
Whether a Restart Is Required
Description
tdsql_enable_stale_read
GLOBAL
Boolean
ON
ON/OFF
No
The switch for the flashback query feature.
advance-global-earliest-snapshot-delay
GLOBAL
Integer
10
0~43200
No
The MC side controls the queryable time range for flashback queries. Unit: seconds.
The larger the value of this parameter, the longer the time range for querying historical data supported by Flashback Query, while the storage space occupied and query duration may also increase.
tdsql_stale_read_role
GLOBAL
UINT
0
0/1
No
Set the replica for routing access of Stale Read.
0: indicates the Leader node.
1: indicates the Follower node.

tdsql_read_staleness_t
SESSION
CHAR
''
-
No
Set the data staleness time for Stale Read. Example:
set session tdsql_read_staleness_t='-3'
Enable the staleness mode for Stale Read to read data from 3 seconds before the current physical time.
Note: set session tdsql_read_staleness_t='' (empty string) indicates that the staleness mode for Stale Read is disabled.

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan