SQL233. 针对上面的salaries表emp_no字段创建索引idx_emp_no
描述
针对salaries表emp_no字段创建索引idx_emp_no,查询emp_no为10005,使用强制索引。示例1
输入:
drop table if exists salaries; CREATE TABLE `salaries` ( `emp_no` int(11) NOT NULL, `salary` int(11) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL, PRIMARY KEY (`emp_no`,`from_date`)); create index idx_emp_no on salaries(emp_no); INSERT INTO salaries VALUES(10005,78228,'1989-09-12','1990-09-12'); INSERT INTO salaries VALUES(10005,94692,'2001-09-09','9999-01-01');
输出:
10005|78228|1989-09-12|1990-09-12 10005|94692|2001-09-09|9999-01-01
Sqlite 解法, 执行用时: 9ms, 内存消耗: 3308KB, 提交时间: 2021-06-04
select * from salaries indexed by idx_emp_no where emp_no = 10005
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3192KB, 提交时间: 2020-10-30
select * from salaries indexed by idx_emp_no where emp_no = 10005
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3272KB, 提交时间: 2020-07-12
SELECT * FROM salaries INDEXED BY idx_emp_no WHERE emp_no = 10005
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3280KB, 提交时间: 2020-07-12
select * from salaries indexed by idx_emp_no where emp_no = 10005
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3296KB, 提交时间: 2020-08-01
select * from salaries indexed by idx_emp_no where emp_no = 10005;