【 使用环境 】生产环境 or 测试环境
【 OB or 其他组件 】
【 使用版本 】
【问题描述】
如下图所示,这种剪枝法,会不会漏掉下述场景:
create table test(id int primary key , c1 int, c2 int, c3 int, key idx1
(c1), key idx2
(c2, c3))
其中,c1 ndv 比 c2 ndv 大很多,接近 unique
SQL: SELECT * from test where c1 = ? and c2 = ? order by c3 ;
在 skyline阶段,是不是一定会把idx1 减掉?
https://www.oceanbase.com/docs/common-oceanbase-database-cn-10000000001699696
【复现路径】问题出现前后相关操作
【问题现象及影响】
【附件】
此贴终结:测试发现不会出现上述情况:
mysql> explain extended select * from test12 where c1 = 1 and c2 = 1 order by c3;
±-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Query Plan |
±-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ==========================================
|ID|OPERATOR |NAME |EST. ROWS|COST|
|0 |SORT | |1 |89 |
|1 | TABLE SCAN|test12(c2)|1 |89 |
Outputs & filters:
0 - output([test12.id(0x7ec69d8e8a90)], [test12.c1(0x7ec69d8e7aa0)], [test12.c2(0x7ec69d8e8810)], [test12.c3(0x7ec69d8e8d10)]), filter(nil), sort_keys([test12.c3(0x7ec69d8e8d10), ASC])
1 - output([test12.c1(0x7ec69d8e7aa0)], [test12.c2(0x7ec69d8e8810)], [test12.id(0x7ec69d8e8a90)], [test12.c3(0x7ec69d8e8d10)]), filter([test12.c1(0x7ec69d8e7aa0) = 1(0x7ec69d8e7450)]),
access([test12.c1(0x7ec69d8e7aa0)], [test12.c2(0x7ec69d8e8810)], [test12.id(0x7ec69d8e8a90)], [test12.c3(0x7ec69d8e8d10)]), partitions(p0),
is_index_back=true, filter_before_indexback[false],
range_key([test12.c2(0x7ec69d8e8810)], [test12.id(0x7ec69d8e8a90)]), range(1,MIN ; 1,MAX),
range_cond([test12.c2(0x7ec69d8e8810) = 1(0x7ec69d8e81c0)])
Used Hint:
/*+
*/
Outline Data:
/*+
BEGIN_OUTLINE_DATA
INDEX(@“SEL$1” “test.test12”@“SEL$1” “c2”)
END_OUTLINE_DATA
*/
Plan Type:
LOCAL
Optimization Info:
test12:table_rows:722800, physical_range_rows:1, logical_range_rows:1, index_back_rows:1, output_rows:0, est_method:local_storage, optimization_method=cost_based, avaiable_index_name[test12,c1,c2], estimation info[table_id:1100611139454625, (table_type:1, version:0-1680514894590276-1680514894590276, logical_rc:1, physical_rc:1), (table_type:0, version:1680514597951223-1680514597951223-9223372036854775807, logical_rc:0, physical_rc:0)]
Parameters
|
±-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.04 sec)
mysql> show create table test12;
±-------±----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
±-------±----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| test12 | CREATE TABLE test12
(
id
int(11) NOT NULL,
c1
int(11) DEFAULT NULL,
c2
int(11) DEFAULT NULL,
c3
int(11) DEFAULT NULL,
PRIMARY KEY (id
),
KEY c1
(c1
, c3
) BLOCK_SIZE 16384 LOCAL,
KEY c2
(c2
) BLOCK_SIZE 16384 LOCAL
) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = ‘zstd_1.0’ REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 10 |
±-------±----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.04 sec)
mysql>
溪峰
2023 年4 月 3 日 18:58
#4
目前是不会发生裁剪的,本质原因在于贡献抽取的query-range列集合不存在dominate关系,对于idx1(c1)这个索引,贡献query-range的列集合是{c1}, 对于idx2(c2,c3) 贡献query-range的列集合是{c2}, 这两个集合不存在子集关系,也就是不存在dominate关系,所以不会做裁剪的
1 个赞
好的,之前对文章理解得不够深,测试发现确实是这样,感谢大佬解答