Details
-
Bug
-
Status: Stalled (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.1(EOL), 10.2(EOL), 10.3(EOL), 10.4(EOL)
-
None
Description
I see 10.1 crashing after MDEV-20576 is pused to 10.1
Here is the stack trace
#5 0x00007ffff5284412 in __GI___assert_fail (assertion=0x555557773960 "0 < sel && sel <= 2.0",
|
file=0x555557772de0 "/home/varunraiko/MariaDB/10.1-dev/sql/sql_select.cc", line=7764,
|
function=0x55555777be40 <table_cond_selectivity(JOIN*, unsigned int, st_join_table*, unsigned long long)::__PRETTY_FUNCTION__> "double table_cond_selectivity(JOIN*, uint, JOIN_TAB*, table_map)") at assert.c:101
|
#6 0x00005555560069bc in table_cond_selectivity (join=<optimized out>, idx=<optimized out>, s=<optimized out>, rem_tables=0)
|
at /home/varunraiko/MariaDB/10.1-dev/sql/sql_select.cc:7764
|
#7 0x000055555602bc3a in best_extension_by_limited_search (join=0x62b000010230, remaining_tables=2, idx=<optimized out>,
|
record_count=<optimized out>, read_time=<optimized out>, search_depth=<optimized out>, prune_level=<optimized out>,
|
use_cond_selectivity=<optimized out>) at /home/varunraiko/MariaDB/10.1-dev/sql/sql_select.cc:8022
|
#8 0x000055555602d7c1 in greedy_search (use_cond_selectivity=2, prune_level=1, search_depth=62, remaining_tables=2,
|
join=0x62b000010230) at /home/varunraiko/MariaDB/10.1-dev/sql/sql_select.cc:7169
|
#9 choose_plan (join=0x62b000010230, join_tables=<optimized out>) at /home/varunraiko/MariaDB/10.1-dev/sql/sql_select.cc:6745
|
#10 0x0000555556090973 in make_join_statistics (join=<optimized out>, tables_list=..., keyuse_array=<optimized out>)
|
at /home/varunraiko/MariaDB/10.1-dev/sql/sql_select.cc:4249
|
#11 0x00005555560ab39c in JOIN::optimize_inner (this=0x62b000010230) at /home/varunraiko/MariaDB/10.1-dev/sql/sql_select.cc:1405
|
#12 0x00005555560b61e4 in JOIN::optimize (this=0x62b000010230) at /home/varunraiko/MariaDB/10.1-dev/sql/sql_select.cc:1059
|
This crash is reproducible with the below mtr test :
--source include/have_sequence.inc
|
|
create table t1 (id int, a int, PRIMARY KEY(id), key(a)); |
insert into t1 select seq,seq from seq_1_to_100; |
create table t2 (id int, a int, b int, PRIMARY KEY(id), key(a), key(b)); |
insert into t2 select seq,seq,seq from seq_1_to_100; |
|
set optimizer_use_condition_selectivity=2; |
EXPLAIN SELECT * FROM t1 A, t1 B WHERE A.a = B.a and A.id = 65; |
Attachments
Issue Links
- is blocked by
-
MDEV-20740 Odd computations in calculate_cond_selectivity_for_table
-
- Open
-
- relates to
-
MDEV-20576 A new assertion added to check validity of calculated selectivity values fails
-
- Closed
-
-
MDEV-21633 Assertion `tmp >= 0' failed in best_access_path with rowid_filter=ON
-
- Stalled
-
-
MDEV-20519 Query plan regression with optimizer_use_condition_selectivity > 1
-
- Closed
-
-
MDEV-20697 Take selectivity of join conditions into account correctly with optimizer_use_condition_selectivity > 1
-
- Stalled
-
ANALYSIS
Looking at the test case in the description:
The WHERE clause is A.a = B.a AND A.id=65
There is a primary key on A.id, so we will only read one table, hence so A is a const table.
Then we substitute the value of A.a read from the const table
in the condition A.a = B.a, so the condition now becomes B.a = 65.
So the join planner picked ref access for table B
The key is on column B.a
(gdb) p table->alias.Ptr
(gdb) p table->cond_selectivity
$9 = 0.01
(gdb) p pos->key
$14 = (KEYUSE *) 0x7fffe000aa30
(gdb) p pos->key->key
$15 = 1
(gdb) p table->quick_keys.is_set(key)
(gdb) p table->quick_rows[key]
$13 = 1
Discount the seletivity for ref(const).
After discount, we have
(gdb) p sel
$16 = 1
Discount selectivity for ref(non-const)
Here we again consider the case B.a = A.a
(gdb) p next_field->table->alias.Ptr
(gdb) p next_field->field_name
(gdb) p field->field_name
(gdb) p field->table->alias.Ptr
(gdb) p sel
$28 = 1
(gdb) p field->cond_selectivity
$33 = 0.01
So here the discount happens
sel/= field->cond_selectivity;
(gdb) p sel
$29 = 100
Then we hit the assert, as selectivity value is again absurd.
So the discount should have only happened once not twice, we should make sure that selectivity for a field is discounted only once