maria:bb-11.2-MDEV-31431

Last commit made on 2023-08-24
Get this branch:
git clone -b bb-11.2-MDEV-31431 https://git.launchpad.net/maria

Branch merges

Branch information

Name:
bb-11.2-MDEV-31431
Repository:
lp:maria

Recent commits

d1023d6... by Rex Johnston

MDEV-31431 support sql standard <explicit table> expressions

Initial support for sql standard <explicit table> expressions
The <explicit table>
    TABLE <table or query name>
    is equivalent to the <query specification>
    SELECT * FROM <table or query name>
Deal with the conflict caused by ANALYZE TABLE t1; being both
a request for table statistics and analyzing an SQL statement.

ded4ed3... by Monty <email address hidden>

MDEV-30944 Range_rowid_filter::fill() leaves file->keyread at MAX_KEY

This test case exposed 2 different bugs:
- When replacing a range with an index scan on a covering key
  in test_if_skip_sort_order() we didn't disable filtering.
  Filtering does not make much sense in this case.
  - Fixed by disabling filtering in this case.
- Range_rowid_filter::fill() did not take into account that keyread
  could already active, which caused an assert when it tried to
  activate another keyread.
  - Fixed by remembering old keyread state at start and restoring it
    at end.

Other things:
- ha_start_keyread() allowed multiple calls. This is wrong, especially
  as we do no check if the index changed!
  I added an assert() to ensure that we don't call it there is already
  an active keyread.
- ha_end_keyread() always called ha_extra(), even if keyread was not
  active. Added a check to avoid the extra call.

3ea8f30... by Monty <email address hidden>

Added compare cost for DS-MRR (multi-range-read with disk sweep)

07b02ab... by Monty <email address hidden>

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

7079386... by Daniel Bartholomew <email address hidden>

bump the VERSION

5ba3baf... by Oleksandr "Sanja" Byelkin

Fix of maturity

7083e58... by Sergey Petrunia

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.

aac88fc... by Monty <email address hidden>

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.

6611419... by Monty <email address hidden>

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.

209fed8... by Monty <email address hidden>

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).