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

 

posted @ 2019-01-23 11:17  那一剑的風情  阅读(1560)  评论(0)    收藏  举报