From 952fd037e9dcd9fcbdc64b5f3d149cb9204372a8 Mon Sep 17 00:00:00 2001 From: xingyuyang Date: Fri, 15 Sep 2023 14:17:01 +0800 Subject: [PATCH] [bugfix] issue#594 Index conditions referencing the const table were not added to RANGE SCAN Problems: ========= Index conditions refering to const table should be added to RANGE SCAN as the condition value can be read before execution. Bug#32976857 (commit 9a13c1c6971f4bd56d143179ecfb34cca8ecc018) omitted to pass the const table map when judging the condition-related table, resulting in the index condition referencing the const table not being added to the range scan, and the range scan needed to scan more data. Solution: ========= Fix it by taking the const table map into account when adding conditions to RANGE SCAN. MR!892, reviewed by maxmqiu, kenkkchen, willhan. --- mysql-test/include/range.inc | 15 +++++++++++++++ mysql-test/r/range_all.pq | 27 +++++++++++++++++++++++++++ mysql-test/r/range_all.result | 25 +++++++++++++++++++++++++ mysql-test/r/range_icp.pq | 27 +++++++++++++++++++++++++++ mysql-test/r/range_icp.result | 25 +++++++++++++++++++++++++ mysql-test/r/range_icp_mrr.pq | 25 +++++++++++++++++++++++++ mysql-test/r/range_icp_mrr.result | 25 +++++++++++++++++++++++++ mysql-test/r/range_mrr.pq | 27 +++++++++++++++++++++++++++ mysql-test/r/range_mrr.result | 25 +++++++++++++++++++++++++ mysql-test/r/range_mrr_cost.pq | 27 +++++++++++++++++++++++++++ mysql-test/r/range_mrr_cost.result | 25 +++++++++++++++++++++++++ mysql-test/r/range_none.pq | 27 +++++++++++++++++++++++++++ mysql-test/r/range_none.result | 25 +++++++++++++++++++++++++ sql/sql_optimizer.cc | 13 +++++++++++-- 14 files changed, 336 insertions(+), 2 deletions(-) diff --git a/mysql-test/include/range.inc b/mysql-test/include/range.inc index e07d7e9f385..5b98f3c7eb8 100644 --- a/mysql-test/include/range.inc +++ b/mysql-test/include/range.inc @@ -3211,3 +3211,18 @@ SET @@GLOBAL.innodb_stats_transient_sample_pages= @innodb_stats_transient_sample SET @@GLOBAL.innodb_stats_persistent_sample_pages= @innodb_stats_persistent_sample_pages; -- enable_result_log -- enable_query_log + +--echo # +--echo # BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +--echo # +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +EXPLAIN FORMAT=TREE +SELECT t2.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; +SELECT t2.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; +DROP TABLE t1,t2; diff --git a/mysql-test/r/range_all.pq b/mysql-test/r/range_all.pq index 92095b0e5ec..80887141ec1 100644 --- a/mysql-test/r/range_all.pq +++ b/mysql-test/r/range_all.pq @@ -4239,4 +4239,31 @@ a 2 1 DROP TABLE t1; +# +# BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +# +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +EXPLAIN FORMAT=TREE +SELECT t2.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; +EXPLAIN +-> PX Receiver (slice: 0; workers: 1) + -> PX Sender (slice: 1; workers: 3) + -> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= (('2' + 2)))) (cost=0.86 rows=3) + -> Parallel covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=0.86 rows=3) + +SELECT t2.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; +b +2 +3 +4 +DROP TABLE t1,t2; set optimizer_switch=default; diff --git a/mysql-test/r/range_all.result b/mysql-test/r/range_all.result index 3ecf2f3a57c..6fa5f585418 100644 --- a/mysql-test/r/range_all.result +++ b/mysql-test/r/range_all.result @@ -4060,4 +4060,29 @@ a 2 1 DROP TABLE t1; +# +# BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +# +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +EXPLAIN FORMAT=TREE +SELECT t2.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; +EXPLAIN +-> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= (('2' + 2)))) (cost=0.86 rows=3) + -> Covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=0.86 rows=3) + +SELECT t2.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; +b +2 +3 +4 +DROP TABLE t1,t2; set optimizer_switch=default; diff --git a/mysql-test/r/range_icp.pq b/mysql-test/r/range_icp.pq index 55bd24c3019..20823ea40cf 100644 --- a/mysql-test/r/range_icp.pq +++ b/mysql-test/r/range_icp.pq @@ -4239,4 +4239,31 @@ a 2 1 DROP TABLE t1; +# +# BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +# +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +EXPLAIN FORMAT=TREE +SELECT t2.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; +EXPLAIN +-> PX Receiver (slice: 0; workers: 1) + -> PX Sender (slice: 1; workers: 3) + -> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= (('2' + 2)))) (cost=0.86 rows=3) + -> Parallel covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=0.86 rows=3) + +SELECT t2.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; +b +2 +3 +4 +DROP TABLE t1,t2; set optimizer_switch=default; diff --git a/mysql-test/r/range_icp.result b/mysql-test/r/range_icp.result index 6f0f8fb26a0..b8c4f0717e8 100644 --- a/mysql-test/r/range_icp.result +++ b/mysql-test/r/range_icp.result @@ -4060,4 +4060,29 @@ a 2 1 DROP TABLE t1; +# +# BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +# +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +EXPLAIN FORMAT=TREE +SELECT t2.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; +EXPLAIN +-> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= (('2' + 2)))) (cost=0.86 rows=3) + -> Covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=0.86 rows=3) + +SELECT t2.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; +b +2 +3 +4 +DROP TABLE t1,t2; set optimizer_switch=default; diff --git a/mysql-test/r/range_icp_mrr.pq b/mysql-test/r/range_icp_mrr.pq index b28db9adc31..c44cbc569cd 100644 --- a/mysql-test/r/range_icp_mrr.pq +++ b/mysql-test/r/range_icp_mrr.pq @@ -4239,4 +4239,29 @@ a 2 1 DROP TABLE t1; +# +# BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +# +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +EXPLAIN FORMAT=TREE +SELECT t2.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; +EXPLAIN +-> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= (('2' + 2)))) (cost=0.86 rows=3) + -> Covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=0.86 rows=3) + +SELECT t2.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; +b +2 +3 +4 +DROP TABLE t1,t2; set optimizer_switch=default; diff --git a/mysql-test/r/range_icp_mrr.result b/mysql-test/r/range_icp_mrr.result index 67983f48bb7..084ca453336 100644 --- a/mysql-test/r/range_icp_mrr.result +++ b/mysql-test/r/range_icp_mrr.result @@ -4060,4 +4060,29 @@ a 2 1 DROP TABLE t1; +# +# BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +# +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +EXPLAIN FORMAT=TREE +SELECT t2.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; +EXPLAIN +-> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= (('2' + 2)))) (cost=0.86 rows=3) + -> Covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=0.86 rows=3) + +SELECT t2.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; +b +2 +3 +4 +DROP TABLE t1,t2; set optimizer_switch=default; diff --git a/mysql-test/r/range_mrr.pq b/mysql-test/r/range_mrr.pq index 0309a8733f5..113ae5afd65 100644 --- a/mysql-test/r/range_mrr.pq +++ b/mysql-test/r/range_mrr.pq @@ -4240,4 +4240,31 @@ a 2 1 DROP TABLE t1; +# +# BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +# +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +EXPLAIN FORMAT=TREE +SELECT t2.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; +EXPLAIN +-> PX Receiver (slice: 0; workers: 1) + -> PX Sender (slice: 1; workers: 3) + -> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= (('2' + 2)))) (cost=0.86 rows=3) + -> Parallel covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=0.86 rows=3) + +SELECT t2.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; +b +2 +3 +4 +DROP TABLE t1,t2; set optimizer_switch=default; diff --git a/mysql-test/r/range_mrr.result b/mysql-test/r/range_mrr.result index 8841f957df3..deeee13d0ea 100644 --- a/mysql-test/r/range_mrr.result +++ b/mysql-test/r/range_mrr.result @@ -4061,4 +4061,29 @@ a 2 1 DROP TABLE t1; +# +# BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +# +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +EXPLAIN FORMAT=TREE +SELECT t2.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; +EXPLAIN +-> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= (('2' + 2)))) (cost=0.86 rows=3) + -> Covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=0.86 rows=3) + +SELECT t2.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; +b +2 +3 +4 +DROP TABLE t1,t2; set optimizer_switch=default; diff --git a/mysql-test/r/range_mrr_cost.pq b/mysql-test/r/range_mrr_cost.pq index 24b7c8a4ba4..8aae3e40be2 100644 --- a/mysql-test/r/range_mrr_cost.pq +++ b/mysql-test/r/range_mrr_cost.pq @@ -4240,4 +4240,31 @@ a 2 1 DROP TABLE t1; +# +# BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +# +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +EXPLAIN FORMAT=TREE +SELECT t2.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; +EXPLAIN +-> PX Receiver (slice: 0; workers: 1) + -> PX Sender (slice: 1; workers: 3) + -> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= (('2' + 2)))) (cost=0.86 rows=3) + -> Parallel covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=0.86 rows=3) + +SELECT t2.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; +b +2 +3 +4 +DROP TABLE t1,t2; set optimizer_switch=default; diff --git a/mysql-test/r/range_mrr_cost.result b/mysql-test/r/range_mrr_cost.result index 1ca21882377..4091acb450f 100644 --- a/mysql-test/r/range_mrr_cost.result +++ b/mysql-test/r/range_mrr_cost.result @@ -4061,4 +4061,29 @@ a 2 1 DROP TABLE t1; +# +# BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +# +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +EXPLAIN FORMAT=TREE +SELECT t2.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; +EXPLAIN +-> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= (('2' + 2)))) (cost=0.86 rows=3) + -> Covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=0.86 rows=3) + +SELECT t2.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; +b +2 +3 +4 +DROP TABLE t1,t2; set optimizer_switch=default; diff --git a/mysql-test/r/range_none.pq b/mysql-test/r/range_none.pq index c13be59fada..d0257533989 100644 --- a/mysql-test/r/range_none.pq +++ b/mysql-test/r/range_none.pq @@ -4239,4 +4239,31 @@ a 2 1 DROP TABLE t1; +# +# BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +# +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +EXPLAIN FORMAT=TREE +SELECT t2.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; +EXPLAIN +-> PX Receiver (slice: 0; workers: 1) + -> PX Sender (slice: 1; workers: 3) + -> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= (('2' + 2)))) (cost=0.86 rows=3) + -> Parallel covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=0.86 rows=3) + +SELECT t2.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; +b +2 +3 +4 +DROP TABLE t1,t2; set optimizer_switch=default; diff --git a/mysql-test/r/range_none.result b/mysql-test/r/range_none.result index 8a7e227d4ba..b782bf1ee0e 100644 --- a/mysql-test/r/range_none.result +++ b/mysql-test/r/range_none.result @@ -4060,4 +4060,29 @@ a 2 1 DROP TABLE t1; +# +# BUGFIX: issue#594 Index conditions refering to const table were not added to RANGE SCAN +# +CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a)); +CREATE TABLE t2 (a INTEGER, b INTEGER, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1, 1), (2, 2); +INSERT INTO t2 VALUES (2, 1), (2, 2), (2, 3), (2, 4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +EXPLAIN FORMAT=TREE +SELECT t2.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; +EXPLAIN +-> Filter: ((t2.a = 2) and (t2.b >= '2') and (t2.b <= (('2' + 2)))) (cost=0.86 rows=3) + -> Covering index range scan on t2 using PRIMARY over (a = 2 AND 2 <= b <= 4) (cost=0.86 rows=3) + +SELECT t2.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; +b +2 +3 +4 +DROP TABLE t1,t2; set optimizer_switch=default; diff --git a/sql/sql_optimizer.cc b/sql/sql_optimizer.cc index 00e7e51c50a..96c7e592dff 100644 --- a/sql/sql_optimizer.cc +++ b/sql/sql_optimizer.cc @@ -6107,9 +6107,18 @@ static ha_rows get_quick_record_count(THD *thd, JOIN_TAB *tab, ha_rows limit) { keys_to_use.merge(tab->skip_scan_keys); MEM_ROOT temp_mem_root(key_memory_test_quick_select_exec, thd->variables.range_alloc_block_size); + table_map const_tables = tab->join()->found_const_table_map; + table_map read_tables = tab->join()->is_executed() + ? + // in execution, range estimation + // is done for each row, so can + // access previous tables + (tab->prefix_tables() & ~tab->added_tables()) + : const_tables; + table_map prev_tables = const_tables; int error = test_quick_select( - thd, thd->mem_root, &temp_mem_root, keys_to_use, 0, - 0, // empty table_map + thd, thd->mem_root, &temp_mem_root, keys_to_use, prev_tables, + read_tables, limit, false, // don't force quick range ORDER_NOT_RELEVANT, tab->table(), tab->skip_records_in_range(), -- 2.19.1