当前位置:网站首页>Database notes 04
Database notes 04
2022-07-07 06:09:00 【ZMC Xi】
Database notes 04
Indexes
- Indexes are added by fields in database tables , It is a mechanism to improve query efficiency , An index can be added to a field of a table , Of course, you can also add indexes to multiple fields ,index It is equivalent to the catalogue of a book , It is a mechanism that exists to narrow the scope of scanning
- MySQL There are two ways to query : Full table scan , Search by index
- stay MySQL in index It is also necessary to sort , The way of sorting is Balanced binary trees Data structure of : Left small right big
- Index objects will be added to the primary key in any database , When the field exists unique When restrained , The index will also be created
- In the database , A record of any table has a physical storage number on the hard disk ( Equivalent to address )
- stay MySQL in ,index Is a separate object , Different storage engines index Store in different places ; But no matter where it is stored , The data structures used are B-tree( Self balanced binary trees )
The process of indexing
for example : To find a value on a field , Through the first index Search for , Then you can find a physical number , You can directly query the record through this number , Such queries will be faster , So as to avoid global search .
Conditions for adding indexes
- Huge data
- This field often appears in where Back , That is to say, this field is often queried
- This field is rarely used DML sentence , because DML Statement will cause index refactoring
Adding too many indexes is generally not recommended , Because the index also needs to be maintained , And too many will slow down the query , Generally recommended
primary keyoruniqueConstrained fields are added index To query , In this way, its efficiency will be much faster
The creation process
create index index_name on table_name(column_name);
Delete process :
drop index index_name on table_name;
Use alter Create :( General index )
alter table table_name add index index_name ( Field name );
Create primary key index :
alter table table_name add primary key ( Field name );
Create unique index :
alter table table_name add unique index_name ( Field name );
Check whether to use index: Use explain keyword , Followed by Query statement
create Can't create primary key Indexes , While using alter You can create multiple
Index failure
- In the process of query
likeFuzzy query - Created a composite index , But the index on the left is not used
- In the process of querying ,where Later, the indexed fields use arithmetic operations
- In the process of querying ,where Later, the function is used by the indexed field
- Use or when , Only or When there are indexes on both sides , Will query according to the index , Otherwise, the index will not be used
Index is an important means of optimization in various databases
Classification of indexes
| classification | Interpretation of the |
|---|---|
| Single index | Add an index to a single field |
| Composite index | Join multiple fields to add an index |
| unique index | primary key Add on field |
| primary key | unique Add on field |
There is no need to add fields with weak uniqueness index, Not very useful
View (view)
Look at the same data from different angles
Create view :
create view view_name as Follow dql sentence ;Delete view
drop view view_name;Add views , Delete , Change , The data of the original table will also be changed
Using views, you can create view objects associated with multiple tables
Using views can reduce operations , It can reduce the complexity of development , Make a long one SQL Statements can be converted into view objects to operate on them , This can improve development efficiency .
The view is stored on the hard disk ,
Additions and deletions :CRUD
DBA
- export :mysqldump database > route -u XXXX -p XXXX( On the command line )
- Import :source route
Three paradigms for database design
- Every table has a primary key , Every field is indivisible
- Rely on the first paradigm , All non primary key fields are required to rely on primary keys , Can't generate partial dependence
- Rely on the second paradigm , All non primary key fields depend on primary keys , Cannot generate delivery dependency
Second normal form : Generally need Foreign key constraints To achieve Many to many ; Many to many formula :” Many to many , Three tables , Relationship table two foreign keys “
Third normal form : You also need to use foreign key constraints to solve ;
One to many formula :” One to many , Two tables , More tables with foreign keys “
one-on-one : Maybe because of too much data , You may need to split into multiple tables , When connecting , Need to pass through Foreign key constraints and unique Constraints to achieve one-to-one correspondence .
Finally, the customer's needs are taken as the standard , The three paradigms just stay in theory , Sometimes there may be redundancy ( Space ) Change speed ( Time ), Because when the table is connected too much , Query efficiency will be reduced . Written in this way sql The statement will become simple , Writing difficulty decreases
边栏推荐
- Say sqlyog deceived me!
- Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)
- PTA ladder game exercise set l2-004 search tree judgment
- JVM command - jmap: export memory image file & memory usage
- PTA 天梯赛练习题集 L2-004 搜索树判断
- Financial risk control practice - decision tree rule mining template
- Career experience feedback to novice programmers
- 盘点国内有哪些EDA公司?
- MySQL performance_ Schema common performance diagnosis query
- Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
猜你喜欢

外设驱动库开发笔记43:GPIO模拟SPI驱动

cf:C. Column Swapping【排序 + 模拟】

Introduction to yarn (one article is enough)

绕过open_basedir

Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();

目标检测中的BBox 回归损失函数-L2,smooth L1,IoU,GIoU,DIoU,CIoU,Focal-EIoU,Alpha-IoU,SIoU

产业金融3.0:“疏通血管”的金融科技

SubGHz, LoRaWAN, NB-IoT, 物联网

Interview skills of software testing

Reading notes of Clickhouse principle analysis and Application Practice (6)
随机推荐
SAP ABAP BDC (batch data communication) -018
Sequential storage of stacks
jmeter 函数助手 — — 随机值、随机字符串、 固定值随机提取
360织语发布7.0新品 为党政军、央国企打造专属“统一数字工作空间”
[FPGA tutorial case 14] design and implementation of FIR filter based on vivado core
STM32按键状态机2——状态简化与增加长按功能
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用shap决策图结合LightGBM模型实现异常值检测案例之详细攻略
Jinfo of JVM command: view and modify JVM configuration parameters in real time
苹果cms V10模板/MXone Pro自适应影视电影网站模板
10W word segmentation searches per second, the product manager raised another demand!!! (Collection)
Swagger3 configuration
Input of native applet switches between text and password types
PowerPivot - DAX (function)
Type de texte de commutation d'entrée et de mot de passe de l'applet natif
线性回归
深度聚类:将深度表示学习和聚类联合优化
Bypass open_ basedir
绕过open_basedir
Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)
CMD permanently delete specified folders and files