Skip to content

Commit ea65886

Browse files
Merge pull request #5594 from kamil-holubicki/PS-9753-8.0
PS-9753: Investigate Optimizer patches from Enhanced MySQL
2 parents e263e0b + 43e364c commit ea65886

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a));
2+
CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b));
3+
INSERT INTO t1 VALUES (1, 1), (2, 2);
4+
ANALYZE TABLE t1, t2;
5+
Table Op Msg_type Msg_text
6+
test.t1 analyze status OK
7+
test.t2 analyze status OK
8+
EXPLAIN FORMAT=TREE SELECT t1.b FROM t1 JOIN t2 WHERE t1.a = t2.a AND t2.a = 2 AND t2.b >= t1.b AND t2.b <= t1.b+2;
9+
EXPLAIN
10+
-> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= <cache>(('2' + 2)))) (cost=COST rows=3)
11+
-> Covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=COST rows=3)
12+
13+
DROP TABLE t1, t2;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# In the following test, t1 evaluates to const table.
3+
# Ensure that range optimzer sets the upper scan boundary accordingly.
4+
# (ensure that b<=4 boundary is set)
5+
#
6+
7+
CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a));
8+
CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b));
9+
INSERT INTO t1 VALUES (1, 1), (2, 2);
10+
11+
--let $n = 1000
12+
--disable_query_log
13+
BEGIN;
14+
while($n) {
15+
--eval INSERT INTO t2 VALUES (2, $n)
16+
--dec $n
17+
}
18+
COMMIT;
19+
--enable_query_log
20+
21+
ANALYZE TABLE t1, t2;
22+
23+
--replace_regex /cost=[0-9]*\.[0-9]*/cost=COST/
24+
EXPLAIN FORMAT=TREE SELECT t1.b FROM t1 JOIN t2 WHERE t1.a = t2.a AND t2.a = 2 AND t2.b >= t1.b AND t2.b <= t1.b+2;
25+
26+
27+
# cleanup
28+
DROP TABLE t1, t2;

sql/sql_optimizer.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6276,9 +6276,13 @@ static ha_rows get_quick_record_count(THD *thd, JOIN_TAB *tab, ha_rows limit,
62766276
keys_to_use.merge(tab->skip_scan_keys);
62776277
MEM_ROOT temp_mem_root(key_memory_test_quick_select_exec,
62786278
thd->variables.range_alloc_block_size);
6279+
table_map const_tables = tab->join()->found_const_table_map;
6280+
table_map read_tables = tab->join()->is_executed()
6281+
? (tab->prefix_tables() & ~tab->added_tables())
6282+
: const_tables;
62796283
int error = test_quick_select(
6280-
thd, thd->mem_root, &temp_mem_root, keys_to_use, 0,
6281-
0, // empty table_map
6284+
thd, thd->mem_root, &temp_mem_root, keys_to_use, const_tables,
6285+
read_tables,
62826286
limit,
62836287
false, // don't force quick range
62846288
ORDER_NOT_RELEVANT, tab->table(), tab->skip_records_in_range(),

0 commit comments

Comments
 (0)