当前位置:网站首页>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


边栏推荐
- Solution of commercial supply chain collaboration platform in household appliance industry: lean supply chain system management, boosting enterprise intelligent manufacturing upgrading
- Drive brushless DC motor based on Ti drv10970
- How can non-technical departments participate in Devops?
- webRTC SDP mslabel lable
- Isn't it right to put money into the external market? How can we ensure safety?
- GPS original coordinates to Baidu map coordinates (pure C code)
- 一键更改多个文件名字
- 我想咨询一下,mysql一个事务对于多张表的更新,怎么保证数据一致性的?
- 基于TI DRV10970驱动直流无刷电机
- Pointer operation - C language
猜你喜欢

机器学习笔记 - 灰狼优化

Loop invariant
![[detailed explanation of Huawei machine test] character statistics and rearrangement](/img/0f/972cde8c749e7b53159c9d9975c9f5.png)
[detailed explanation of Huawei machine test] character statistics and rearrangement

浅谈Dataset和Dataloader在加载数据时如何调用到__getitem__()函数

用 Go 跑的更快:使用 Golang 为机器学习服务

基于TI DRV10970驱动直流无刷电机

危机重重下的企业发展,数字化转型到底是不是企业未来救星

CyCa children's physical etiquette Ningbo training results assessment came to a successful conclusion

Countermeasures of enterprise supply chain management system in UCA Era

一键更改多个文件名字
随机推荐
Thymeleaf 常用函數
Talking about how dataset and dataloader call when loading data__ getitem__ () function
通过npm 或者 yarn安装依赖时 报错 出现乱码解决方式
Disjoint Set
微帧科技荣获全球云计算大会“云鼎奖”!
Is the securities account given by the head teacher of qiniu school safe? Can I open an account?
Machine learning notes - gray wolf optimization
729. My schedule I: "simulation" & "line segment tree (dynamic open point) &" block + bit operation (bucket Division) "
I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?
【招聘岗位】软件工程师(全栈)- 公共安全方向
How does redis implement multiple zones?
CPU design practice - Chapter 4 practical task 2 using blocking technology to solve conflicts caused by related problems
Does maxcompute have SQL that can query the current storage capacity (KB) of the table?
leetcode:881. lifeboat
[detailed explanation of Huawei machine test] character statistics and rearrangement
Online electronic component purchasing Mall: break the problem of information asymmetry in the purchasing process, and enable enterprises to effectively coordinate management
【数组和进阶指针经典笔试题12道】这些题,满足你对数组和指针的所有幻想,come on !
Niuke: intercepting missiles
How to protect user privacy without password authentication?
Explain Vue's plan to clean up keepalive cache in time