簡體   English   中英

如何最小化將數據從(大)分區表復制到另一個分區表的 RAM 要求?

[英]How to minimize the RAM requirements for copying data from (large) partitioned table to another partitioned table?

對於 table1 和 table2 這兩個大表,table1 中有數千個分區和 1.5 億行,mysql/mariadb 執行此查詢效率低下。

insert into table2 select * from table1

事實上,在兩個表上都使用了 8192 個分區,在查詢結束之前 RAM 已經耗盡。 當它分配了 6.1 GB 的 RAM 時,我不得不終止它,因為這個特定的盒子只有 8 GB 的 RAM。 如何以較低的 RAM 占用空間執行此任務?

通過強制 mysql/mariadb 一次處理來自一個分區的數據,可以在任何時候使用少於 500 MB 的 RAM 完成任務。

解決方案的結構是這樣的:

insert into table2 select * from table1 partition (p<X>)

其中 X 應該是與分區相對應的完整整數集,在我的例子中是從 0 到 8191。這可以通過存儲過程來實現,如下所示:

drop procedure if exists my_partitioning_data_copy_procedure;

delimiter #
create procedure my_partitioning_data_copy_procedure()
begin

declare v_max int unsigned default 8191;
declare v_counter int unsigned default 0;

  start transaction;
  while v_counter < v_max do
    SET @expression = concat("insert into table2 select * from table1 partition (p", v_counter, ");");
    prepare myquery from @expression;
    execute myquery;
    set v_counter=v_counter+1;
  end while;
  commit;
end #

delimiter ;

call my_partitioning_data_copy_procedure();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM