首页 > 解决方案 > 使用存储过程从不同的临时表更新主表 - MySQL

问题描述

我有以下架构,其中有多个 python 进程将数据批量写入临时表。

为简单起见,让我们考虑有两个 python 进程(p1 和 p2),并将数据推送到 2 个临时表中,如图所示。

我需要创建一个存储过程,它将从临时表(t1、t2、t3 和 t4)中获取数据并更新主表。

在此处输入图像描述

Questions:

if i create two stored procedures, (ie. one of each process) , will there be a lock while writing to database. How do we handle that.

For example, both P1 and P2 trigger at the same time and uploads data in temp tables. Now, if we two stored procedures S1 and S2 getting triggered. S1 writes the data into main table. However, S2 will get a WRITE_LOCK (my assumption).


If we have only one stored procedure overall, still the data will be updated sequentially and the python job P2 will have to wait until P1 is getting copied. 

The data we are handling is in GBs and has millions of records. 

Can you please suggest a suitable solution for this design ?

标签: mysql

解决方案


推荐阅读