当前位置:网站首页>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’;
边栏推荐
- Common method signatures and meanings of Iterable, collection and list
- 1142_ SiCp learning notes_ Functions and processes created by functions_ Linear recursion and iteration
- Invalid table alias or column reference`xxx`
- Tianqing sends instructions to bypass the secondary verification
- [UTCTF2020]file header
- 【性能压测】如何做好性能压测?
- Tencent's one-day life
- leanote私有云笔记搭建
- Rust Versus Go(哪种是我的首选语言?)
- 2022年茶艺师(中级)考试试题及模拟考试
猜你喜欢

nacos

Most elements
![[Stanford Jiwang cs144 project] lab4: tcpconnection](/img/fd/704d19287a12290f779cfc223c71c8.png)
[Stanford Jiwang cs144 project] lab4: tcpconnection

Jenkins remote build project timeout problem

Hands on deep learning (IV) -- convolutional neural network CNN

Idea add class annotation template and method template

3D reconstruction - stereo correction

Resource create package method

idea添加类注释模板和方法模板

【经验分享】如何为visio扩展云服务图标
随机推荐
[2022 CISCN]初赛 web题目复现
After the interview, the interviewer roast in the circle of friends
2022焊工(初级)判断题及在线模拟考试
buuctf misc USB
leetcode:105. Constructing binary trees from preorder and inorder traversal sequences
【斯坦福计网CS144项目】Lab4: TCPConnection
IO流 file
即刻报名|飞桨黑客马拉松第三期等你挑战
Redis technology leak detection and filling (II) - expired deletion strategy
电商常规问题part1
Value sequence (subsequence contribution problem)
1140_ SiCp learning notes_ Use Newton's method to solve the square root
Leetcode-206. Reverse Linked List
Why is the row of SQL_ The ranking returned by number is 1
自定义类加载器加载网络Class
After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
Numbers that appear only once
【VHDL 并行语句执行】
Leetcode-543. Diameter of Binary Tree
[performance pressure test] how to do a good job of performance pressure test?