【MYSQL】Mysql长时间SQL优化一例(force index)

SELECT SUBSTR(eff_time,1,10),ns_name,COUNT(*) FROM HEHEDA WHERE isActive = 1 AND stype <> 'report' AND usefull = 1 
AND eff_time > '2014-01-01' AND itype =1 
AND ns_name IN ('凤凰网', '新浪财经', '和讯网', '金融界', '腾讯网', '中国经济网', '财经网', '中证网', '中国证券网', '中金在线', '经济观察网') 
GROUP BY SUBSTR(eff_time,1,10),ns_name ORDER BY ns_name,SUBSTR(eff_time,1,10) DESC;


show index from HEHEDA;
Seq_in_index    Column_name Collation   Cardinality Sub_part    Packed  Null    Index_type  Comment Index_comment
1   ID  A   31246724    BTREE   
1   news_url    A   31246724    150 YES BTREE   
2   stype   A   31246724    YES BTREE   
1   group_id    A   31246724    BTREE   
1   news_id A   31246724    BTREE   
2   has_summary A   31246724    YES BTREE   
3   stype   A   31246724    YES BTREE   
1   insert_time A   31246724    YES BTREE   
1   news_fetch_time A   31246724    YES BTREE   
1   update_time A   31246724    YES BTREE   
1   news_publish_time   A   31246724    YES BTREE   
2   news_id A   31246724    BTREE   
1   ns_name A   54247   YES BTREE   
2   insert_time A   31246724    YES BTREE   
1   ns_name A   78707   YES BTREE   
2   news_title  A   31246724    255 YES BTREE   
3   news_publish_time   A   31246724    YES BTREE   
1   itype   A   3188    YES BTREE   
1   eff_time    A   15623362    YES BTREE   
1   ns_name A   86079   YES BTREE   
2   itype   A   72666   YES BTREE   
1   itype   A   1200    YES BTREE   
2   stype   A   2402    YES BTREE   
3   ns_name A   164456  YES BTREE


--修改SQL
SELECT
    SUBSTR(eff_time, 1, 10),
    ns_name,
    COUNT(*)
FROM
    HEHEDA FORCE INDEX (HEHEDA_ix_10)
WHERE itype = 1
AND stype <> 'report'
AND ns_name IN (
    '凤凰网',
    '新浪财经',
    '和讯网',
    '金融界',
    '腾讯网',
    '中国经济网',
    '财经网',
    '中证网',
    '中国证券网',
    '中金在线',
    '经济观察网'
)
AND isActive = 1
AND usefull = 1
AND eff_time > '2014-01-01'
GROUP BY
    SUBSTR(eff_time, 1, 10),
    ns_name
ORDER BY
    ns_name,
    SUBSTR(eff_time, 1, 10) DESC;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SQL中,"UPDATE"语句用于更新表中的数据,而"SUBSTR"函数则用于截取字符串的一部分。根据提供的引用和引用,你可以使用"UPDATE"语句结合"SUBSTR"函数来更新某个字段的字符串子串。 具体的方法取决于你想要实现的功能。如果你要从字符串的头部截取到某个位置,可以使用"SUBSTR"函数指定截取的起始位置和度来实现。例如,以下是一个示例代码: UPDATE your_table SET your_column = SUBSTR(your_column, 1, desired_length) WHERE your_condition; 如果你要截取字符串的中间片段,可以使用"SUBSTR"函数结合字符串连接操作符"||"来实现。你可以使用多个"SUBSTR"函数来指定不同的起始位置和度,然后使用字符串连接操作符将它们拼接在一起。例如,以下是一个示例代码: UPDATE your_table SET your_column = SUBSTR(your_column, start1, length1) || SUBSTR(your_column, start2, length2) || ... WHERE your_condition; 如果你想要从字符串的中间截取到末尾,可以使用"SUBSTR"函数指定起始位置,并不指定度,这样就会截取从指定位置到字符串末尾的部分。例如,以下是一个示例代码: UPDATE your_table SET your_column = SUBSTR(your_column, start) WHERE your_condition; 如果你想要删除字符串的前面部分,可以使用"SUBSTR"函数指定起始位置,并不指定度,这样就会从指定位置开始截取到字符串末尾的部分。例如,以下是一个示例代码: UPDATE your_table SET your_column = SUBSTR(your_column, start) WHERE your_condition; 请根据具体的需求选择适合的方法,并替换示例中的"your_table"、"your_column"、"desired_length"、"start"、"length"和"your_condition"为实际的表名、列名、度、起始位置和条件。记得在执行"UPDATE"语句时要谨慎选择条件,以免错误地更新了不需要的数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值