# Stale Read

__*Stale Read*__
__*tidb_replica_read*__
__*TIDB_BOUNDED_STALENESS function*__

+ System variable **`tidb_replica_read`** controls where `TiDB` reads data from
+ Function **`TIDB_BOUNDED_STALENESS`** reads the latest data as much as possible within the specified time window

```
/* 10 seconds before */
SELECT *
FROM test.t_west 
  AS OF TIMESTAMP (NOW()-10);

SET SESSION tidb_replica_read = 'follower';

/* Between 20 seconds before and 5 seconds before */
SELECT *
FROM test.t_west
  AS OF TIMESTAMP TIDB_BOUNDED_STALENESS(NOW()-20, NOW()-5);
```

------------------------------

Class demo scripts:

https://github.com/pingcap/tidb-course-201-lab/blob/master/scripts/07-demo-placement-policy-01-show.sql

tidb_replica_read: This variable is used to control where TiDB reads data. There are three options:

 leader: Read from the leader node only
 follower: Read from the follower nodes only
 leader-and-follower: Read from leader or follower nodes

TIDB_BOUNDED_STANESS Function: Read the latest data as much as possible within the time range.
