# Primary and Supplemental Statistics Synchronization

+ Supplemental statistics are loaded asynchronously on demand
+ On-demand asynchronous statistics loading does not affect the performance of SQL execution but might provide incomplete statistics for SQL optimization

![`smart`](LoadStatistics05_aa_002_20231225.png)

------------------------------------------------------------------------------
For statistics that require significant memory, such as histograms, TopN, and Count-Min Sketch, TiDB employs an asynchronous, on-demand loading mechanism.

As illustrated, when a SQL statement necessitates access to related columns on TiDB Server 3, the latest relevant statistics—such as histograms, TopN, and Count-Min Sketch—are loaded into the memory of that server. However, a potential issue is that the statistics might not be fully loaded before being utilized by the optimizer, which could adversely affect the creation of execution plans.

To address this, TiDB offers a synchronous statistics loading feature. This capability allows TiDB to load large-scale statistics, including histograms, TopN, and Count-Min Sketch, into memory in a synchronous manner during SQL execution. This process enhances the completeness of statistics for SQL optimization purposes.

To activate this feature, the `tidb_stats_load_sync_wait` system variable (introduced in version 5.4) can be configured to specify a timeout period, in milliseconds, during which SQL optimization can wait for the complete loading of column statistics. The default setting for this variable is 100 milliseconds, indicating that the feature is enabled.