Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: improve journal deletion #169

Merged
merged 13 commits into from
Apr 24, 2024
Merged

Conversation

Roiocam
Copy link
Member

@Roiocam Roiocam commented Apr 3, 2024

Motivation

Resolve #155, improve the deletion performance.

  • Avoid updating large rows(will only mark the highest journal as delete)
  • Remove unused queries.

@Roiocam Roiocam force-pushed the remove-logic-delete branch from ea64f0d to 4fcceb1 Compare April 19, 2024 02:57
@Roiocam Roiocam changed the title feat: remove logic delete for optimization perf: improve journal deletion Apr 19, 2024
@Roiocam Roiocam marked this pull request as ready for review April 19, 2024 07:57
Copy link
Contributor

@nvollmar nvollmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@He-Pin
Copy link
Member

He-Pin commented Apr 19, 2024

I will check this after work

Copy link
Contributor

@pjfanning pjfanning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

.filter(_.sequenceNumber <= maxSequenceNr)
.take(1)
.map(_.sequenceNumber)
.max
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem like we could avoid max function here, I have compared max and top 1 execute plans, and the former seems to cost more.

TOP 1

Limit  (cost=0.29..0.35 rows=1 width=8)
  ->  Index Only Scan Backward using event_journal_pkey on event_journal  (cost=0.29..12.29 rows=200 width=8)
        Index Cond: ((persistence_id = 'my-7'::text) AND (sequence_number <= 10000))

Max

Result  (cost=0.35..0.36 rows=1 width=8)
  InitPlan 1 (returns $0)
    ->  Limit  (cost=0.29..0.35 rows=1 width=8)
          ->  Index Only Scan Backward using event_journal_pkey on event_journal  (cost=0.29..12.79 rows=200 width=8)
                Index Cond: ((persistence_id = 'my-7'::text) AND (sequence_number IS NOT NULL) AND (sequence_number <= 10000))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SQL before update.

select max(x2.x3) from (select "sequence_number" as x3 from "event_journal" where ("persistence_id" = ?) and ("sequence_number" <= ?) order by "sequence_number" desc limit 1) x2

The SQL after update.

select "sequence_number" from "event_journal" where ("persistence_id" = ?) and ("sequence_number" <= ?) order by "sequence_number" desc limit 1

@Roiocam Roiocam merged commit 8e170c2 into apache:main Apr 24, 2024
20 checks passed
@Roiocam Roiocam deleted the remove-logic-delete branch April 24, 2024 08:03
@He-Pin
Copy link
Member

He-Pin commented Apr 24, 2024

Cool~

@pjfanning pjfanning added this to the 1.1.0 milestone May 23, 2024
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.

Journal does logical and physical deletion in same transaction
4 participants