当前位置:网站首页>2022 latest MySQL interview questions

2022 latest MySQL interview questions

2022-06-21 14:54:00 Resourceful!

Catalog

 Insert picture description here

0. What is? MySQL?

MySQL Is a relational database management system , from Oracle Companies to develop 、 Release and support .

1、MySQL It's a database management system

    A database is a collection of structured data , It can be a picture of a simple shopping list or a large amount of information on the company's network , To add 、 Access and process data stored in corporate databases , You need a database management system , such as MySQL server. Because computers are very good at processing large amounts of data , As part of a stand-alone utility or other application , Database management system plays a very central role in computing .

2、MySQL The database is relational

    A relational database stores data in different tables , Instead of storing all the data in a large storage area . In order to improve storage speed , Structured data is stored in structured files . database 、 form 、 View 、 The logical model of objects such as rows and columns provides a flexible programming environment . You can set the rules of correspondence in different data fields pointing to different tables , Such as one-to-one 、 One to many 、 only 、 Required and optional . The database enforces these rules , therefore , In a well-designed database , Applications will never see inconsistencies 、 Repeated or isolated 、 Expired or missing data .


   MySQL Of SQL Part corresponds to structured query language ,SQL Is the most common standardized language for accessing databases . According to your programming environment , You can type SQL( Such as generating reports ), Or will SQL Language is embedded in other languages , Or in a special language API hide SQL grammar .


   SQL It's based on ANSI/ISO SQL Standard definition of .1986 Since then ,SQL Standards have been evolving , There have been several versions up to now , Such as 92 Version of the standard 、99 Version of the standard and 2003 Version of , At present, they basically use 2003 The latest version of the standard .

3、MySQL Software is open source

    Open source means that everyone can use and modify software . Everyone can download and use it on the Internet for free MySQL. You can learn and change the source code according to your personal needs ,MySQL The software uses GPL agreement .

4、MySQL The database server is fast 、 High reliability , Extensibility is strong , And easy to use

   MySQL The server can work with other applications on the desktop or laptop 、web Servers and so on , No special attention is needed . If the whole machine is to be used for MySQL, You can adjust MySQL Set up , To make full use of all memory 、CPU Capabilities and available input and output capabilities .MySQL It can also be extended to a group of machines , And connect them to the Internet .

5、MySQL The server is on the client side 、 Server or embedded system

   MySQL Database software is a client / Server system , By a multithreaded SQL Service composition , Support for different back ends 、 Multiple different client programs and Libraries 、 Management tools and extensive application program interfaces .MySQL The server can also be used as an embedded multithreading library , It can be connected to an application , To get smaller 、 faster , Stand alone products that are easier to manage .

6、 Provide a large number of MySQL Software support

   MySQL Support a large number of languages , Most application languages support MySQL Software . 

1、MySQL What kinds of locks are there ?

1、 Table lock : Low overhead , Locked fast ; A deadlock will not occur ; Large locking size , The probability of lock conflict is the highest high , Lowest degree of concurrency .

2、 Row-level locks : Spending big , Lock the slow ; A deadlock occurs ; Locking granularity minimum , The probability of lock conflict is the highest low , The highest degree of concurrency .

3、 Page lock : Cost and lock time are between table lock and row lock ; A deadlock occurs ; Locking granularity is bounded by the table Between lock and row lock , The concurrency is average .

2、MySQL What are the different tables in ?

share 5 Types of forms : 1、 MyISAM
2、 Heap
3、 Merge
4、 INNODB

5、 ISAM

3、 Brief description MySQL In the database MyISAM and InnoDB The difference between

MyISAM:

Unsupported transaction , But every query is atomic ;

Support table level lock , That is to say, every operation is to lock the whole table ; Store the total number of tables ;
One MYISAM The table has three files : Index file 、 Table structure file 、 Data files ;

Using the fey clustering index , The data field of the index file stores the pointer to the data file . Secondary index and primary index Almost the same , But secondary indexes don't guarantee uniqueness .

InnoDB:

Support ACID The business of , Support four isolation levels of transactions ; Supports row level locks and foreign key constraints : So write concurrency is supported ; Do not store the total number :
One InnoDb The engine is stored in a file space ( Shared tablespace , Table size is not controlled by the operating system , A table may be distributed in multiple files ), It's also possible for multiple ( Set to independent table empty , Table size is affected by
Operating system file size limit , It's usually 2G), Limited by operating system file size ;

