Commit graph

198247 commits

Author SHA1 Message Date
Monty
07b02ab40e MDEV-31356: Range cost calculations does not take into account join_buffer
This patch also fixes
MDEV-31391 Assertion `((best.records_out) == 0.0 ... failed

Cost changes caused by this change:
- range queries with join buffer now have a notable smaller cost.
- range ranges are bit more expensive as the MULTI_RANGE_COST is now
  properly applied to it in all cases (this extra cost is equal to a
  key lookup).
- table scan cost is slight smaller as we now assume data is cached in
  the engine after the first scan pass. (We did this before for range
  scans and other access methods).
- partition tables had wrong values for max_row_blocks and
  max_index_blocks.  Correcting this, causes range access on
  partitioned tables to have slightly higher cost because of the
  increased estimated IO.
- Using first match + join buffer caused 'filtered' to be calcualted
  wrong.  (Only affected EXPLAIN, not query costs).
- Added cost_without_join_buffer to optimizer_trace.
- check_quick_select() adjusted the number of rows according to persistent
  statistics, but did not adjust cost. Now fixed.

The big change in the patch are:

- In best_access_path(), where we now are using storing the cost in
  'ALL_READ_COST cost' and only converting it to a double at the end.
   This allows us to more exactly calculate the effect of the join_cache.
- In JOIN_TAB::estimate_scan_time(), store the cost also in a
  ALL_READ_COST object.

One of effect if this change is that when joining very small tables:

t1    some_access_method
t2    range
t3    ALL         Use join buffer

This is swiched to

t1      some_access_method
t3      ALL
t2      range      use join buffer

Both plans has the same cost, but as table scan in this case has less
cost than rang, the table scan will be considered first and thus have
precidence.

Test case changes:
- optimizer_trace          - Addition of cost_without_join_buffer
- subselect_mat_cost_bugs  - Small tables and scan versus range
- range & range_mrr_icp    - Range + join_cache is faster than ref
- optimizer_trace          - cost_without_join_buffer, smaller scan cost,
                             range setup cost.
- mrr                      - range+join_buffer used as smaller cost
2023-06-07 18:42:58 +03:00
Daniel Bartholomew
7079386587
bump the VERSION 2023-06-06 15:27:52 -04:00
Oleksandr Byelkin
5ba3bafb83 Fix of maturity 2023-06-03 18:30:12 +02:00
Sergei Petrunia
7083e58e2e Fix UBSAN failure: sql_select.h:982:7: load of value ... not valid for type bool
This is 11.0 part of the fix: in 11.0, get_costs_for_tables() calls
best_access_path() for all possible tables, for each call it saves
a POSITION object with the access method and "loose_scan_pos"
POSITION object.
The latter is saved even if there is no possible LooseScan plan. Saving
is done by copying POSITION objects which may generate a spurious
UBSan error.
2023-06-03 18:30:04 +02:00
Monty
aac88fc205 MDEV-31237 Assertion `!(tab->select && tab->select->quick)' failed in make_join_readinfo
The problem was a wrong assert. I changed it to match the code in
best_access_path().

The given test case was a bit tricky for the optimizer, which first
decided on using a index scan (because of force index), but then
test_if_skip_sort_order() decided to use range anyway to handle
distinct.
2023-05-27 17:42:14 +03:00
Monty
661141948f MDEV-31247 Assertion `c >= 0' failed in COST_MULT upon query with many joins
Problem was an overflow when calculating number of join cache refills.
2023-05-27 17:42:14 +03:00
Monty
209fed8eed MDEV-31258 Assertion `cond_selectivity <= 1.000000001' upon range query
This was caused of two minor issues:
- get_quick_record_count() returned the number of rows for range with
  least cost, when it should have returned the minum number of rows
  for any range.
- When changing REF to RANGE, we also changed records_out, which
  should not be done (number of records in the result will not
  change).

The above change can cause a small change in row estimates where the
optimizer chooses a clustered key with more rows than a range one
secondary key (unlikely case).
2023-05-27 12:20:31 +03:00
Sergei Petrunia
368dd22a81 MDEV-31223: UBSan error: sql_select.h:969:7: runtime error: load of value...
In Loose_scan_opt::save_to_position, initialize
POSITION::firstmatch_with_join_buf.
2023-05-09 13:09:00 +03:00
Sergei Petrunia
b3edbf25a1 MDEV-31022: SIGSEGV in maria_create from create_internal_tmp_table
The code in create_internal_tmp_table() didn't take into account that
now temporary (derived) tables may have multiple indexes:

