当前位置:网站首页>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
边栏推荐
- Postgresql 13 安装
- Photoshop插件-动作相关概念-非加载执行动作文件中动作-PS插件开发
- 超级哇塞的快排,你值得学会!
- 【NVMe2.0b 14-9】NVMe SR-IOV
- Interpretation of Apache linkage parameters in computing middleware
- Fr exercise topic --- comprehensive question
- Using tensorboard to visualize the training process in pytoch
- 申请代码签名证书时如何选择合适的证书品牌?
- Matrix chain multiplication dynamic programming example
- 美国费城发生“安全事故” 2名警察遭枪杀
猜你喜欢
freesurfer运行完recon-all怎么快速查看有没有报错?——核心命令tail重定向
leetcode:881. 救生艇
超级哇塞的快排,你值得学会!
危机重重下的企业发展,数字化转型到底是不是企业未来救星
leetcode:881. lifeboat
CyCa children's physical etiquette Ningbo training results assessment came to a successful conclusion
Differences between IPv6 and IPv4 three departments including the office of network information technology promote IPv6 scale deployment
Pointer operation - C language
Section - left closed right open
[12 classic written questions of array and advanced pointer] these questions meet all your illusions about array and pointer, come on!
随机推荐
Photoshop插件-动作相关概念-ActionList-ActionDescriptor-ActionList-动作执行加载调用删除-PS插件开发
Solution of commercial supply chain collaboration platform in household appliance industry: lean supply chain system management, boosting enterprise intelligent manufacturing upgrading
Thymeleaf 使用后台自定义工具类处理文本
超级哇塞的快排,你值得学会!
Talking about how dataset and dataloader call when loading data__ getitem__ () function
[detailed explanation of Huawei machine test] character statistics and rearrangement
Two policemen were shot dead in a "safety accident" in Philadelphia, USA
一键更改多个文件名字
mysql8.0JSON_ Instructions for using contains
Principle and performance analysis of lepton lossless compression
webRTC SDP mslabel lable
729. My schedule I: "simulation" & "line segment tree (dynamic open point) &" block + bit operation (bucket Division) "
Is the securities account given by the head teacher of qiniu school safe? Can I open an account?
CPU design practice - Chapter 4 practice task 3 use pre delivery technology to solve conflicts caused by related issues
Explain Vue's plan to clean up keepalive cache in time
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
手写promise与async await
通过npm 或者 yarn安装依赖时 报错 出现乱码解决方式
Pointer operation - C language
安装配置Jenkins