Skip to content
  • Abhishek Ranjan's avatar
    eb18a752
    Bug#26203731 : INFORMATION_SCHEMA.TABLES TABLE STATISTICS ARE NULL · eb18a752
    Abhishek Ranjan authored
    In MySQL 8.0, SHOW TABLE STATUS ...  and SELECT * FROM
    INFORMATION_SCHEMA.TABLES ... do not return meaningful data for the
    fields rows, avg_row_length, data_length, max_data_length, index_length,
    data_free, update_time. Instead they return NULL. On MySQL 5.7 these
    statements return valid data. Same behavior is observed for cardinality
    column in INFORMATION_SCHEMA.STATISTICS table.
    
    New implementation of information schema in 8.0 introduces two modes for
    dynamic table statistics retrieval for information schema - `cached` and
    `latest`. In cached mode, dynamic meta-data is fetched from
    mysql.table_stats and mysql.index_stats tables. The data is populated
    and refreshed in the stats table by explicit ANALYZE command on the
    tables. If data is fetched from information schema in `cached` mode
    without first executing ANALYZE, user will get `NULL` or stale data
    for dynamic table statistics.
    
    Fix:
    
    - Implement time based caching of the dynamic metadata in mysql.table_stats
      and mysql.index_stats.
    
    - Time based caching will fetch data from Storage engines when retriving
      data for first time. User will never get NULL value.
    
    - Remove 'cached' and 'latest' modes for data fetching from information
      schema. Remove information_schema_stats variable.
    
    - Add SESSION variable `information_schema_stats_expiry` to specify the
      value of timeout for cached data.
    
    - Default value of information_schema_stats_expiry variable is 24 hours
      (86400 seconds).
    
    - If information_schema_stats_expiry is specified as ZERO, always retrieve
      latest data from storage engine.
    
    - Do not store the retrieved dynamic data in mysql.table_stats and
      mysql.index_stats if any of the following condition is satisfied:
      - information_schema_stats_expiry value is ZERO.
      - innodb_read_only is ON.
      - transaction_read_only is ON.
      - read_only is ON.
      - super_read_only is ON.
      - data is retrieved for performance schema table.
    
    - For other values for information_schema_stats_expiry, store the data
      retrieved from storage engine in mysql.index_stats and mysql.table_stats.
      The stored data will be used for further queries on information_schema.tables
      and information_schema.statistics till data expires.
    
    - Remove internal system views TABLES_DYNAMIC, STATISTICS_DYNAMIC and
      SHOW_STATISTICS_DYNAMIC.
    
    - The metadata of columns of information schema which store dynamic
      information now depends directly on the UDF implementing them. Add
      'unsigned' flag the UDFs to maintain unsigned property of the columns.
    eb18a752
    Bug#26203731 : INFORMATION_SCHEMA.TABLES TABLE STATISTICS ARE NULL
    Abhishek Ranjan authored
    In MySQL 8.0, SHOW TABLE STATUS ...  and SELECT * FROM
    INFORMATION_SCHEMA.TABLES ... do not return meaningful data for the
    fields rows, avg_row_length, data_length, max_data_length, index_length,
    data_free, update_time. Instead they return NULL. On MySQL 5.7 these
    statements return valid data. Same behavior is observed for cardinality
    column in INFORMATION_SCHEMA.STATISTICS table.
    
    New implementation of information schema in 8.0 introduces two modes for
    dynamic table statistics retrieval for information schema - `cached` and
    `latest`. In cached mode, dynamic meta-data is fetched from
    mysql.table_stats and mysql.index_stats tables. The data is populated
    and refreshed in the stats table by explicit ANALYZE command on the
    tables. If data is fetched from information schema in `cached` mode
    without first executing ANALYZE, user will get `NULL` or stale data
    for dynamic table statistics.
    
    Fix:
    
    - Implement time based caching of the dynamic metadata in mysql.table_stats
      and mysql.index_stats.
    
    - Time based caching will fetch data from Storage engines when retriving
      data for first time. User will never get NULL value.
    
    - Remove 'cached' and 'latest' modes for data fetching from information
      schema. Remove information_schema_stats variable.
    
    - Add SESSION variable `information_schema_stats_expiry` to specify the
      value of timeout for cached data.
    
    - Default value of information_schema_stats_expiry variable is 24 hours
      (86400 seconds).
    
    - If information_schema_stats_expiry is specified as ZERO, always retrieve
      latest data from storage engine.
    
    - Do not store the retrieved dynamic data in mysql.table_stats and
      mysql.index_stats if any of the following condition is satisfied:
      - information_schema_stats_expiry value is ZERO.
      - innodb_read_only is ON.
      - transaction_read_only is ON.
      - read_only is ON.
      - super_read_only is ON.
      - data is retrieved for performance schema table.
    
    - For other values for information_schema_stats_expiry, store the data
      retrieved from storage engine in mysql.index_stats and mysql.table_stats.
      The stored data will be used for further queries on information_schema.tables
      and information_schema.statistics till data expires.
    
    - Remove internal system views TABLES_DYNAMIC, STATISTICS_DYNAMIC and
      SHOW_STATISTICS_DYNAMIC.
    
    - The metadata of columns of information schema which store dynamic
      information now depends directly on the UDF implementing them. Add
      'unsigned' flag the UDFs to maintain unsigned property of the columns.
Loading