MySQL 长字符串字段的查询优化

比如有一张表 osx_yue_order,包含字段 yo_order_id、yo_pay_status,值形如 tywx2021073015544530593

原本的查询语句为 select yo_pay_status  from osx_yue_order oyo where yo_order_id ='tywx2021081209433714083';

优化的方法是:

1、新建字段 yo_order_id_crc32,int (10) unsigned NOT NULL DEFAULT '0' COMMENT 'yo_order_id 的 crc32 值 ',

2、对此字段建立索引  KEY `osx_yue_order_yo_order_id_crc32_IDX` (`yo_order_id_crc32`) USING BTREE

3、修改查询语句 select yo_pay_status  from osx_yue_order oyo where  yo_order_id_crc32=crc32 ('tywx2021081209433714083')  and yo_order_id ='tywx2021081209433714083';

使用如下命令压测:

mysqlslap -h127.0.0.1 -uroot --concurrency=8 --iterations=10 --create-schema=osx1 --query=d:\bench.sql --engine=innodb --number-of-queries=100000 --debug-info

优化前的压测结果:

Benchmark
        Running for engine innodb
        Average number of seconds to run all queries: 9.735 seconds
        Minimum number of seconds to run all queries: 8.906 seconds
        Maximum number of seconds to run all queries: 10.172 seconds
        Number of clients running queries: 8
        Average number of queries per client: 12500

优化后的压测结果:

Benchmark
        Running for engine innodb
        Average number of seconds to run all queries: 7.026 seconds
        Minimum number of seconds to run all queries: 6.219 seconds
        Maximum number of seconds to run all queries: 7.875 seconds
        Number of clients running queries: 8
        Average number of queries per client: 12500

因为本机表的数据量少,所以性能的提升还不算大。如果数据量大的话,性能的提升会更大。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值