Skip to content

Conversation

vincent-pochet
Copy link
Collaborator

Context

A slow query was identified on the charge table:

SELECT count(*) FROM "charges" WHERE (plan_id = $1 AND billable_metric_id = $2) AND pay_in_advance = true AND "charges"."deleted_at" IS NULL

This query is made by the events processor to identify if an event needs to be billed in advance. The problem was identified because a big burst of event was post-processed, leading to a pike in CPU usage on the database.

Description

This PR only adds a new index to speed up the processing.

@vincent-pochet vincent-pochet merged commit d9bae67 into main Jul 8, 2025
14 checks passed
@vincent-pochet vincent-pochet deleted the misc-add-post-process-index branch July 8, 2025 10:07
diegocharles pushed a commit that referenced this pull request Jul 11, 2025
…rocessing (#3943)

## Context

A slow query was identified on the charge table:
```
SELECT count(*) FROM "charges" WHERE (plan_id = $1 AND billable_metric_id = $2) AND pay_in_advance = true AND "charges"."deleted_at" IS NULL
```

This query is made by the events processor to identify if an event needs
to be billed in advance. The problem was identified because a big burst
of event was post-processed, leading to a pike in CPU usage on the
database.

## Description

This PR only adds a new index to speed up the processing.
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