mysql 条件输出_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、将原始数据导出

ec6d16fbefa1ccbe1947b44d7564fb44.png

2、去除索引,然后在测试库中将.sql 文件执行

3ae0921a7e1f3fc5e7b1b97494601fb8.png

3、按所需过滤条件创建对应索引(索引方法选 BTREE。亲测 HASH (耗时 700+ s)比 BTREE(耗时 13+ s) 慢,原因参见: https://blog.csdn.net/u011305680/article/details/55520853)

d6503c42ee1faa356480196a1c50f9ec.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值