The primary key index adopts the clustered index ( The indexed data field stores the data file itself ), The data field of the secondary index is saved Store the value of the primary key ; So look up the data from the secondary index , You need to find the primary key value through the secondary index first , Then visit the auxiliary Indexes ; It's better to use auto primary key , Prevent data insertion , To maintain B+ Tree structure , A big adjustment of the document .

4、MySQL in InnoDB Four supported transaction isolation level names , And the difference between levels ?

SQL The four isolation levels defined by the standard are :

1、 read uncommited : Read uncommitted data
2、 read committed: Dirty reading , It can't be read repeatedly
3、 repeatable read: Can be reread
4、 serializable : Serial things

5、CHAR and VARCHAR The difference between ?

1、 CHAR and VARCHAR Types differ in storage and Retrieval

2、 CHAR The column length is fixed to the length declared when the table is created , The length value range is 1 To 255 When CHAR When values are stored , They are filled with spaces to a specific length , retrieval CHAR Value to delete trailing space .

6、 What's the difference between a primary key and a candidate key ?

Each row of the table is uniquely identified by the primary key , A table has only one primary key .

The primary key is also a candidate key . By convention , Candidate keys can be specified as primary keys , And can be used for any foreign key quote .

7 、myisamchk What is it used for ?

It's used to compress MyISAM surface , This reduces disk or memory usage .

MyISAM Static  and  MyISAM Dynamic  What's the difference? ?

stay MyISAM Static All fields on have a fixed width . dynamic MyISAM The watch will have a look like TEXT, BLOB Etc , To accommodate different length data types .

MyISAM Static Easier to recover in case of damage .

8、 If a table has a column defined as TIMESTAMP, What will happen ?

Every time a line is changed , The timestamp field will get the current timestamp .

The column is set to AUTO INCREMENT when , If the maximum value is reached in the table , What will happen ?

It will stop increasing , Any further insertion will result in an error , Because the key is already in use .

How to find out which auto increment was allocated at the last insert ?

LAST_INSERT_ID Will be returned by Auto_increment Last value assigned , And you don't have to point to Name of rating table .

9、 How do you see all the indexes defined for the table ?

An index is defined for a table by :

SHOW INDEX FROM ;

10、LIKE Statement % and _ What does that mean? ?

% Corresponding to 0 Characters or more ,_ It's just LIKE A character in a statement .

How to be in Unix and MySQL Conversion between timestamps ?

UNIX_TIMESTAMP It's from MySQL The timestamp is converted to Unix Time stamp order
FROM_UNIXTIME It's from Unix The timestamp is converted to MySQL Time stamp order

11、 What is the column comparison operator ?

stay SELECT Use... In column comparison of statements =,<>,<=,<,> =,>,<<,>>,<=>,AND, OR or LIKE Operator .

12、BLOB and TEXT What's the difference? ?

BLOB It's a binary object , Can hold a variable amount of data . TEXT Is a case insensitive Of BLOB.

BLOB and TEXT The only difference between types is that they are right BLOB Values are case sensitive when sorting and comparing Write , Yes TEXT Value is case insensitive .

13、MySQL_fetch_array and MySQL_fetch_object Is the difference between the what ?

Here are MySQL_fetch_array and MySQL_fetch_object The difference between :

MySQL_fetch_array( ) – Return the result row as an associative array or as a regular array from the database . MySQL_fetch_object – Return the result line from the database as an object .

14、MyISAM Where will the forms be stored , And also provides its storage format ?

Every MyISAM Tables are stored on disk in three formats :

·“.frm” File storage table definition

· The data file has “.MYD” ( MYData) Extension Indexes

15、MySQL How to optimize DISTINCT?

DISTINCT Convert to on all columns GROUP BY, And with ORDER BY Clause is used in conjunction with . SELECT DISTINCT t1.a FROM t1,t2 where t1.a=t2.a;

16、 How to display the front 50 That's ok ?

stay MySQL in , Use the following code to query the display before 50 That's ok : SELECT*FROM

LIMIT 0,50;

17、 How many columns can be used to create indexes ?

Any standard table can be created up to 16 Index columns .

18、NOW() and CURRENT_DATE() What's the difference? ?

NOW() The command is used to display the current year , month , date , Hours , Minutes and seconds . CURRENT_DATE() Show only the current year , Month and date .
#19、 What is nonstandard string type ?

1、 TINYTEXT

2、 TEXT

3、 MEDIUMTEXT

