当前位置:网站首页>12 MySQL interview questions that you must chew through to enter Alibaba
12 MySQL interview questions that you must chew through to enter Alibaba
2022-07-05 14:49:00 【InfoQ】
1. Can you say myisam and innodb The difference between ?
2. Under the said mysql What's the index of , What are clustered and nonclustered indexes ?
create table user(
id int(11) not null,
age int(11) not null,
primary key(id),
key(age)
);



3. Do you know what is overlay index and return table ?
explain select * from user where age=1; // Of the query name Cannot get from index data
explain select id,age from user where age=1; // You can get it directly from the index
4. What are the types of locks
5. Can you talk about the basic characteristics and isolation level of transactions ?


6. So what do you mean by phantom reading , What is? MVCC?

select * from user where id<=3;
update user set name=' Zhang Sansan ' where id=1;


select * from user where id<=3 and create_version<=3 and (delete_version>3 or delete_version is null);
- Xiao Ming opens up business current_version=6 The query name is ' Wang Wu ' The record of , Discover that there is no .
- Xiaohong opens the business current_version=7 Insert a piece of data , So it turns out :

- Xiao Ming executes insert name ' Wang Wu ' The record of , Unique index conflict found , Can't insert , This is unreal reading .
7. that ACID By what guarantee ?
8. Do you know what a clearance lock is ?

begin;
select * from user where age=20 for update;
begin;
insert into user(age) values(10); # success
insert into user(age) values(11); # Failure
insert into user(age) values(20); # Failure
insert into user(age) values(21); # Failure
insert into user(age) values(30); # Failure
(negative infinity,10],(10,20],(20,30],(30,positive infinity)
9. After the sub table ID How to guarantee uniqueness ?
- Set the step size , such as 1-1024 Let's set up a table 1024 The basic step size of , In this way, the primary keys will not conflict when they fall into different tables .
- Distributed ID, Realize a set of distributed ID Generate algorithms or use open source ones like snowflake
- After table splitting, the primary key is not used as the query basis , Instead, a field is added to each form as a unique primary key , For example, the order number is unique , No matter which table it ends up in, it is based on the order number , It's the same with updates .
10. What's the magnitude of your data ? How to do sub database and sub table ?


11. After the table is divided, it is not sharding_key How to handle the query of ?
- You can make one mapping surface , For example, what should businesses do when they want to query the order list ? No user_id You can't scan the whole table if you want to inquire ? So we can make a mapping table , Keep the relationship between the merchant and the user , When querying, first query the user list through the merchant , Re pass user_id Go to query .
- Wide watch , generally speaking , The real-time data requirement of the merchant is not very high , For example, to query the order list , You can synchronize the order table to offline ( real time ) Several positions , Then make a wide table based on the data warehouse , Based on other things like es Provide inquiry service .
- If the amount of data is not large , For example, some queries in the background , You can also scan the table through multithreading , And then aggregate the results to do . Or asynchronous form is OK .
List<Callable<List<User>>> taskList = Lists.newArrayList();
for (int shardingIndex = 0; shardingIndex < 1024; shardingIndex++) {
taskList.add(() -> (userMapper.getProcessingAccountList(shardingIndex)));
}
List<ThirdAccountInfo> list = null;
try {
list = taskExecutor.executeTask(taskList);
} catch (Exception e) {
//do something
}
public class TaskExecutor {
public <T> List<T> executeTask(Collection<? extends Callable<T>> tasks) throws Exception {
List<T> result = Lists.newArrayList();
List<Future<T>> futures = ExecutorUtil.invokeAll(tasks);
for (Future<T> future : futures) {
result.add(future.get());
}
return result;
}
}
12. say something mysql Master slave synchronization how to do it ?
- master After committing the transaction , write in binlog
- slave Connect to master, obtain binlog
- master establish dump Threads , push binglog To slave
- slave Start a IO Thread reads synchronized master Of binlog, It was recorded that relay log In the relay log
- slave Open one more sql Thread reads relay log Events and slave perform , Complete synchronization
- slave Record your own binglog

13. How to solve the delay of master-slave ?
- For specific business scenarios , Read and write requests are forced to go to the main library
- Read request from library , If there is no data , Go to the main database for secondary query


边栏推荐
- 【leetcode周赛总结】LeetCode第 81 场双周赛(6.25)
- Principle and performance analysis of lepton lossless compression
- Niuke: intercepting missiles
- Stm32+bh1750 photosensitive sensor obtains light intensity
- Reconnaissance des caractères easycr
- 【招聘岗位】基础设施软件开发人员
- Jmeter性能测试:ServerAgent资源监控
- Is the securities account given by the head teacher of qiniu school safe? Can I open an account?
- CyCa children's physical etiquette Ningbo training results assessment came to a successful conclusion
- I collect multiple Oracle tables at the same time. After collecting for a while, I will report that Oracle's OGA memory is exceeded. Have you encountered it?
猜你喜欢
Talking about how dataset and dataloader call when loading data__ getitem__ () function
超级哇塞的快排,你值得学会!
leetcode:881. 救生艇
【leetcode周赛总结】LeetCode第 81 场双周赛(6.25)
FR练习题目---简单题
Interview shock 62: what are the precautions for group by?
Thymeleaf th:with局部变量的使用
How to protect user privacy without password authentication?
Interpretation of Apache linkage parameters in computing middleware
Section - left closed right open
随机推荐
安装配置Jenkins
Intelligent supply chain collaboration system solution for daily chemical products industry: digital intelligent SCM supply chain, which is the "acceleration" of enterprise transformation
Photoshop plug-in action related concepts actionlist actiondescriptor actionlist action execution load call delete PS plug-in development
easyOCR 字符識別
CPU设计实战-第四章实践任务三用前递技术解决相关引发的冲突
[summary of leetcode weekly competition] the 81st fortnight competition of leetcode (6.25)
I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?
How to solve the problem of garbled code when installing dependency through NPM or yarn
Thymeleaf 模板的创建与使用
Thymeleaf common functions
启牛学堂班主任给的证券账户安全吗?能开户吗?
漫画:优秀的程序员具备哪些属性?
美国费城发生“安全事故” 2名警察遭枪杀
Section - left closed right open
leetcode:881. lifeboat
Online electronic component purchasing Mall: break the problem of information asymmetry in the purchasing process, and enable enterprises to effectively coordinate management
Differences between IPv6 and IPv4 three departments including the office of network information technology promote IPv6 scale deployment
FR练习题目---综合题
长列表优化虚拟滚动
在Pytorch中使用Tensorboard可视化训练过程