mysql 8优化实战例子
Posted 大树叶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 8优化实战例子相关的知识,希望对你有一定的参考价值。
表:tax_salary_person, 目前为 6,577,256记录
慢SQL:我在mysql执行为 10.16s, 执行多次,平均在10s,扫描 4.38M, 返回1300
SELECT id, natural_person_id, company_id, net_amount_total, payer_id
, agency_id, tax_assessment_section_type, tax_period, create_time, update_time
, is_delete, pay_amount_total, taxable_amount
FROM tax_x
WHERE 1 = 1
AND company_id IN (2057249)
AND payer_id = 2
AND tax_assessment_section_type = 1
AND tax_period = '2021-04'
AND is_delete = 0
LIMIT 410800, 1300
优化方案一,采用索引。 测试 效果明显,执行一次,费时 1.32s
ALTER TABLE `shebao_tax`.`tax_x` ADD INDEX `idx_comtaxtypepayer83` (`company_id`, `tax_period`, `tax_assessment_section_type`, `payer_id`, `is_delete`),ALGORITHM=INPLACE, LOCK=NONE;
优化方案一,采用:延迟关联技术。但是效果不大:,费时9.13s。
SELECT a.id, a.natural_person_id, a.company_id, a.net_amount_total,a.payer_id,a.agency_id,a.tax_assessment_section_type,a.tax_period, a.create_time, a.update_time,a.is_delete,a.pay_amount_total,a.taxable_amount FROM tax_x a,( select id from tax_x WHERE company_id IN (2057249) AND payer_id = 2 AND tax_assessment_section_type = 1 AND tax_period = '2021-04' AND is_delete = 0 LIMIT 410800, 1300 ) b where a.id=b.id;
以上是关于mysql 8优化实战例子的主要内容,如果未能解决你的问题,请参考以下文章