Overview
Scenarios
Product Architecture
Instance Types
Compatibility Notes
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.last_insert_id() that do not correspond to actual columns.Can't stale read from the future).SELECT FOR UPDATE, FOR SHARE, LOCK IN SHARE MODE; does not support INSERT...SELECT statements; does not support BEGIN; SELECT... syntax.advance-global-earliest-snapshot-delay. Enabling the flashback feature delays GES advancement, which may increase storage usage and query latency.-- Enable the flashback query feature.SET persist tdsql_enable_stale_read = ON;
AS OF syntax to query data at a specified point in time.SELECT ... FROM <table_name> [ AS OF {TIMESTAMP timestamp_option | GTS gts_option} ]
get_date can be used as timestamp_option, including but not limited to:'2023-09-05 12:00:00'NOW(), SYSDATE(), UTC_TIMESTAMP()SELECT NOW() INTO @time1NOW + INTERVAL 1 SECOND, @time1 - INTERVAL 1 YEARgts_option, including but not limited to:29610460101738510((UNIX_TIMESTAMP(@time1) << 24) | 0xFFFFFF)@gts1-- 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 dataSELECT * FROM t1 ORDER BY a;a»b1»102»203»304»405»506»107»208»309»4010»■50-- Flashback query to the initial state (empty table).SELECT * FROM t1 ORDER BY a AS OF TIMESTAMP @time0;a»bSELECT * 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»b1»12»23»34»45»56»17»28»39»410»■5SELECT * FROM t1 ORDER BY a AS OF GTS @gts1;a»b1»12»23»34»45»56»17»28»39»410»■5
-- 0: Leader node, 1: Follower node.SET persist tdsql_stale_read_role=1;
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 |+----+-----+
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;
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. |
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback