mariadb/storage/myisam
Monty a6bf4b5807 MDEV-29693 ANALYZE TABLE still flushes table definition cache when engine-independent statistics is used
This commits enables reloading of engine-independent statistics
without flushing the table from table definition cache.

This is achieved by allowing multiple version of the
TABLE_STATISTICS_CB object and having independent pointers to it in
TABLE and TABLE_SHARE.  The TABLE_STATISTICS_CB object have reference
pointers and are freed when no one is pointing to it anymore.

TABLE's TABLE_STATISTICS_CB pointer is updated to use the
TABLE_SHARE's pointer when read_statistics_for_tables() is called at
the beginning of a query.

Main changes:
- read_statistics_for_table() will allocate an new TABLE_STATISTICS_CB
  object.
- All get_stat_values() functions has a new parameter that tells
  where collected data should be stored. get_stat_values() are not
  using the table_field object anymore to store data.
- All get_stat_values() functions returns 1 if they found any
  data in the statistics tables.

Other things:
- Fixed INSERT DELAYED to not read statistics tables.
- Removed Statistics_state from TABLE_STATISTICS_CB as this is not
  needed anymore as wer are not changing TABLE_SHARE->stats_cb while
  calculating or loading statistics.
- Store values used with store_from_statistical_minmax_field() in
  TABLE_STATISTICS_CB::mem_root. This allowed me to remove the function
  delete_stat_values_for_table_share().
  - Field_blob::store_from_statistical_minmax_field() is implemented
    but is not normally used as we do not yet support EIS statistics
    for blobs. For example Field_blob::update_min() and
    Field_blob::update_max() are not implemented.
    Note that the function can be called if there is an concurrent
    "ALTER TABLE MODIFY field BLOB" running because of a bug in
    ALTER TABLE where it deletes entries from column_stats
    before it has an exclusive lock on the table.
- Use result of field->val_str(&val) as a pointer to the result
  instead of val (safetly fix).
- Allocate memory for collected statistics in THD::mem_root, not in
  in TABLE::mem_root. This could cause the TABLE object to grow if a
  ANALYZE TABLE was run many times on the same table.
  This was done in allocate_statistics_for_table(),
  create_min_max_statistical_fields_for_table() and
  create_min_max_statistical_fields_for_table_share().
- Store in TABLE_STATISTICS_CB::stats_available which statistics was
  found in the statistics tables.
- Removed index_table from class Index_prefix_calc as it was not used.
- Added TABLE_SHARE::LOCK_statistics to ensure we don't load EITS
  in parallel. First thread will load it, others will reuse the
  loaded data.
- Eliminate read_histograms_for_table(). The loading happens within
  read_statistics_for_tables() if histograms are needed.
  One downside is that if we have read statistics without histograms
  before and someone requires histograms, we have to read all statistics
  again (once) from the statistics tables.
  A smaller downside is the need to call alloc_root() for each
  individual histogram. Before we could allocate all the space for
  histograms with a single alloc_root.
- Fixed bug in MyISAM and Aria where they did not properly notice
  that table had changed after analyze table. This was not a problem
  before this patch as then the MyISAM and Aria tables where flushed
  as part of ANALYZE table which did hide this issue.
- Fixed a bug in ANALYZE table where table->records could be seen as 0
  in collect_statistics_for_table(). The effect of this unlikely bug
  was that a full table scan could be done even if
  analyze_sample_percentage was not set to 1.
- Changed multiple mallocs in a row to use multi_alloc_root().
- Added a mutex protection in update_statistics_for_table() to ensure
  that several tables are not updating the statistics at the same time.

Some of the changes in sql_statistics.cc are based on a patch from
Oleg Smirnov <olernov@gmail.com>

