-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
ea64f0d
to
4fcceb1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
core/src/main/scala/org/apache/pekko/persistence/jdbc/journal/dao/JournalQueries.scala
Outdated
Show resolved
Hide resolved
I will check this after work |
core/src/main/scala/org/apache/pekko/persistence/jdbc/journal/dao/JournalQueries.scala
Show resolved
Hide resolved
core/src/main/scala/org/apache/pekko/persistence/jdbc/journal/dao/JournalQueries.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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
Cool~ |
Motivation
Resolve #155, improve the deletion performance.