1
0
mirror of https://github.com/MariaDB/server.git synced 2025-04-18 21:44:20 +03:00

MDEV-36094 Row ID filtering for reverse-ordered scans

Add tests showing that RowID filtering is not enabled for
reverse-ordered scans.
This commit is contained in:
Dave Gosselin 2025-02-19 07:22:05 -05:00 committed by Dave Gosselin
parent 7e4233746e
commit 24b5c3021d
3 changed files with 193 additions and 0 deletions

View File

@ -0,0 +1,6 @@
[myisam]
default-storage-engine=myisam
[innodb]
innodb
default-storage-engine=innodb

View File

@ -0,0 +1,134 @@
create table t1 (a int, b int);
insert into t1 (a, b) values
(1, 1000),
(2, 2000),
(3, 3000),
(4, 4000),
(5, 5000),
(6, 6000),
(7, 7000),
(8, 8000),
(9, 9000),
(10, 10000);
create index t1_a on t1 (a);
create index t1_b on t1 (b);
set @old_where_cost=@@optimizer_where_cost;
set session optimizer_where_cost=10;
explain format=json select * from t1 where t1.a between 3 and 8 and t1.b between 4000 and 4100 order by t1.b desc;
EXPLAIN
{
"query_block": {
"select_id": 1,
"cost": "COST_REPLACED",
"nested_loop": [
{
"table": {
"table_name": "t1",
"access_type": "range",
"possible_keys": ["t1_a", "t1_b"],
"key": "t1_b",
"key_length": "5",
"used_key_parts": ["b"],
"loops": 1,
"rows": 1,
"cost": "COST_REPLACED",
"filtered": 60,
"index_condition": "t1.b between 4000 and 4100",
"attached_condition": "t1.a between 3 and 8"
}
}
]
}
}
select * from t1 where t1.a between 3 and 8 and t1.b between 4000 and 4100 order by t1.b desc;
a b
4 4000
flush status;
select * from t1 where t1.a between 3 and 8 and t1.b between 4000 and 4100 order by t1.b desc;
a b
4 4000
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
VARIABLE_NAME VARIABLE_VALUE
HANDLER_ICP_ATTEMPTS 1
HANDLER_ICP_MATCH 1
explain format=json select * from t1 where t1.a between 2 and 9 and t1.b between 4000 and 5001 order by t1.b desc;
EXPLAIN
{
"query_block": {
"select_id": 1,
"cost": "COST_REPLACED",
"nested_loop": [
{
"table": {
"table_name": "t1",
"access_type": "range",
"possible_keys": ["t1_a", "t1_b"],
"key": "t1_b",
"key_length": "5",
"used_key_parts": ["b"],
"loops": 1,
"rows": 2,
"cost": "COST_REPLACED",
"filtered": 80,
"index_condition": "t1.b between 4000 and 5001",
"attached_condition": "t1.a between 2 and 9"
}
}
]
}
}
select * from t1 where t1.a between 2 and 9 and t1.b between 4000 and 5001 order by t1.b desc;
a b
5 5000
4 4000
flush status;
select * from t1 where t1.a between 2 and 9 and t1.b between 4000 and 5001 order by t1.b desc;
a b
5 5000
4 4000
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
VARIABLE_NAME VARIABLE_VALUE
HANDLER_ICP_ATTEMPTS 2
HANDLER_ICP_MATCH 2
set @old_optimizer_switch=@@optimizer_switch;
set optimizer_switch='index_condition_pushdown=off';
explain format=json select * from t1 where t1.a between 3 and 8 and t1.b between 4000 and 4100 order by t1.b desc;
EXPLAIN
{
"query_block": {
"select_id": 1,
"cost": "COST_REPLACED",
"nested_loop": [
{
"table": {
"table_name": "t1",
"access_type": "range",
"possible_keys": ["t1_a", "t1_b"],
"key": "t1_b",
"key_length": "5",
"used_key_parts": ["b"],
"loops": 1,
"rows": 1,
"cost": "COST_REPLACED",
"filtered": 60,
"attached_condition": "t1.a between 3 and 8 and t1.b between 4000 and 4100"
}
}
]
}
}
select * from t1 where t1.a between 3 and 8 and t1.b between 4000 and 4100 order by t1.b desc;
a b
4 4000
flush status;
select * from t1 where t1.a between 2 and 9 and t1.b between 4000 and 5001 order by t1.b desc;
a b
5 5000
4 4000
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
VARIABLE_NAME VARIABLE_VALUE
HANDLER_ICP_ATTEMPTS 0
HANDLER_ICP_MATCH 0
set optimizer_switch=@old_optimizer_switch;
set session optimizer_where_cost=@old_where_cost;
drop table t1;

View File

@ -0,0 +1,53 @@
create table t1 (a int, b int);
insert into t1 (a, b) values
(1, 1000),
(2, 2000),
(3, 3000),
(4, 4000),
(5, 5000),
(6, 6000),
(7, 7000),
(8, 8000),
(9, 9000),
(10, 10000);
create index t1_a on t1 (a);
create index t1_b on t1 (b);
# set the WHERE clause cost higher to force the use of the rowid filter
set @old_where_cost=@@optimizer_where_cost;
set session optimizer_where_cost=10;
--source include/explain-no-costs.inc
explain format=json select * from t1 where t1.a between 3 and 8 and t1.b between 4000 and 4100 order by t1.b desc;
select * from t1 where t1.a between 3 and 8 and t1.b between 4000 and 4100 order by t1.b desc;
--disable_ps_protocol
flush status;
select * from t1 where t1.a between 3 and 8 and t1.b between 4000 and 4100 order by t1.b desc;
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
--enable_ps_protocol
--source include/explain-no-costs.inc
explain format=json select * from t1 where t1.a between 2 and 9 and t1.b between 4000 and 5001 order by t1.b desc;
select * from t1 where t1.a between 2 and 9 and t1.b between 4000 and 5001 order by t1.b desc;
--disable_ps_protocol
flush status;
select * from t1 where t1.a between 2 and 9 and t1.b between 4000 and 5001 order by t1.b desc;
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
--enable_ps_protocol
set @old_optimizer_switch=@@optimizer_switch;
set optimizer_switch='index_condition_pushdown=off';
--source include/explain-no-costs.inc
explain format=json select * from t1 where t1.a between 3 and 8 and t1.b between 4000 and 4100 order by t1.b desc;
select * from t1 where t1.a between 3 and 8 and t1.b between 4000 and 4100 order by t1.b desc;
--disable_ps_protocol
flush status;
select * from t1 where t1.a between 2 and 9 and t1.b between 4000 and 5001 order by t1.b desc;
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
--enable_ps_protocol
set optimizer_switch=@old_optimizer_switch;
set session optimizer_where_cost=@old_where_cost;
drop table t1;