Tidb_read_staleness Not Effective

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tidb_read_staleness 不起效

| username: Wind-Gone222

[Test Environment] TiDB
[TiDB Version] 7.1.0
[Reproduction Path] Operations that led to the issue
I strictly followed the example provided on the official website 通过系统变量 `tidb_read_staleness` 读取历史数据 | PingCAP 文档中心, even setting set @@tidb_read_staleness=“-1000” and tested using both manual command line input and automated programs. The data observed was always the latest. I want to know how to read old data within a certain bound and if there are any other operations required.
[Encountered Issue: Issue Phenomenon and Impact]
[Resource Configuration] Enter TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
[Attachments: Screenshots/Logs/Monitoring]

| username: h5n1 | Original post link

How should this be understood? Has this variable been set in the automation program?

| username: Wind-Gone222 | Original post link

It has been set up. In this mode, the session settings are executed immediately after insertion, and then read, and it is still the latest. However, from my understanding of the examples on the official website, even if you manually type commands, you should be able to see historical data.

| username: Wind-Gone222 | Original post link

The main reason for the slow speed is that the SQL statement is not optimized. You can try to optimize the SQL statement or add an index to improve the query speed.

| username: h5n1 | Original post link

Try using the “as of timestamp” syntax to read historical data and see if it works properly.

| username: Wind-Gone222 | Original post link

It’s normal. If you specify reading at a historical point in time, but my requirement is to just provide a bound for weak consistency.

| username: h5n1 | Original post link

This function呢

| username: h5n1 | Original post link

I tried version 7.1.2, and it shows the same phenomenon as yours. According to the explanation, this should be because no question was asked.

| username: Wind-Gone222 | Original post link

Okay, but I don’t know how to measure such an effect. I tried the above as of timestamp, and it is also the latest.

| username: andone | Original post link

I have the same problem.

| username: Kongdom | Original post link

:thinking: Reading the timestamps from 5 seconds ago to the present, isn’t that just the latest version? I don’t understand the significance of this variable.

| username: Wind-Gone222 | Original post link

It may not be fully synchronized, so you don’t have to wait for complete linear consistency and can read an old version on the spot.