Co-authored-by: Oleg Smirnov <olernov@gmail.com>
Co-authored-by: Vicentiu Ciorbaru <cvicentiu@gmail.com>
Reviewer: Sergei Petrunia <sergey@mariadb.com>
2023-08-18 13:28:39 +03:00
..
ftbench mtr: use env for perl 2020-06-23 03:24:46 +02:00
mysql-test MDEV-19236 Improve error message for ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_COLUMN_TYPE 2019-04-12 12:28:09 +03:00
ChangeLog
CMakeLists.txt Add build on AIX 2020-12-16 08:07:04 +11:00
ft_boolean_search.c perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
ft_myisam.c Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
ft_nlq_search.c perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
ft_parser.c Merge 10.4 into 10.5 2021-10-13 12:33:56 +03:00
ft_static.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
ft_stopwords.c perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
ft_update.c Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
ftdefs.h Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
fulltext.h Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
ha_myisam.cc Merge branch '10.5' into 10.6 2023-08-01 15:08:52 +02:00
ha_myisam.h Merge 10.4 into 10.5 2023-02-10 12:02:11 +02:00
mi_cache.c Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
mi_changed.c Update FSF Address 2019-05-11 21:29:06 +03:00
mi_check.c Fix of4cb0d43ac63761174a39cea892c176b9cfa6edfc after merge in 10.5 2023-07-30 08:41:54 +02:00
mi_checksum.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mi_close.c Merge 10.2 into 10.3 2020-04-22 14:45:55 +03:00
mi_create.c Merge branch '10.5' into 10.6 2023-08-04 07:52:54 +02:00
mi_dbug.c Update FSF Address 2019-05-11 21:29:06 +03:00
mi_delete.c MDEV-27030 vcol.vcol_keys_myisam fails on Windows x64, with Visual Studio 2022 2021-11-12 00:32:39 +01:00
mi_delete_all.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
mi_delete_table.c MDEV-11412 Ensure that table is truly dropped when using DROP TABLE 2020-06-14 19:39:42 +03:00
mi_dynrec.c perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
mi_extra.c Fixed flush table issue in MyISAM with CREATE ... SELECT 2021-06-19 03:46:00 +03:00
mi_extrafunc.h Update FSF Address 2019-05-11 21:29:06 +03:00
mi_info.c Merge 10.5 into 10.6 2022-03-14 10:59:46 +02:00
mi_key.c Merge 10.4 into 10.5 2020-11-03 16:24:47 +02:00
mi_keycache.c Update FSF Address 2019-05-11 21:29:06 +03:00
mi_locking.c MDEV-29693 ANALYZE TABLE still flushes table definition cache when engine-independent statistics is used 2023-08-18 13:28:39 +03:00
mi_log.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
mi_open.c Merge 10.5 into 10.6 2023-05-23 12:25:39 +03:00
mi_packrec.c Fixed access of undefined memory for compressed MyISAM and Aria tables 2020-06-14 19:39:42 +03:00
mi_page.c Update FSF Address 2019-05-11 21:29:06 +03:00
mi_panic.c Update FSF Address 2019-05-11 21:29:06 +03:00
mi_preload.c perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
mi_range.c Added page_range to records_in_range() to improve range statistics 2020-03-27 03:54:45 +02:00
mi_rename.c Make rename atomic/repeatable in MyISAM and Aria 2021-05-19 22:54:12 +02:00
mi_rfirst.c Fix spelling mistakes in MyISAM code comments 2019-09-20 07:21:21 +03:00
mi_rkey.c MDEV-21794: Optimizer flag rowid_filter leads to long query 2020-05-07 12:27:17 +02:00
mi_rlast.c Update FSF Address 2019-05-11 21:29:06 +03:00
mi_rnext.c MDEV-21794: Optimizer flag rowid_filter leads to long query 2020-05-07 12:27:17 +02:00
mi_rnext_same.c MDEV-21794: Optimizer flag rowid_filter leads to long query 2020-05-07 12:27:17 +02:00
mi_rprev.c MDEV-21794: Optimizer flag rowid_filter leads to long query 2020-05-07 12:27:17 +02:00
mi_rrnd.c Update FSF Address 2019-05-11 21:29:06 +03:00
mi_rsame.c Update FSF Address 2019-05-11 21:29:06 +03:00
mi_rsamepos.c Update FSF Address 2019-05-11 21:29:06 +03:00
mi_scan.c Update FSF Address 2019-05-11 21:29:06 +03:00
mi_search.c Merge remote-tracking branch 'origin/10.1' into 10.2 2019-09-24 19:19:25 +04:00
mi_static.c perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
mi_statrec.c Update FSF Address 2019-05-11 21:29:06 +03:00
mi_test1.c Added 'const' to arguments in get_one_option and find_typeset() 2021-02-08 12:16:29 +02:00
mi_test2.c Added page_range to records_in_range() to improve range statistics 2020-03-27 03:54:45 +02:00
mi_test3.c Fix clang -Wunused-but-set-variable 2022-09-19 13:30:52 +03:00
mi_test_all.res
mi_test_all.sh Merge remote-tracking branch 'origin/5.5' into 10.1 2019-09-24 11:18:39 +04:00
mi_unique.c MDEV-21581 Helper functions and methods for CHARSET_INFO 2020-01-28 12:29:23 +04:00
mi_update.c Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
mi_write.c cleanup: PSI key is *always* the first argument 2020-03-10 19:24:23 +01:00
myisam_ftdump.c Merge 10.4 into 10.5 2022-10-06 08:29:56 +03:00
myisamchk.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
myisamdef.h MDEV-31083 ASAN use-after-poison in myrg_attach_children 2023-05-23 09:16:36 +03:00
myisamlog.c perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
myisampack.c Merge 10.4 into 10.5 2021-04-21 09:01:01 +03:00
NEWS Merge remote-tracking branch 'origin/10.1' into 10.2 2019-09-24 19:19:25 +04:00
rt_index.c perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
rt_index.h Update FSF Address 2019-05-11 21:29:06 +03:00
rt_key.c Update FSF Address 2019-05-11 21:29:06 +03:00
rt_key.h Update FSF Address 2019-05-11 21:29:06 +03:00
rt_mbr.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
rt_mbr.h Update FSF Address 2019-05-11 21:29:06 +03:00
rt_split.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
rt_test.c Merge 10.4 into 10.5 2021-08-25 07:53:23 +03:00
sort.c Merge branch '10.5' into 10.6 2023-08-01 15:08:52 +02:00
sp_defs.h Update FSF Address 2019-05-11 21:29:06 +03:00
sp_key.c MDEV-21082: isnan/isinf compilation errors, isfinite warnings on MacOS 2019-11-19 16:28:15 +03:00
sp_test.c Added page_range to records_in_range() to improve range statistics 2020-03-27 03:54:45 +02:00
test_pack