当前位置:网站首页>输入的查询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" ;边栏推荐
- Superscalar processor design yaoyongbin Chapter 6 instruction decoding excerpt
- 同事悄悄告诉我,飞书通知还能这样玩
- 蓝桥:合根植物
- Open source PostgreSQL extension age for graph database was announced as the top-level project of Apache Software Foundation
- LD_ LIBRARY_ Path environment variable setting
- curl 命令妙用
- Clever use of curl command
- 中断的顶半部和底半部介绍以及实现方式(tasklet 和 工作队列)
- TCP waves twice, have you seen it? What about four handshakes?
- Unity makes revolving door, sliding door, cabinet door drawer, click the effect of automatic door opening and closing, and automatically play the sound effect (with editor extension code)
猜你喜欢

What if Kaili can't input Chinese???

Rainfall warning broadcast automatic data platform bwii broadcast warning monitor

Ks007 realizes personal blog system based on JSP

如何提高开发质量

Vscode modification indentation failed, indent four spaces as soon as it is saved

Load test practice of pingcode performance test

Once the "king of color TV", he sold pork before delisting
![[HCIA continuous update] WAN technology](/img/31/8e9ed888d22b15eda5ddcda9b8869b.png)
[HCIA continuous update] WAN technology

比李嘉诚还有钱的币圈大佬,刚在沙特买了楼

Numpy 的仿制 2
随机推荐
超标量处理器设计 姚永斌 第5章 指令集体系 摘录
【系统盘转回U盘】记录系统盘转回U盘的操作
I2C子系统之适配器的设备接口分析(i2c-dev.c文件分析)
明星开店,退,退,退
被忽视的问题:测试环境配置管理
Face_ Attendance statistics of recognition face recognition
Achieve animation effect through event binding
ITSS运维能力成熟度分级详解|一文搞清ITSS证书
设置窗体透明 隐藏任务栏 与全屏显示
Five thousand words to clarify team self-organization construction | Liga wonderful talk
Interpretation of data security governance capability evaluation framework 2.0, the fourth batch of DSG evaluation collection
[system disk back to U disk] record the operation of system disk back to U disk
78 year old professor Huake impacts the IPO, and Fengnian capital is expected to reap dozens of times the return
你应该懂些CI/CD
TCP两次挥手,你见过吗?那四次握手呢?
Rainfall warning broadcast automatic data platform bwii broadcast warning monitor
How to improve development quality
Device interface analysis of the adapter of I2C subsystem (I2C dev.c file analysis)
Heartless sword Chinese translation of Elizabeth Bishop's a skill
超标量处理器设计 姚永斌 第7章 寄存器重命名 摘录