当前位置:网站首页>输入的查询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" ;
边栏推荐
- Make a grenade with 3DMAX
- 超标量处理器设计 姚永斌 第5章 指令集体系 摘录
- 【210】PHP 定界符的用法
- Win32 API 访问路由的加密网页
- 78 year old professor Huake impacts the IPO, and Fengnian capital is expected to reap dozens of times the return
- 怎么开户才是安全的,
- Device interface analysis of the adapter of I2C subsystem (I2C dev.c file analysis)
- Five thousand words to clarify team self-organization construction | Liga wonderful talk
- mysql5.7安装教程图文详解
- 如何使用 wget 和 curl 下载文件
猜你喜欢
ISO27001认证办理流程及2022年补贴政策汇总
"In Vietnam, money is like lying on the street"
celebrate! Kelan sundb and Zhongchuang software complete the compatibility adaptation of seven products
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)
Blue bridge: sympodial plant
估值900亿,超级芯片IPO来了
Just today, four experts from HSBC gathered to discuss the problems of bank core system transformation, migration and reconstruction
[HCIA continuous update] network management and operation and maintenance
2022年全国CMMI认证补贴政策|昌旭咨询
People in the workplace with a miserable expression
随机推荐
How to test MDM products
Tutorial on the use of Huawei cloud modelarts (with detailed illustrations)
[HCIA continuous update] WAN technology
Blue bridge: sympodial plant
Lua emmylua annotation details
高中物理:力、物体和平衡
I wrote a learning and practice tutorial for beginners!
【每日一题】871. 最低加油次数
超标量处理器设计 姚永斌 第7章 寄存器重命名 摘录
Five thousand words to clarify team self-organization construction | Liga wonderful talk
High school physics: force, object and balance
Dynamic programming stock problem comparison
Once the "king of color TV", he sold pork before delisting
【210】PHP 定界符的用法
怎么开户才是安全的,
[cloud native] what is the "grid" of service grid?
android使用SQLiteOpenHelper闪退
Mathematical analysis_ Notes_ Chapter 7: differential calculus of multivariate functions
Is BigDecimal safe to calculate the amount? Look at these five pits~~
Implementation of shell script replacement function