当前位置:网站首页>输入的查询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" ;边栏推荐
- Five thousand words to clarify team self-organization construction | Liga wonderful talk
- 78 year old professor Huake impacts the IPO, and Fengnian capital is expected to reap dozens of times the return
- 2022年DCMM认证全国各地补贴政策汇总
- 简单易用的地图可视化
- Blue bridge: sympodial plant
- Flask 轻量web框架
- Detectron2 installation method
- The top half and bottom half of the interrupt are introduced and the implementation method (tasklet and work queue)
- ISO27001认证办理流程及2022年补贴政策汇总
- LD_LIBRARY_PATH 环境变量设置
猜你喜欢

Why are some online concerts always weird?

TCP waves twice, have you seen it? What about four handshakes?

Grain Mall (I)

DB engines database ranking in July 2022: Microsoft SQL Server rose sharply, Oracle fell sharply

使用3DMAX制作一枚手雷

谷粒商城(一)

被忽视的问题:测试环境配置管理

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

mysql5.7安装教程图文详解

The controversial line of energy replenishment: will fast charging lead to reunification?
随机推荐
General environmental instructions for the project
People in the workplace with a miserable expression
android使用SQLiteOpenHelper闪退
ARTS_20220628
机器学习概念漂移检测方法(Aporia)
设置窗体透明 隐藏任务栏 与全屏显示
你应该懂些CI/CD
【系统盘转回U盘】记录系统盘转回U盘的操作
Detectron2 installation method
[daily question] 871 Minimum refueling times
上市公司改名,科学还是玄学?
shell脚本的替换功能实现
Grain Mall (I)
要上市的威马,依然给不了百度信心
被忽视的问题:测试环境配置管理
Initial experience of domestic database tidb: simple and easy to use, quick to start
Tutorial on the use of Huawei cloud modelarts (with detailed illustrations)
【每日一题】556. 下一个更大元素 III
What if Kaili can't input Chinese???
[proteus simulation] printf debugging output example based on VSM serial port