- one index due to duplicate removal
   = In this example created by conversion of big-IN(...) into subquery
   = this index might be converted into a "unique constraint" if the key
     length is too large.
- one index added by derived_with_keys optimization.

Make create_internal_tmp_table() handle multiple indexes.

Before this patch, use of a unique constraint was indicated in
TABLE_SHARE::uniques. This was ok as unique constraint was the only index
in the table. Now it's no longer the case so TABLE_SHARE::uniques is removed
and replaced with an in-memory-only flag HA_UNIQUE_HASH.

This patch is based on Monty's patch.
Co-Author: Monty <monty@mariadb.org>
2023-05-09 10:12:27 +03:00
Monty
63df43a0e8 Removed temporary test file that should not have been pushed 2023-05-03 21:44:57 +03:00
Monty
78f684e552 Moved events tests from main to suite/events
This makes it easier to run test on just events.
2023-05-03 21:44:57 +03:00
Monty
ec820a380e Moved merge tests from main to suite/merge
This makes it easier to run test on just the MRG_MYISAM engine.

Other things:
- Renamed merge-big.test to flush_corruption.test as it does not
  have anything to do with merge tables.
2023-05-03 21:44:57 +03:00
Monty
0099c2fc1a MDEV-30786 SIGFPE in cost_group_min_max on EXP
The problem was that for merge tables without any underlaying tables the
block size was 0, which the code could not handle.

Fixed by ensuring that MERGE tables never have a block size of 0.
Fixed also a wrong assumption of number of seeks needed to scan
merge tables.
2023-05-03 21:44:57 +03:00
Monty
3bdc5542dc MDEV-30812: Improve output cardinality estimates for hash join
Introduces @@optimizer_switch flag: hash_join_cardinality

When this option is on, use EITS statistics to produce tighter bounds
for hash join output cardinality.

This patch is an extension / replacement to a similar patch in 10.6

New features:
- optimizer_switch hash_join_cardinality is on by default
- records_out is set to fanout when HASH is used
- Fixed bug in is_eits_usable: The function did not work with views
2023-05-03 21:44:57 +03:00
Marko Mäkelä
8d26537fbf MDEV-30895 Assertion btr_cur->rtr_info->thr... in rtr_ins_enlarge_mbr()
rtr_ins_enlarge_mbr(): Relax the assertion that was added in
commit f27e9c8947
to cover also table-rebuilding DDL. We only need
btr_cur->rtr_info->thr for acquiring R-tree locks,
and the thread that is executing a DDL operation has exclusive
access to the being-built index or the copy of the being-rebuilt table.
2023-04-28 10:18:30 +03:00
Yuchen Pei
6abafdbb7c
MDEV-29676 Add query to set lock wait timeout when getting sts crd
Set the lock wait timeout to 1 beforehand, and reset it afterwards, to
avoid lock conflict caused by opening the same table twice in case of
self-reference.
2023-04-28 10:32:51 +10:00
Yuchen Pei
779307dd5b
MDEV-29676 Some changes in behaviour w.r.t. spider sts crd
- assign spider->share early when !new_share
- remove locking before spider_share_init_{sts,crd}
2023-04-28 10:30:30 +10:00
Yuchen Pei
b5d317197c
MDEV-29676 refactored and documented spider_get_share() and friends
Extracted out common subroutines, gave more meaningful names etc,
added comments etc.

Also:
- Documented active servers load balancing reads, and other fields in
  SPIDER_SHARE etc.
- Removed commented out code
- Documented and refactored self-reference check
- Removed some unnecessary functions
- Renamed unhelpful roop_count
- Refactored spider_get_{sts,crd}, where we turn get_type into an enum
- Cleaned up spider_mbase_handler::show_table_status() and
  spider_mbase_handler::show_index()
