当前位置:网站首页>输入的查询SQL语句,是如何执行的?
输入的查询SQL语句,是如何执行的?
2022-07-04 16:33:00 【InfoQ】
select * from where id ='1';

Server服务层
连接器
mysql -h$ip -P$port -u$user -p- 如果用户名或密码不对,你就会收到一个“Access denied for user”的错误,然后客户端程序结束执行。
- 如果用户名密码认证通过,连接器会到权限表里面查出你拥有的权限。之后,这个连接里面的权限判断逻辑,都将依赖于此时读到的权限。

- 定期断开长连接。使用一段时间,或者程序里面判断执行过一个占用内存的大查询后,断开连接,之后要查询再重连。
- 如果你用的是 MySQL 5.7 或更新版本,可以在每次执行一个比较大的操作后,通过执行 mysql_reset_connection 来重新初始化连接资源。这个过程不需要重连和重新做权限验证,但是会将连接恢复到刚刚创建完时的状态。
查询缓存
mysql> select SQL_CACHE * from T where ID=10;分析器
mysql> elect * from t where ID=1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'elect * from t where ID=1' at line 1优化器
- 选择最合适的索引;
- 选择表扫还是走索引;
- 选择表关联顺序;
- 优化 where 子句;
- 排除管理中无用表;
- 决定 order by 和 group by 是否走索引;
- 尝试使用 inner join 替换 outer join;
- 简化子查询,决定结果缓存;
执行器
mysql> select * from T where ID=10;
ERROR 1142 (42000): SELECT command denied to user 'b'@'localhost' for table 'T'- 调用 InnoDB 引擎接口取这个表的第一行,判断 ID 值是不是 10,如果不是则跳过,如果是则将这行存在结果集中;
- 调用引擎接口取"下一行",重复相同的判断逻辑,直到取到这个表的最后一行。
- 执行器将上述遍历过程中所有满足条件的行组成的记录集作为结果集返回给客户端。
存储引擎
InnoDB存储引擎
- 经常更新的表,适合处理多重并发的更新请求。
- 支持事务。
- 可以从灾难中恢复(通过bin-log日志等)。
- 外键约束。只有他支持外键。
- 支持自动增加列属性auto_increment。
MyISAM存储引擎
- 不支持事务的设计,但是并不代表着有事务操作的项目不能用MyISAM存储引擎,完全可以在程序层进行根据自己的业务需求进行相应的控制。
- 不支持外键的表设计。
- 查询速度很快,如果数据库insert和update的操作比较多的话比较适用。
- 整天 对表进行加锁的场景。
- MyISAM极度强调快速读取操作。
- MyIASM中存储了表的行数,于是SELECT COUNT(*) FROM TABLE时只需要直接读取已经保存好的值而不需要进行全表扫描。如果表的读操作远远多于写操作且不需要数据库事务的支持,那么MyIASM也是很好的选择。
MySQL内建的其他存储引擎
Archive存储引擎
黑洞存储引擎
CSV存储引擎
Memory存储引擎
- 用于查找或者映射表,例如将邮箱和州名映射的表。
- 用于缓存周期性聚合数据的结果。
- 用于保存数据分析中产生的中间数据。
如何选择合适的存储引擎呢
- 事务
- 备份
- 恢复
- 特有的特性
其他查找引擎SQL
mysql> show variables like '%storage_engine%';
--查看表的存储引擎
show table status like "table_name" ;边栏推荐
- Dynamic programming stock problem comparison
- Grain Mall (I)
- Interpretation of data security governance capability evaluation framework 2.0, the fourth batch of DSG evaluation collection
- ITSS运维能力成熟度分级详解|一文搞清ITSS证书
- mysql5.7安装教程图文详解
- LD_ LIBRARY_ Path environment variable setting
- 超标量处理器设计 姚永斌 第6章 指令解码 摘录
- 【209】go语言的学习思想
- Win32 API 访问路由的加密网页
- 一直以为做报表只能用EXCEL和PPT,直到我看到了这套模板(附模板)
猜你喜欢

上市公司改名,科学还是玄学?

Superscalar processor design yaoyongbin Chapter 7 register rename excerpt

Stars open stores, return, return, return

Talk about seven ways to realize asynchronous programming

78岁华科教授冲击IPO,丰年资本有望斩获数十倍回报

I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)

Mathematical analysis_ Notes_ Chapter 7: differential calculus of multivariate functions

90后开始攒钱植发,又一个IPO来了

Superscalar processor design yaoyongbin Chapter 6 instruction decoding excerpt

ISO27001认证办理流程及2022年补贴政策汇总
随机推荐
The money circle boss, who is richer than Li Ka Shing, has just bought a building in Saudi Arabia
Grain Mall (I)
MVC mode and three-tier architecture
With an estimated value of 90billion, the IPO of super chip is coming
Recast of recastnavigation
How to improve development quality
俄罗斯 Arenadata 发布基于PostgreSQL的产品
被忽视的问题:测试环境配置管理
项目通用环境使用说明
Ks007 realizes personal blog system based on JSP
2022 national CMMI certification subsidy policy | Changxu consulting
I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)
Is it safe to open an account online? is that true?
Thawte通配符SSL证书提供的类型有哪些
[HCIA continuous update] WAN technology
New technology releases a small program UNIPRO to meet customers' mobile office scenarios
要上市的威马,依然给不了百度信心
超标量处理器设计 姚永斌 第6章 指令解码 摘录
Rainfall warning broadcast automatic data platform bwii broadcast warning monitor
Detectron2 installation method