4、 LONGTEXT

20、 What is universal SQL function ?

1、CONCAT(A, B) – Concatenate two string values to create a single string output . through It is often used to combine two Merge one or more fields into one field .

2、 FORMAT(X, D)- Formatting Numbers X To D Significant figures .

3、 CURRDATE(), CURRTIME()- Returns the current date or time .

4、 NOW() – Returns the current date and time as a value .

5、 MONTH(), DAY( ), YEAR(), WEEK(), WEEKDAY() – From the date Extract the given data from the value .

6、 HOUR(), MINUTE(), SECOND() – Extract given data from time value .

7、 DATEDIFF( A, B) – Determine the difference between the two dates , Usually used to calculate age

8、 SUBTIMES( A, B) – Determine the difference between the two .

9、 FROMDAYS( INT) – Convert integer days to date values .

21、MySQL Do you support transactions ?

In default mode ,MySQL yes autocommit Mode , All database updates will be done immediately Submit , So by default , MySQL It doesn't support transactions .

But if yours MySQL The type of table is to use InnoDB Tables or BDB tables Words , you Of MySQL You can use transactions , Use SET
AUTOCOMMIT=0 You can make MySQL Allow in non autocommit Pattern , stay Not
autocommit In mode , you You have to use COMMIT To submit your changes , or To use ROLLBACK To roll back your changes .

22、MySQL What field type is good for recording currency in

