题解 | #针对上面的salaries表emp_no字段创建索引idx_emp_no#

针对上面的salaries表emp_no字段创建索引idx_emp_no

http://www.nowcoder.com/practice/f9fa9dc1a1fc4130b08e26c22c7a1e5f

mysql 中使用 FORCE INDEX (indexname)

sqlite 中使用 INDEXED BY indexname

select *
from salaries
force index (idx_emp_no)
where emp_no = '10005'

可以通过在查询头部添加 EXPLAIN 来查看使用的 key 是否为 idx_emp_no

explain select *
from salaries
force index (idx_emp_no)
where emp_no = '10005'

结果为:

id	select_type	table		partitions	type		possible_keys	key			key_len		ref		rows	filtered	Extra
1	SIMPLE		salaries		null	ref			idx_emp_no		idx_emp_no	4			const	2		100.00		null
SQL练习 文章被收录于专栏

已完成牛客的SQL练习。接下来是算法的练习

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务