麒麟v10 上部署 TiDB v5.1.2 生产环境优化实践
1266
2023-05-15
记一次***数据库实验--索引的常见执行计划
概述
今天主要介绍下***索引的常见执行计划:
INDEX FULL SCAN:索引的全扫描,单块读,有序INDEX RANGE SCAN:索引的范围扫描INDEX FAST FULL SCAN:索引的快速全扫描,多块读,无序INDEX FULL SCAN(MIN/MAX):针对MAX(),MIN()函数的查询INDEX SKIP SCAN:查询条件没有用到组合索引的第一列,而组合索引的第一列重复度较高时,可能用到。
这里用简单的测试案例,体会下索引使用这些执行计划的场景。
1. 准备测试环境
创建测试表和索引:
drop table test_objects; create table test_objects as select * from all_objects; create index idx_test_objects_1 on test_objects(owner, object_name, subobject_name); create index idx_test_objects_2 on test_objects(object_id); desc test_objects;
查看测试表上的索引信息:
select index_name, column_name, column_position from user_ind_columns where table_name = 'TEST_OBJECTS';
分析表并清空测试环境的shared_pool和buffer_cache:
2. 准备SQL语句
根据不同执行计划的场景,编写SQL语句:
--INDEX RANGE SCAN(索引的范围扫描) SELECT owner, object_name FROM test_objects WHERE owner = 'SYS' AND object_name = 'DBMS_OUTPUT'; --INDEX SKIP SCAN(针对MAX(),MIN()函数的查询) SELECT owner, object_name FROM test_objects WHERE object_name = 'DBMS_OUTPUT'; --INDEX FAST FULL SCAN(索引的快速全扫描,多块读,无序) SELECT owner, object_name FROM test_objects; --INDEX FULL SCAN(索引的全扫描,单块读,有序) SELECT owner, object_name FROM test_objects order by 1, 2; --INDEX FULL SCAN (MIN/MAX)(针对MAX(),MIN()函数的查询) SELECT max(object_id) FROM test_objects;
3. 实验论证
结果如下:
(1) INDEX RANGE SCAN
set autotrace traceonly SELECT owner, object_name FROM test_objects WHERE owner = 'SYS' AND object_name = 'DBMS_OUTPUT';
(2) INDEX SKIP SCAN
SELECT owner, object_name FROM test_objects WHERE object_name = 'DBMS_OUTPUT';
(3) INDEX FAST FULL SCAN
SELECT owner, object_name FROM test_objects;
(4) INDEX FULL SCAN
SELECT owner, object_name FROM test_objects order by 1, 2;
(5) INDEX FULL SCAN (MIN/MAX)
SELECT max(object_id) FROM test_objects;
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。