NUMERIC and DECIMAL Type by MySQL Implement the same type , This is in SQL92 Standard permission xu . They are used to save values , The accuracy of this value is extremely important , For example, the number related to money According to the . When declaring a class is one of these types , Capable of precision and scale ( And it's usually ) Appoint .

for example :

salary DECIMAL(9,2)

In this case , 9(precision) Represents the total number of decimal places that will be used to store values , and 2(scale) generation The table will be used to store the number of digits after the decimal point .

therefore , under these circumstances , Can be stored in salary The range of values in the column is from -9999999.99 To 9999999.99.

23、MySQL What are the tables about permissions ?

MySQL The server controls the user's access to the database through the permission table , The authority list is stored in MySQL Count According to curry , from MySQL_install_db Script initialization . this Some authority tables are divided into other user,db,table_priv, columns_priv and host.

24、 What string types of columns can be ?

The string type is : 1、 SET

2、 BLOB

3、 ENUM

4、 CHAR

5、 TEXT

25、MySQL The database is used as the storage of the publishing system , More than 50000 increments a day , It is expected that the operation and maintenance will last for three years , How to optimize the ?

1、 Well designed database structure , Allow partial data redundancy , Try to avoid join Inquire about , Increase of efficiency .

2、 Select the appropriate table field data type and storage engine , Add index as appropriate .

3、 MySQL The library master is separated from the reader and the writer .

4、 Look for a regular score , Reduce the amount of data in a single table and improve the query speed . 5、 Add caching mechanism , such as memcached, apc etc. .
6、 Pages that don't change often , Generate static page .

7、 Write efficiently SQL. such as SELECT * FROM TABEL Change it to SELECT field_1, field_2, field_3 FROM TABLE.

26、 Lock optimization strategy

1、 Read / write separation

2、 Lock in sections

3、 Reduce lock holding time

4. Multiple threads try to get resources in the same order

The granularity of lock cannot be too refined , Otherwise, threads may be locked and released too many times , Instead, it works The rate is not as good as adding a big lock at a time .

27、 The underlying implementation principle and optimization of index

B+ Trees , Optimized B+ Trees

It mainly adds a pointer to the next leaf node among all leaf nodes , therefore InnoDB build It is recommended that most tables use the default self incrementing primary key as the primary index .

28、 When the index is set but cannot be used

1、 With “ %” At the beginning LIKE sentence , Fuzzy matching

2、 OR The index is not used before and after the statement

3、 Count There is an implicit conversion according to the type ( Such as varchar Without a single quotation mark, it may automatically convert to int type )

29、 How to optimize MySQL

It's best to optimize in the following order :

1、 SQL Statement and index optimization

2、 Database table structure optimization

3、 Optimization of system configuration

4、 Hardware optimization

Details can be found in Ali P8 Architect talk :MySQL Slow query optimization 、 Index optimization 、 And table optimization summary

30、 How to optimize the database

1、 choose Take the most applicable field attribute , all It is possible to reduce the definition field width , all Set the field to Set up NOTNULL, for example ’ Province ’ 、’ Gender ’ Best for ENUM

2、 Use connections (JOIN) Instead of subquery

3、 Applicable joint (UNION) Instead of manually created temporary tables
4、 Transaction processing

5、 Lock the table 、 Optimize transactions

6、 For foreign keys , Optimize lock table

7、 Index

8、 Optimize query statements

31、 A brief description MySQL in , Indexes , Primary key , unique index , The difference between federated indexes , What is the impact on the performance of the database ( From reading and writing )

Index is a special kind of file (InnoDB An index on a data table is an integral part of a table space ), they Contains a reference pointer to all records in the data table .

General index ( By keyword KEY or INDEX Index of definitions ) Our only task is to speed up access to data degree .

A normal index allows the indexed data column to contain duplicate values . If it can be determined that a data column will contain only that The different values , You should use keywords when creating an index for this data column UNIQUE Take it Defined as a unique index . in other words , Unique index can ensure the uniqueness of data records .

Primary key , Is a special unique index , Only one primary key index can be defined in a table , Primary key for unique Mark a record , Use keywords PRIMARY KEY To create .

The index can cover multiple data columns , similar to INDEX(columnA, columnB) Indexes , This is the United cable lead .

Index can greatly improve the query speed of data , But it will lower the insertion 、 Delete 、 Update table speed , Because when doing these writes , Also operate index files .

32、 What are the transactions in the database ?

Business ( transaction) Is a set of ordered database operations as a unit . If all in the group Operation succeeded , The transaction is considered successful , Even if only one operation fails , Things don't work . If so

The operation has been completed , Transaction commit , Its modification will affect all other database processes . If an operation
Failure , The transaction will be rolled back , The influence of the operation of the firm will be cancelled .

Transaction features :

1、 Atomicity : That is, indivisibility , The transaction is either all executed , Or not all of them .

2、 Consistency or stringability . The execution of transactions makes the database change from one correct state to another state

3、 Isolation, . Before the transaction is properly committed , It is not allowed to provide any changes to the data by this transaction to any Other business ,

4、 persistence . When the transaction is correctly committed , The results will be permanently stored in the database , Even after the transaction is committed There are other faults , The result of the transaction will also be saved .

Or to understand it like this :

Transactions are bound together as a logical unit of work SQL Statement grouping , If any language If the operation fails, the whole operation will fail , Later, the operation will roll back to the pre operation state , Or on There is a node. . In order to make sure that or carry out , Or not , You can use transactions . Make a group of statements Consider for business , It needs to pass ACID test , Atomicity , Uniformity , Isolation and persistence .

33、SQL The cause of injection hole ? How to prevent ?

SQL The cause of Injection : Don't pay attention to standard writing in the process of program development sql Statements and special characters
Line filter , guide To the client, you can use global variables POST and GET Submit some sql Statement executes normally .

prevent SQL The way of Injection :
Open... In the configuration file magic_quotes_gpc and magic_quotes_runtime Set up

perform sql Use addslashes Conduct sql Sentence conversion

Sql Try not to omit double quotation marks and single quotation marks in statement writing .

To filter out sql Some key words in the sentence : update、 insert、 delete、 select、 * .

Improve database table and field naming skills , Some important fields are named according to the characteristics of the program , Take no Easy to guess .

34、 Select the appropriate data type for the fields in the table

Field type priority : plastic >date,time>enum,char>varchar>blob,text
Number type is preferred , Next is the date or binary type , Finally, the string type , You have to data type , Priority should be given to data types that take up less space

35、 Storage period

Datatime: With YYYY-MM-DD HH:MM:SS Format storage period time , Accurate to seconds , Occupy 8 Bytes of storage space , datatime Type has nothing to do with time zone
Timestamp: Store in time stamp format , Occupy use 4 Bytes , Fan Wai Xiao 1970-1-1 To 2038-1-19, Display depends on the specified time zone , By default, the data of the first column and row can be modified automatically Change
timestamp The list is worth
Date:( Birthday ) It takes up more bytes than strings .datatime.int Less storage , Use date only need 3 Bytes , Storage date month , You can also use the date time function to calculate dates
Time: Store time part of the data
Be careful : Do not use string type to store date time numbers According to the ( It's usually smaller than a string , In search filtering you can use the date function )
Use int Storage date time is not as good as using timestamp type

36、 For relational databases , Index is a very important concept , Please answer the questions

Some questions about index :

1、 What is the purpose of the index ?

Quick access to specific information in data tables , Improve retrieval speed
Create a unique index , Ensure the uniqueness of each row of data in the database table . Connection between accelerometers and meters

When using grouping and sorting clauses for data retrieval , It can significantly reduce the time of grouping and sorting in queries

2、 What is the negative effect of index on database system ?

negative effect :

Creating and maintaining indexes takes time , This time increases with the amount of data ; The index needs Take up physical space , It's not just tables that need to take up data space , Each index also needs to occupy physical space ; When the watch is added 、 Delete 、 Change 、 Index should also be maintained dynamically , This reduces the speed of data maintenance degree .

3、 What are the principles for indexing data tables ?

In the most frequently used 、 To narrow the scope of the query to build an index on the field . In frequent use 、 Index the fields that need to be sorted

4、 When is it not appropriate to build an index ?

For the columns rarely involved in the query or the columns with more duplicate values , It's not good to index .

For some special data types , It's not good to index , For example, text field ( text) etc.

37、 explain MySQL External connection 、 The difference between internal connection and self connection

Let's talk about cross connect first : Cross connect is also called Cartesian product , It means not using any conditions , Direct a All records in one table match all records in another table one by one .

Internal connection It's a conditional cross connection , According to a certain condition to filter out the records that meet the conditions , Do not conform to the Records of conditions do not appear in the result set , That is to say, the inner link only connects the matching lines .
External connection The result set contains not only the rows that meet the join conditions , It also includes the left watch 、 Right table or two In the table
All data rows of , These three cases are called left outer connection in turn , Right connection , And all outside connection .

The left outer join , Also called left connection , Left table is the main table , All records in the left table appear in the result set , For those records that do not match in the right table , Still show , The values of the corresponding fields on the right are as follows NULL Fill in . Right connection , Also called right connection , The right table is the main one , All records in the right table will appear In the result set . Left connection and right connection can be interchanged , MySQL At present, it does not support all external connection .

38、Myql Overview of transaction rollback mechanism in

A transaction is a user-defined sequence of database operations , All or nothing of these operations , It's a Indivisible work unit , Transaction rollback refers to the cancellation of the database update operation that has been completed by the transaction pin .

When you want to modify two different tables in the database at the same time , If they are not a transaction , When the first watch repair It's over , Maybe there is an exception in the second table modification process and it can't be modified , At this time, there is only the second table Old is the state before modification , And the first table has been modified . And when you set them to a

When it comes to business , When the first table is modified , There is an exception in the second table modification and it can't be modified , The first table and
The second table should return to the unmodified state , This is called transaction rollback

39、SQL What are the parts of language ? What are the operation keywords in each part ?

SQL Language includes data definition (DDL)、 Count According to manipulation (DML), Data control (DCL) And data search Inquiry ( DQL) Four parts .

Data definition : Create Table,Alter Table,Drop Table, Craete/Drop Index etc.

Data manipulation : Select ,insert,update,delete,

Data control : grant,revoke

Data query : select

40、 What are the integrity constraints ?

Data integrity (Data Integrity) The accuracy of data (Accuracy) And reliability (Reliability).

It can be divided into four categories :

1、 Entity integrity : Specifies that each row of the table is the only entity in the table .

2、 Domain integrity : It means that the columns in the table must meet certain data type constraints , Constraints include Value range 、 Precision, etc .

3、 Referential integrity : It means that the data of the primary key and the external key of the two tables should be consistent , It ensures that between tables The consistency of the data of , Prevent data loss or meaningless data from spreading in the database .

4、 User defined integrity : Different RDBMS are based on different application environments , It often needs to be done
Some special constraints . User defined integrity is a constraint on a specific relational database Conditions , It reflects the semantic requirements that a specific application must meet .

Constraints related to tables : Include column constraints (NOT NULL( Non empty constraint )) And table constraints (PRIMARY KEY、 foreign key、 check、 UNIQUE) .

41、 What is a lock ?

answer : Database is a shared resource used by multiple users . When multiple users access data concurrently , In number Multiple transactions access the same data at the same time in the database . If you do not control concurrent operations, you can Can read and store incorrect data , Breaking database consistency .

Locking is a very important technology to realize database concurrency control . When a transaction is processing a data object Before the operation , Make a request to the system first , Lock it . After locking, the transaction has a certain effect on the data object The control of , Before the transaction releases the lock , Other transactions cannot update this data object .

Basic lock type : Locks include row level locks and table level locks

42、 What is view ? What is a cursor ?

answer : A view is a virtual table , It has the same function as the physical table . The view can be added , Change , check , operation , A view is usually a subset of rows or columns that have one or more tables . Changes to the view do not affect Ring the basic table . It makes it easier for us to get data , Compared to multi table query .

The cursor : It is to effectively process the result set as a unit . The cursor can be set in this unit A specific line in , Retrieve one or more rows... From the current row in the result set . You can modify the current row of the result set . Generally, cursors are not used , But when it comes to processing data item by item , Cursors are very important .

43、 What is stored procedure ? What to call ?

answer : Stored procedure is a precompiled SQL sentence , The advantage is to allow modular design , That means just To create a , Later in the program can be called many times . If an operation needs to be performed more than once SQL, Using stored procedures is better than just SQL Statement execution should be fast . You can call a stored procedure with a command object .

44、 How to understand three paradigms in a popular way ?

answer : First normal form :1NF It's an atomic constraint on properties , Properties are required to be atomic , It can't be broken down ;
Second normal form :2NF It's a constraint on the uniqueness of records , The record is required to have a unique identification , That is, the uniqueness of the entity ;
Third normal form : 3NF It's a constraint on field redundancy , That is, any field cannot be derived from other fields , It requires that the fields are not redundant ..

Advantages and disadvantages of normal design : advantage :
Data redundancy can be minimized , Make updates fast , Small volume

shortcoming : For queries, multiple tables are required to be associated , Reduce the efficiency of writing and increase the efficiency of reading , More difficult to index Optimize

Anti normalization :

advantage : Can reduce the correlation of tables , Better index optimization

shortcoming : Data redundancy and data exception , It costs more to modify the data

45、 What is a basic watch ? What is a view ?

answer : A basic table is a table that exists independently of itself , stay SQL A relationship in the corresponding table . The view is from A table exported from one or more basic tables . The view itself is not stored independently in the database , It's a virtual watch

46、 Try to explain the advantages of the view ?

answer : (1) View can simplify the operation of users
(2) Views enable users to view the same data from multiple perspectives ;
(3) Views provide a certain degree of logical independence for the database ;
(4) Views can provide access to confidential data safeguard .

47、 NULL What does that mean?

answer : NULL This value represents UNKNOWN( Unknown ): It doesn't mean “” ( An empty string ). Yes NULL this Any comparison of values produces a NULL value . You can't combine any value with a NULL Compare values a , And logically want to get an answer .

Use IS NULL To carry out NULL Judge

48、 Primary key 、 The difference between foreign key and index ?

Primary key 、 The difference between foreign key and index

Definition :

Primary key – Uniquely identify a record , There can be no repetition , Not allowed to be empty

Foreign keys – The foreign key of a table is the primary key of another table , Foreign keys can have duplicate , It can be null Indexes – There are no duplicate values for this field , But there can be a null value
effect :

Primary key – To ensure data integrity

Foreign keys – Used to make connections with other tables Indexes – It is to improve the speed of query sorting
Number :

Primary key – There can only be one primary key

Foreign keys – A table can have multiple foreign keys

Indexes – A table can have multiple unique indexes

49、 What can you do to make sure that the fields in the table only accept values in a specific range ?

answer : Check Limit , It's defined in the database table , Used to limit the input value of this column .

Triggers can also be used to limit the values that a field in a database table can accept , But this approach requires Triggers are defined in the table , This may affect performance... In some cases .

50、 Say yes SQL What are the methods of statement optimization ?( Choose a few )

1、Where clause :where Connections between tables must be written in other Where Before condition , Those can be The condition to filter out the maximum number of records must be written in Where End of clause .HAVING Last .

2、 use EXISTS replace IN、 use NOT EXISTS replace NOT IN.

3、 Avoid using calculations on index columns

4、 Avoid using... On index columns IS NULL and IS NOT NULL

5、 Yes Query optimization , Should be Try to avoid full scan , The first It should be considered at first where And order by Involve Index the columns of and .

6、 Should try to avoid in where Field in the clause null Value judgement , Otherwise, it will cause the engine to give up Full table scan using index

7、 Should try to avoid in where The clause performs an expression operation on the field , This will cause the engine to be abandoned Index and scan the whole table

 Insert picture description here

If you think it's OK , give the thumbs-up , Collection , Share , One click three times to support me ~

原网站

版权声明
本文为[Resourceful!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221334465355.html