当前位置:网站首页>一些小知识点
一些小知识点
2022-07-01 04:06:00 【speoki】
(1)使用mysql进行集合运算
1.并集 union 取并集
SELECT product_id, product_name
FROM product
UNION
SELECT product_id, product_name
FROM product2;
2.差集 not in
SELECT *
FROM Product
WHERE product_id NOT IN (SELECT product_id
FROM Product2)
3.交集 inner join
SELECT p1.product_id, p1.product_name
FROM Product p1
INNER JOIN Product2 p2
ON p1.product_id=p2.product_id
- 对称差
SELECT *
FROM Product
WHERE product_id NOT IN (SELECT product_id FROM Product2)
UNION
SELECT *
FROM Product2
WHERE product_id NOT IN (SELECT product_id FROM Product)
5.笛卡儿积 cross join
笛卡尔积:
SELECT SP.shop_id
,SP.shop_name
,SP.product_id
,P.product_name
,P.sale_price
FROM ShopProduct AS SP
CROSS JOIN Product AS P;
(2)mysql 破除死锁的方法
设置事务等待的超时时间
innodb_lock_wait_timeout
- 开启主动死锁检测
innodb_deadlock_detect
(3) 查看最近发生的一次死锁的信息
show engine innodb status
(4)mysql执行一条sql语句的流程
首先第一步其实是查询缓存,但是mysql8取消了查询缓存。虽然查询缓存提升系统的性能,但是维护缓存的开销也比较大
解析语句(查询分析)
select title from order where id=1
①词法分析 将关键字提取出来,上面这句sql会被分成8个部分
在elasticsearch引擎中也有一个字典对语句进行分词
②语法分析 根据词法分析的结果,生成语法树(解析树),判断sql语句是否满足语法规则。
如果语句有语法错误的话会在这个时候显示‘You have an error in your SQL syntax’
- 查询检查(预处理器)
①语义分析
形成关系代数转化成的语义树
②符号名转化
将变量和符号表中的定义绑定
如果字段名和表名不存在会报错 UnKnow column ‘abc’ in ‘field list’
③安全性检查
- 自主存取控制
- 强制存取控制
④完整性初步检查
- 参照完整性
- 实体完整性
- 用户定义完整性
- 查询优化(优化器)
mysql 使用基于开销的优化器,选择开销较小的计划
mysql通过查询当前会话的 last_query_cost的值来得到计算当前查询的成本
查看last_query_cost的命令:show status like ‘last_query_cost’
考虑的开销可能有:每张表或者索引的页面个数,索引的基数,索引和数据行的长度。索引的分布等等。
优化的策略有:
① 重新定义表的关联顺序,这时候要看表的大小,或者有可能将将外连接转换为内连接,子查询转化为连接
②优化查找最大最小函数
③优化排序
…
- 查询执行(执行器)
对上述得到的执行策略生成执行计划,让代码生成器执行这个查询计划,从存储引擎取出数据返回给客户端
边栏推荐
- 8. string conversion integer (ATOI)
- LeetCode 1399. Count the maximum number of groups
- The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
- [TA frost wolf _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API
- LeetCode 1827. Increment array with minimal operation
- 采购数智化爆发在即,支出宝'3+2'体系助力企业打造核心竞争优势
- 跳槽一次涨8k,5年跳了3次...
- 【无标题】
- Loop filtering based on Unet
- Embedded System Development Notes 80: using QT designer to design the main interface
猜你喜欢

Loop filtering based on Unet

TS type gymnastics: illustrating a complex advanced type

LeetCode 1828. Count the number of points in a circle

Web components series (VIII) -- custom component style settings

HoloLens2开发环境搭建及部署app

Go learning --- unit test subtest

Visit the image URL stored by Alibaba cloud to preview the thumbnail directly on the web page instead of downloading it directly

Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination

283. move zero

It's settled! 2022 JD cloud summit of JD global technology Explorer conference see you in Beijing on July 13
随机推荐
基于Unet的环路滤波
8. string conversion integer (ATOI)
多次跳槽后,月薪等于老同事的年薪
高并发下接口幂等性如何保证?
“目标检测“+“视觉理解“实现对输入图像的理解
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture
392. judgment subsequence
Why can't you find the corresponding function by clicking go to definiton (super easy has a diagram)
Libevent Library Learning
【TA-霜狼_may-《百人计划》】1.2.2 矩阵计算
Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
165. 比较版本号
Millet College wechat scanning code login process record and bug resolution
The programmer's girlfriend gave me a fatigue driving test
NFT: start NFT royalty journey with eip-2981
Huawei simulator ENSP - hcip - Hybrid Experiment 2
[send email with error] 535 error:authentication failed
It's settled! 2022 JD cloud summit of JD global technology Explorer conference see you in Beijing on July 13
10. regular expression matching
Promql select time series