mysql 按所需條件過濾導出數據(線上環境表中數據總量較大)


場景:線上庫中 表: quant_stk_calc_d_wxcp 的數據總量為 660W+,已有索引為 gscode_ymd_gpcode,現需按條件 f1 = 1 or f2 = 1 導出數據集。

CREATE TABLE `quant_stk_calc_d_wxcp` (
  `id` bigint(15) unsigned NOT NULL AUTO_INCREMENT,
  `gsset` int(11) DEFAULT NULL,
  `gscode` varchar(128) DEFAULT NULL,
  `gpcode` varchar(20) DEFAULT NULL,
  `ymd` int(11) DEFAULT NULL,
  `hms` int(11) DEFAULT NULL,
  `f1` decimal(18,4) DEFAULT NULL,
  `f2` decimal(18,4) DEFAULT NULL,
  `f3` decimal(18,4) DEFAULT NULL,
  `f4` decimal(18,4) DEFAULT NULL,
  `f5` decimal(18,4) DEFAULT NULL,
  `f6` decimal(18,4) DEFAULT NULL,
  `f7` decimal(18,4) DEFAULT NULL,
  `f8` decimal(18,4) DEFAULT NULL,
  `f9` decimal(18,4) DEFAULT NULL,
  `f10` decimal(18,4) DEFAULT NULL,
  `f11` decimal(18,4) DEFAULT NULL,
  `f12` decimal(18,4) DEFAULT NULL,
  `f13` decimal(18,4) DEFAULT NULL,
  `f14` decimal(18,4) DEFAULT NULL,
  `f15` decimal(18,4) DEFAULT NULL,
  `f16` decimal(18,4) DEFAULT NULL,
  `rise_max` decimal(18,4) DEFAULT NULL,
  `rise_signalDay` decimal(18,4) DEFAULT NULL,
  `high_max` decimal(18,4) DEFAULT NULL,
  `Low_signalDay` decimal(18,4) DEFAULT NULL,
  `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `gscode` (`gscode`,`gpcode`,`ymd`) USING BTREE,
  KEY `index_gscode_ymd` (`gscode`,`ymd`) USING BTREE,
  KEY `index_ymd` (`ymd`) USING BTREE,
  KEY `index_updatetime` (`update_time`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=36674898 DEFAULT CHARSET=utf8;

解決方法:為了不直接操作線上庫表,把數據導出至測試環境操作,步驟如下:

  1、將原始數據導出

  2、去除索引,然后在測試庫中將.sql 文件執行

  

  3、按所需過濾條件創建對應索引(索引方法選 BTREE。親測 HASH (耗時 700+ s)比 BTREE(耗時 13+ s) 慢,原因參見: https://blog.csdn.net/u011305680/article/details/55520853

  

  4、按過濾條件將數據導出(方法參見:https://www.cnblogs.com/SZxiaochun/p/6027450.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM