Skip to content

Conversation

@fengve
Copy link

@fengve fengve commented Jan 19, 2026

What changed?

Removing unnecessary left joins serves no purpose other than wasting MySQL's CPU.
Adding an index to a FOR GROUP statement

Why?

Solve sql

SELECT STATUS , COUNT ( * ) FROM executions_visibility ev LEFT JOIN custom_search_attributes  USING ( namespace_id, run_id ) WHERE ( namespace_id= "32049b68-7872-4094-8e63-d0dd59896a83" ) AND TemporalNamespaceDivision IS NULL GROUP BY STATUS

mysql cpu occupied 100%

Why is the left join meaningless here?

  1. COUNT(*) only counts the left table (executions_visibility).
  2. The filter condition 'TemporalNamespaceDivision IS NULL' also applies to the left table.
  3. All connection keys are PK(namespace_id, run_id), and there is no 1:N relationship.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

@fengve fengve requested review from a team as code owners January 19, 2026 14:08
@fengve fengve changed the title Optimize GROUP BY queries fix bug: MySQL CPU utilization spiked to 100% Jan 19, 2026
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants