mariadb/mysys
Monty b66cdbd1ea Changing all cost calculation to be given in milliseconds
This makes it easier to compare different costs and also allows
the optimizer to optimizer different storage engines more reliably.

- Added tests/check_costs.pl, a tool to verify optimizer cost calculations.
  - Most engine costs has been found with this program. All steps to
    calculate the new costs are documented in Docs/optimizer_costs.txt

- User optimizer_cost variables are given in microseconds (as individual
  costs can be very small). Internally they are stored in ms.
- Changed DISK_READ_COST (was DISK_SEEK_BASE_COST) from a hard disk cost
  (9 ms) to common SSD cost (400MB/sec).
- Removed cost calculations for hard disks (rotation etc).
- Changed the following handler functions to return IO_AND_CPU_COST.
  This makes it easy to apply different cost modifiers in ha_..time()
  functions for io and cpu costs.
  - scan_time()
  - rnd_pos_time() & rnd_pos_call_time()
  - keyread_time()
- Enhanched keyread_time() to calculate the full cost of reading of a set
  of keys with a given number of ranges and optional number of blocks that
  need to be accessed.
- Removed read_time() as keyread_time() + rnd_pos_time() can do the same
  thing and more.
- Tuned cost for: heap, myisam, Aria, InnoDB, archive and MyRocks.
  Used heap table costs for json_table. The rest are using default engine
  costs.
- Added the following new optimizer variables:
  - optimizer_disk_read_ratio
  - optimizer_disk_read_cost
  - optimizer_key_lookup_cost
  - optimizer_row_lookup_cost
  - optimizer_row_next_find_cost
  - optimizer_scan_cost
- Moved all engine specific cost to OPTIMIZER_COSTS structure.
- Changed costs to use 'records_out' instead of 'records_read' when
  recalculating costs.
- Split optimizer_costs.h to optimizer_costs.h and optimizer_defaults.h.
  This allows one to change costs without having to compile a lot of
  files.
- Updated costs for filter lookup.
- Use a better cost estimate in best_extension_by_limited_search()
  for the sorting cost.
- Fixed previous issues with 'filtered' explain column as we are now
  using 'records_out' (min rows seen for table) to calculate filtering.
  This greatly simplifies the filtering code in
  JOIN_TAB::save_explain_data().

This change caused a lot of queries to be optimized differently than
before, which exposed different issues in the optimizer that needs to
be fixed.  These fixes are in the following commits.  To not have to
change the same test case over and over again, the changes in the test
cases are done in a single commit after all the critical change sets
are done.

InnoDB changes:
- Updated InnoDB to not divide big range cost with 2.
- Added cost for InnoDB (innobase_update_optimizer_costs()).
- Don't mark clustered primary key with HA_KEYREAD_ONLY. This will
  prevent that the optimizer is trying to use index-only scans on
  the clustered key.
- Disabled ha_innobase::scan_time() and ha_innobase::read_time() and
  ha_innobase::rnd_pos_time() as the default engine cost functions now
  works good for InnoDB.

Other things:
- Added  --show-query-costs (\Q) option to mysql.cc to show the query
  cost after each query (good when working with query costs).
- Extended my_getopt with GET_ADJUSTED_VALUE which allows one to adjust
  the value that user is given. This is used to change cost from
  microseconds (user input) to milliseconds (what the server is
  internally using).
- Added include/my_tracker.h  ; Useful include file to quickly test
  costs of a function.
- Use handler::set_table() in all places instead of 'table= arg'.
- Added SHOW_OPTIMIZER_COSTS to sys variables. These are input and
  shown in microseconds for the user but stored as milliseconds.
  This is to make the numbers easier to read for the user (less
  pre-zeros).  Implemented in 'Sys_var_optimizer_cost' class.
- In test_quick_select() do not use index scans if 'no_keyread' is set
  for the table. This is what we do in other places of the server.
- Added THD parameter to Unique::get_use_cost() and
  check_index_intersect_extension() and similar functions to be able
  to provide costs to called functions.
- Changed 'records' to 'rows' in optimizer_trace.
- Write more information to optimizer_trace.
- Added INDEX_BLOCK_FILL_FACTOR_MUL (4) and INDEX_BLOCK_FILL_FACTOR_DIV (3)
  to calculate usage space of keys in b-trees. (Before we used numeric
  constants).
- Removed code that assumed that b-trees has similar costs as binary
  trees. Replaced with engine calls that returns the cost.
- Added Bitmap::find_first_bit()
- Added timings to join_cache for ANALYZE table (patch by Sergei Petrunia).
- Added records_init and records_after_filter to POSITION to remember
  more of what best_access_patch() calculates.
- table_after_join_selectivity() changed to recalculate 'records_out'
  based on the new fields from best_access_patch()

Bug fixes:
- Some queries did not update last_query_cost (was 0). Fixed by moving
  setting thd->...last_query_cost in JOIN::optimize().
- Write '0' as number of rows for const tables with a matching row.

Some internals:
- Engine cost are stored in OPTIMIZER_COSTS structure.  When a
  handlerton is created, we also created a new cost variable for the
  handlerton. We also create a new variable if the user changes a
  optimizer cost for a not yet loaded handlerton either with command
  line arguments or with SET
  @@global.engine.optimizer_cost_variable=xx.
- There are 3 global OPTIMIZER_COSTS variables:
  default_optimizer_costs   The default costs + changes from the
                            command line without an engine specifier.
  heap_optimizer_costs      Heap table costs, used for temporary tables
  tmp_table_optimizer_costs The cost for the default on disk internal
                            temporary table (MyISAM or Aria)
- The engine cost for a table is stored in table_share. To speed up
  accesses the handler has a pointer to this. The cost is copied
  to the table on first access. If one wants to change the cost one
  must first update the global engine cost and then do a FLUSH TABLES.
  This was done to be able to access the costs for an open table
  without any locks.
- When a handlerton is created, the cost are updated the following way:
  See sql/keycaches.cc for details:
  - Use 'default_optimizer_costs' as a base
  - Call hton->update_optimizer_costs() to override with the engines
    default costs.
  - Override the costs that the user has specified for the engine.
  - One handler open, copy the engine cost from handlerton to TABLE_SHARE.
  - Call handler::update_optimizer_costs() to allow the engine to update
    cost for this particular table.
  - There are two costs stored in THD. These are copied to the handler
    when the table is used in a query:
    - optimizer_where_cost
    - optimizer_scan_setup_cost
- Simply code in best_access_path() by storing all cost result in a
  structure. (Idea/Suggestion by Igor)
2023-02-02 23:54:45 +03:00
..
crc32 Remove unused header from crc32c.cc 2022-02-24 19:41:00 +11:00
array.c Merge 10.7 into 10.8 2023-01-10 14:42:50 +02:00
base64.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
ChangeLog
charset-def.c MDEV-27009 Add UCA-14.0.0 collations 2022-08-10 15:04:24 +02:00
charset.c MDEV-27009 Add UCA-14.0.0 collations 2022-08-10 15:04:24 +02:00
CMakeLists.txt MDEV-27090 Windows client - ReadConsoleA does not work correctly with UTF8 codepage 2021-12-15 19:13:57 +01:00
crc32ieee.cc MDEV-27208: Extend CRC32() and implement CRC32C() 2022-01-21 19:24:00 +02:00
errors.c MDEV-7947 strcmp() takes 0.37% in OLTP RO 2020-07-23 10:54:33 +03:00
file_logger.c Merge 10.4 into 10.5 2021-03-05 12:54:43 +02:00
get_password.c MDEV-26713 Set activeCodePage=UTF8 for windows programs 2021-12-15 19:13:57 +01:00
guess_malloc_library.c
hash.c Merge 10.6 into 10.7 2023-01-10 13:58:03 +02:00
lf_alloc-pin.c Merge branch '10.3' into 10.4 2021-12-07 09:47:42 +01:00
lf_dynarray.c perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
lf_hash.cc MDEV-27088: Server crash on ARM (WMM architecture) due to missing barriers in lf-hash (10.5) 2021-11-30 15:16:16 +11:00
list.c Merge 10.4 into 10.5 2020-05-13 14:25:06 +03:00
ma_dyncol.c Added typedef decimal_digits_t (uint16) for number of digits in most 2021-05-19 22:27:27 +02:00
mf_arr_appstr.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_cache.c Merge branch '10.3' into 10.4 2019-05-19 20:55:37 +02:00
mf_dirname.c MDEV-21581 Helper functions and methods for CHARSET_INFO 2020-01-28 12:29:23 +04:00
mf_fn_ext.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mf_format.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mf_getdate.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_iocache.c Merge 10.5 into 10.6 2021-06-21 17:49:33 +03:00
mf_iocache2.c Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
mf_keycache.c Merge 10.5 into 10.6 2022-09-26 14:34:43 +03:00
mf_keycaches.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_loadpath.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_pack.c MDEV-21581 Helper functions and methods for CHARSET_INFO 2020-01-28 12:29:23 +04:00
mf_path.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
mf_qsort.c fix clang build: check alignment the other way 2021-07-26 12:37:25 +03:00
mf_qsort2.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_radix.c cleanup: Typo fix appliccable -> applicable 2023-01-30 15:24:15 +02:00
mf_same.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_sort.c cleanup: Typo fix appliccable -> applicable 2023-01-30 15:24:15 +02:00
mf_soundex.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_tempdir.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
mf_tempfile.c MDEV-26601: mysys - O_TMPFILE ^ O_CREAT 2021-09-14 21:06:34 +10:00
mf_unixpath.c Update FSF Address 2019-05-11 21:29:06 +03:00
mf_wcomp.c Update FSF Address 2019-05-11 21:29:06 +03:00
mulalloc.c perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
my_access.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
my_addr_resolve.c Merge 10.5 into 10.6 2022-11-08 17:37:22 +02:00
my_alarm.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_alloc.c Merge 10.6 into 10.7 2023-01-10 13:58:03 +02:00
my_atomic_writes.c MDEV-26029: Implement my_test_if_thinly_provisioned() for ScaleFlux 2021-06-29 15:20:16 +03:00
my_basename.c Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
my_bit.c Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_bitmap.c cleanup: MY_BITMAP mutex 2021-08-26 23:39:52 +02:00
my_chmod.c
my_chsize.c Merge branch '10.3' into 10.4 2019-05-19 20:55:37 +02:00
my_compare.c MDEV-21581 Helper functions and methods for CHARSET_INFO 2020-01-28 12:29:23 +04:00
my_compress.c Cleanup: Remove IF_VALGRIND 2022-04-25 09:40:40 +03:00
my_copy.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
my_cpu.c MDEV-19845: Make my_cpu.h self-contained 2020-02-01 14:56:05 +02:00
my_create.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_default.c MDEV-26221: DYNAMIC_ARRAY use size_t for sizes 2021-10-19 16:00:26 +03:00
my_delete.c Merge 10.6 into 10.7 2022-12-13 18:01:49 +02:00
my_div.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_dlerror.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_error.c Merge branch '10.4' into 10.5 2020-11-01 14:26:15 +01:00
my_file.c perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
my_fopen.c MDEV-27142 - postfix 2022-11-04 13:50:36 +01:00
my_fstream.c Merge branch '10.3' into 10.4 2019-05-19 20:55:37 +02:00
my_gethwaddr.c OS detection logic in my_gethwaddr.c is backwards 2022-11-13 13:12:37 +11:00
my_getncpus.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
my_getopt.c Changing all cost calculation to be given in milliseconds 2023-02-02 23:54:45 +03:00
my_getpagesize.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
my_getsystime.c Windows : fix warning about potential division by 0 2021-05-09 13:26:03 +02:00
my_getwd.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
my_init.c MDEV-27142 disable text mode for Windows stdio by default 2022-07-18 13:18:03 +02:00
my_largepage.c MDEV-25342: autosize innodb_buffer_pool_chunk_size 2022-01-18 14:20:57 +02:00
my_lib.c MDEV-24841: More workarounds 2022-03-14 10:37:39 +02:00
my_libwrap.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_likely.c cleanup: PSI key is *always* the first argument 2020-03-10 19:24:23 +01:00
my_lock.c Merge branch '10.3' into 10.4 2019-05-19 20:55:37 +02:00
my_lockmem.c Merge 10.6 into 10.7 2022-06-21 18:02:41 +03:00
my_malloc.c Merge 10.6 into 10.7 2023-01-10 13:58:03 +02:00
my_memmem.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_mess.c MDEV-23846: O_TMPFILE error in mysqlbinlog stream output breaks restore 2020-11-23 12:16:45 +05:30
my_minidump.cc MDEV-11499 mysqltest, Windows : improve diagnostics if server fails to shutdown 2021-09-24 11:49:28 +02:00
my_mkdir.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
my_mmap.c libpmem cmake macros 2020-02-04 23:23:50 +04:00
my_new.cc Fixes that enables my_new.cc (new wrapper using my_malloc) 2021-05-19 22:27:27 +02:00
my_once.c Merge branch '10.3' into 10.4 2019-05-19 20:55:37 +02:00
my_open.c Added checking to protect against simultaneous double free in safemalloc 2021-05-19 22:54:14 +02:00
my_port.c
my_pread.c Merge 10.3 into 10.4 2019-06-19 10:49:00 +03:00
my_pthread.c Merge 10.5 into 10.6 2022-10-25 14:25:42 +03:00
my_quick.c Update FSF Address 2019-05-11 21:29:06 +03:00
my_rdtsc.c MDEV-27429: Support RISC-V cycle timer 2022-01-06 10:36:55 +11:00
my_read.c Merge branch '10.3' into 10.4 2019-05-19 20:55:37 +02:00
my_redel.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
my_rename.c Merge 10.5 into 10.6 2022-12-13 16:58:58 +02:00
my_rnd.c remove dead code 2022-07-31 14:54:37 +02:00
my_safehash.c cleanup: PSI key is *always* the first argument 2020-03-10 19:24:23 +01:00
my_safehash.h
my_seek.c myseek: AIX has no "tell" 2021-03-19 11:14:53 +11:00
my_setuser.c
my_sleep.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
my_static.c Fixes that enables my_new.cc (new wrapper using my_malloc) 2021-05-19 22:27:27 +02:00
my_static.h Update FSF Address 2019-05-11 21:29:06 +03:00
my_symlink.c MDEV-24841 Build error with MSAN use-of-uninitialized-value in comp_err 2022-03-14 09:28:55 +02:00
my_symlink2.c MDEV-11412 Ensure that table is truly dropped when using DROP TABLE 2020-06-14 19:39:42 +03:00
my_sync.c MDEV-20685: compile fixes for Solaris/OSX/AIX 2020-04-29 12:02:47 +03:00
my_thr_init.c MDEV-24973 Performance schema duplicates rarely executed code for mutex operations 2021-03-02 14:32:37 +02:00
my_uuid.c cleanup: uuid 2021-10-29 18:29:01 +02:00
my_win_popen.cc Ensure that source files contain only valid UTF8 encodings (#2188) 2022-08-30 09:21:40 +01:00
my_wincond.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
my_winerr.c Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
my_winfile.c Merge 10.5 into 10.6 2022-12-13 16:58:58 +02:00
my_winthread.c Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
my_wintoken.c Merge pull request #1221 from grooverdan/10.4-MDEV-18851-multiple-sized-large-page-support 2020-04-02 23:54:08 +04:00
my_write.c Merge branch '10.3' into 10.4 2019-05-19 20:55:37 +02:00
mysys_priv.h Merge 10.5 into 10.6 2022-12-13 16:58:58 +02:00
psi_noop.c Merge branch 'merge-perfschema-5.7' into 10.5 2022-08-02 09:34:15 +02:00
ptr_cmp.c Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
queues.c Merge 10.4 into 10.5 2020-05-05 21:16:22 +03:00
safemalloc.c Merge 10.5 into 10.6 2021-10-28 09:08:58 +03:00
stacktrace.c MDEV-25870 Windows - fix ARM64 cross-compilation 2021-06-07 23:15:36 +02:00
string.c MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
test_charset.c MDEV-8334: Rename utf8 to utf8mb3 2021-05-19 06:48:36 +02:00
test_dir.c Update FSF Address 2019-05-11 21:29:06 +03:00
test_thr_mutex.c
test_xml.c Update FSF Address 2019-05-11 21:29:06 +03:00
testhash.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
thr_alarm.c Merge 10.5 into 10.6 2022-10-25 14:25:42 +03:00
thr_lock.c Merge 10.5 into 10.6 2021-05-04 07:37:38 +03:00
thr_mutex.c MDEV-26637: (explicit length) ASAN: main.metadata and user_variables.basic MTR failures after MDEV-26572 2021-10-12 10:01:07 +02:00
thr_rwlock.c MDEV-19773 : simplify implementation of Windows rwlock 2019-06-18 00:37:09 +01:00
thr_timer.c MDEV-15795 Stack exceeded if pthread_attr_setstacksize(&thr_attr,8196) succeeds 2022-10-22 10:24:14 +02:00
tree.c perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
typelib.c Added 'const' to arguments in get_one_option and find_typeset() 2021-02-08 12:16:29 +02:00
waiting_threads.c MDEV-26221: DYNAMIC_ARRAY use size_t for sizes 2021-10-19 16:00:26 +03:00
wqueue.c Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00