• Sergey Vojtovich's avatar
    Thread safe histograms loading · c2798784
    Sergey Vojtovich authored
    Previously multiple threads were allowed to load histograms concurrently.
    There were no known problems caused by this. But given amount of data
    races in this code, it'd happen sooner or later.
    
    To avoid scalability bottleneck, histograms loading is protected by
    per-TABLE_SHARE atomic variable.
    
    Whenever histograms were loaded by preceding statement (hot-path), a
    scalable load-acquire check is performed.
    
    Whenever histograms have to be loaded anew, mutual exclusion for loaders
    is established by atomic variable. If histograms are being loaded
    concurrently, statement waits until load is completed.
    
    - Table_statistics::total_hist_size moved to TABLE_STATISTICS_CB: only
      meaningful within TABLE_SHARE (not used for collected stats).
    - TABLE_STATISTICS_CB::histograms_can_be_read and
      TABLE_STATISTICS_CB::histograms_are_read are replaced with a tri state
      atomic variable.
    - Simplified away alloc_histograms_for_table_share().
    
    Note: there's still likely a data race if a thread attempts accessing
    histograms data after it failed to load it (because of concurrent load).
    It was there previously and goes out of the scope of this effort. One way
    of fixing it could be reviving TABLE::histograms_are_read and adding
    appropriate checks whenever it is needed.
    
    Part of MDEV-19061 - table_share used for reading statistical tables is
                         not protected
    c2798784
sql_statistics.h 11.2 KB