2023-04-28 10:29:29 +10:00
Yuchen Pei
a8dac17a42
MDEV-28363 remove #ifdef SPIDER_use_LEX_CSTRING_for_Field_blob_constructor 2023-04-28 10:05:38 +10:00
Yuchen Pei
f2f54868b0
MDEV-30920 Remove need_lock and table from spider_close_sys_table() 2023-04-28 10:05:38 +10:00
Marko Mäkelä
aa6ba99310 Merge 10.11 into 11.0 2023-04-27 15:11:18 +03:00
Marko Mäkelä
7b17e0d4ac Merge 10.10 into 10.11 2023-04-27 14:03:24 +03:00
Marko Mäkelä
4f16e95310 Merge 10.9 into 10.10 2023-04-27 13:36:36 +03:00
Daniel Black
d0a71e90b8 deb: sid - debian autobake
Deb-autobakes where failing with:

dh_missing: warning: usr/share/mysql/mysql-test/mysql-test-run exists in debian/tmp but is not installed to anywhere
dh_missing: warning: usr/share/mysql/mysql-test/mtr exists in debian/tmp but is not installed to anywhere
dh_missing: warning: usr/share/mysql/mysql-test/mariadb-test-run exists in debian/tmp but is not installed to anywhere
dh_missing: warning: usr/share/mysql/mysql-test/mysql-test-run.pl exists in debian/tmp but is not installed to anywhere

Add all to mariadb-test.install and remove mariadb-test.links
2023-04-27 17:12:22 +10:00
Marko Mäkelä
436d8ef6b5 Merge 10.8 into 10.9 2023-04-27 10:03:26 +03:00
Marko Mäkelä
bbd261bb2e Merge 10.6 into 10.8 2023-04-27 09:53:56 +03:00
Marko Mäkelä
bb1d1dc846 Merge 10.5 into 10.6 2023-04-27 09:48:27 +03:00
Marko Mäkelä
902c622215 Merge 10.4 into 10.5 2023-04-27 09:39:53 +03:00
Yuchen Pei
6fccf8ba05
MDEV-29644 post-merge fixup
Applying b98375f instead of 9b32e4b for version 10.5-10.8.
Applying 5075f4e instead of 9b32e4b for version 10.9+.
2023-04-27 16:14:05 +10:00
Tuukka Pasanen
c5e50c48bb MDEV-30837: Remove usage of AWK in autobake-debs.sh
AWK is used in autobake-debs.sh for printing information
about created DEB packages.

This can be rewrite with bash inner commands read and echo.
2023-04-27 15:09:01 +10:00
Tuukka Pasanen
f99a891858 MDEV-30837: Remove usage of AWK from Debian init and postinst scripts
AWK in used in Debian SysV-init and postinst scripts to determine
is there enough space starting MariaDB database or create new
database to target destination.

These AWK scripts can be rewrited to use pure SH or help
using Coreutils which is mandatory for usage of MariaDB currently.

Reasoning behind this is to get rid of one very less used dependency
2023-04-27 15:09:01 +10:00
Daniel Black
7020887e3e MDEV-30411: main.explain_json_format_partitions fails on Debian arm{el,hf}
Extend the portability of ANALYZE FORMAT=JSON by using the microsecond
timer if cycles isn't available.

Reviewer: Sergei Petrunia <sergey@mariadb.com>
2023-04-27 14:42:04 +10:00
Daniel Black
55cf4194f9 MDEV-30411: Fix my_timer_init() to match the code in as my_timer_cycles()
make the compile-time logic in my_timer_cycles() also #define
MY_TIMER_ROUTINE_CYCLES to indicate which implementation it is using.
Then, make my_timer_init() use MY_TIMER_ROUTINE_CYCLES.

This leaves us with just one set of compile-time #if's which determine
how we read time in #cycles.

Reviewer (and commit message author): Sergei Petrunia <sergey@mariadb.com>
2023-04-27 14:42:04 +10:00
Marko Mäkelä
54819192fe Merge 10.11 into 11.0 2023-04-26 18:50:15 +03:00
Marko Mäkelä
52f6f364d9 Merge 10.10 into 10.11 2023-04-26 18:31:50 +03:00
Marko Mäkelä
ce6616aa28 Merge 10.9 into 10.10 2023-04-26 18:31:03 +03:00
Marko Mäkelä
09fdd3aca6 After-merge fix
This fixes up commit e3f6e1c92e
2023-04-26 18:19:44 +03:00
Marko Mäkelä
e3f6e1c92e Merge 10.8 into 10.9 2023-04-26 17:48:13 +03:00
Marko Mäkelä
c15c8ef3e3 Merge 10.6 into 10.8 2023-04-26 13:58:40 +03:00
Alexander Barkov
b0ecf4693d Merge remote-tracking branch 'origin/10.10' into 10.11 2023-04-26 13:10:57 +04:00
Marko Mäkelä
5740638c4c MDEV-31132 Deadlock between DDL and purge of InnoDB history
log_free_check(): Assert that the caller must not hold
exclusive lock_sys.latch. This was the case for calls from
ibuf_delete_for_discarded_space(). This caused a deadlock with
another thread that would be holding a latch on a dirty page
that would need to be written so that the checkpoint would advance
and log_free_check() could return. That other thread was waiting
for a shared lock_sys.latch.

