当前位置:网站首页>Linux server development, SQL statements, indexes, views, stored procedures, triggers
Linux server development, SQL statements, indexes, views, stored procedures, triggers
2022-07-07 07:50:00 【Tuen Mun pheasant calls me chicken】
Recommend a free open course of zero sound College , Personally, I think the teacher spoke well , Share with you :Linux,Nginx,ZeroMQ,MySQL,Redis,fastdfs,MongoDB,ZK, Streaming media ,CDN,P2P,K8S,Docker,TCP/IP, coroutines ,DPDK Etc , Learn now
1. Architecture
select(listen+1,readfd,NULL,NILL,0);
int clientfd=accept(listenfd,&addr,&len);
my_sql_thread_create(key_thread_one_connection,&id,^connection_atrrib,handle_connection,(void*)channel_info);
MySql Use a select() function , Only listen for read Events ,0 Indicates that the connection is blocked waiting for the connection to arrive . When the supervisor hears that the connection arrives , utilize accept() Accept the connection , Assign a thread to each connection , One fd One thread .redis use reactor Network encapsulation asynchronous mode , Operating memory , The difference is ,MySql In a blocking way , After all, hard disk operation is heavy IO operation .
Why? MySql Use connection pool ? There are three main points , First , Because it's blocked IO, You need to wait for a return to initiate another connection , Waiting time is too long , Affect the efficiency of execution . secondly ,MySql Short connection adopted , If you don't respond for a long time, the connection will be kicked out , Password verification and other operations are complicated , Connection pooling can reduce waiting time . Last ,MySql Can only support 150+ link , Connection pooling can make full use of the concurrency model .
SQL Processing flow
- SQL Interface:Sql Syntax analysis
- Parser: Object permission validation and filtering
- Optimizer: Analyze the specific execution path of the statement , According to the execution mode of cache analysis , Optimizer
- Cathes & Buffer: cache
MySql Adopt pluggable data engine , Use specific engines according to the table .
2. Three paradigms and anti paradigms of database
- Paradigm one : Make sure that each column remains atomic , All fields in the database are non decomposable atomic values .
- Formula Two : Make sure that every column in the table is related to the primary key , You can't just relate to a part of the primary key ( Composite index ).
- Formula 3 : Similar to II , Ensure that each column is directly related to the primary key , Not indirectly ; Reduce data redundancy .
- Anti paradigm : Paradigms can avoid data redundancy , Reduce database space , Reduce the trouble of maintaining data integrity ; However, the use of normal form results in more tables , Cause more connection queries , Affect performance , Therefore, anti - normal form design is also considered .
Be careful :
- Null queries do not go through the index , It is recommended not to judge empty .is null Cause index invalidation .
- LIMIT 1,2 The speed of range query is relatively fast .
- The purpose of grouping query is to remove duplicates and merge .
- in /not in A full scan will be performed
other
Delete the detail difference of the table
- DROP TABLE ‘table_name’; Delete table and table structure .
- TRUNCATE TABLE ‘table_name’; Truncation table , There is a self incrementing index that accumulates from the initial value . Relatively efficient .
- DELETE TABLE ‘table_name’; Delete line by line , There is a self incrementing index that continues to accumulate from the previous value .
Why? inodb To actively create a primary key , And take the self increasing integer as the primary key ?
Foreign key constraints
CREATE TABLE ‘course’{
‘cid’ int(11) NOT NULL AUTO_INCREMENT,
‘cname’ varchar(32) NOT NULL,
‘teacher_id’ int(11) NOT NULL,
PRIMARY KEY (‘cid’),
KET ‘fk_course_teacher’ (‘teacher_id’),
CONSTRAINT ‘fk_course_teacher’ FOREIGN KEY (‘teacher_id’) REFERENCES "teacher’(‘id’)
}ENGINE=InnoDB AUTO _INCREMENT=5 DEFAULT CHARSET=utf8;
– When the delete teacher In the table id Line time ,teacher_id It's also deleted .
Group aggregation
SELECT ‘gender’,GROUP CONCAT(sname) FROM ‘student’ GROUP BY ‘gender’;
边栏推荐
- [2022 ACTF]web题目复现
- pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
- 【webrtc】m98 screen和window采集
- [2022 ciscn] replay of preliminary web topics
- Make a bat file for cleaning system garbage
- Tongda injection 0day
- Pytest+allure+jenkins installation problem: pytest: error: unrecognized arguments: --alluredir
- [experience sharing] how to expand the cloud service icon for Visio
- [Stanford Jiwang cs144 project] lab4: tcpconnection
- Live online system source code, using valueanimator to achieve view zoom in and out animation effect
猜你喜欢
随机推荐
@component(““)
After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
探索Cassandra的去中心化分布式架构
【VHDL 并行语句执行】
【斯坦福计网CS144项目】Lab3: TCPSender
Regular e-commerce problems part1
[experience sharing] how to expand the cloud service icon for Visio
JS plot flot application - simple curve
[mathematical notes] radian
pytorch 参数初始化
Leetcode-543. Diameter of Binary Tree
Iterable、Collection、List 的常见方法签名以及含义
[guess-ctf2019] fake compressed packets
Live broadcast platform source code, foldable menu bar
leanote私有云笔记搭建
电商常规问题part1
海思芯片(hi3516dv300)uboot镜像生成过程详解
智联+影音,AITO问界M7想干翻的不止理想One
为什么要了解现货黄金走势?
leetcode:105. 从前序与中序遍历序列构造二叉树