fil_delete_tablespace(): Do not invoke ibuf_delete_for_discarded_space()
because in DDL operations, we will be holding exclusive lock_sys.latch.

trx_t::commit(std::vector<pfs_os_file_t>&), innodb_drop_database(),
row_purge_remove_clust_if_poss_low(), row_undo_ins_remove_clust_rec(),
row_discard_tablespace_for_mysql():
Invoke ibuf_delete_for_discarded_space() on the deleted tablespaces after
releasing all latches.
2023-04-26 12:08:59 +03:00
Marko Mäkelä
d4265fbde5 MDEV-26055: Correct the formula for adaptive flushing
page_cleaner_flush_pages_recommendation(): If dirty_pct is
between innodb_max_dirty_pages_pct_lwm
and innodb_max_dirty_pages_pct,
scale the effort relative to how close we are to
innodb_max_dirty_pages_pct.

The previous formula was missing a multiplication by 100.

Tested by: Axel Schwenke
2023-04-26 11:53:42 +03:00
Sergei Golubchik
b942f41438 MDEV-30218 update test result
followup for d1a46c68cd
2023-04-26 09:07:10 +02:00
Sergei Golubchik
b3817425d9 MDEV-11356 Option skip-core-file does not work
remove ancient hard-coded treatment of --core-file. This enables
normal my_getopt behavior for the already existing sysvar
2023-04-26 09:07:10 +02:00
Julius Goryavsky
898320b5f8 MDEV-30804 addendum for 10.6+ branches
This addition to MDEV-30804 is relevant for 10.6+, it excludes
the mixed transaction section using both innodb and aria storage
engines from the galera_var_replicate_aria_off test, since such
transactions cannot be executed unless aria supports two-phase
transaction commit. No additional tests are required as this
commit fixes the mtr test itself.
2023-04-25 18:55:53 +02:00
Andrei
e22a57da82 MDEV-30620 Trying to lock uninitialized LOCK_parallel_entry
The error was seen by a number of mtr tests being caused
by overdue initialization of rpl_parallel::LOCK_parallel_entry.
Specifically, SHOW-SLAVE-STATUS might find in
rpl_parallel::workers_idle() a gtid domain hash entry
already inserted whose mutex had not done
mysql_mutex_init().

Fixed with swapping the mutex init and the its entry's stack insertion.

Tested with a generous number of `mtr --repeat` of a few of the reported
to fail tests, incl rpl.parallel_backup.
2023-04-25 19:43:04 +03:00
Marko Mäkelä
c22ab93f8a MDEV-26827 fixup: Prevent a hang in LRU eviction
buf_pool_t::page_cleaner_wakeup(): If for_LRU=true, wake up the page
cleaner immediately, also when it is in a timed wait. This avoids an
unnecessary delay of up to 1 second.
2023-04-25 15:03:38 +03:00
Sergei Petrunia
a72b2c3ffb MDEV-31121: ANALYZE statement produces 0 for all timings in embedded server
Timers require my_timer_init() call.
It was made only in mysqld_main(). Call it also from init_embedded_server().
2023-04-25 13:47:46 +03:00
Marko Mäkelä
818d5e4814 Merge 10.5 into 10.6 2023-04-25 13:10:33 +03:00
Marko Mäkelä
50f3b7d164 MDEV-31124 Innodb_data_written miscounts doublewrites
When commit a5a2ef079c
implemented asynchronous doublewrite, the writes via
the doublewrite buffer started to be counted incorrectly,
without multiplying them by innodb_page_size.

srv_export_innodb_status(): Correctly count the
Innodb_data_written.

buf_dblwr_t: Remove submitted(), because it is close to written()
and only Innodb_data_written was interested in it. According to
its name, it should count completed and not submitted writes.

Tested by: Axel Schwenke
2023-04-25 12:17:06 +03:00