-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Denormalize buffer operations (#9026)
This should significantly reduce database load on redeploy. Co-Authored-By: Max <max@zed.dev> Co-Authored-By: Nathan <nathan@zed.dev> Release Notes: - Reduced likelihood of being disconnected during deploys Co-authored-by: Max <max@zed.dev> Co-authored-by: Nathan <nathan@zed.dev>
- Loading branch information
1 parent
b5370cd
commit 86748a0
Showing
6 changed files
with
62 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
crates/collab/migrations/20240307163119_denormalize_buffer_ops.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- Add migration script here | ||
|
||
ALTER TABLE buffers ADD COLUMN latest_operation_epoch INTEGER; | ||
ALTER TABLE buffers ADD COLUMN latest_operation_lamport_timestamp INTEGER; | ||
ALTER TABLE buffers ADD COLUMN latest_operation_replica_id INTEGER; | ||
|
||
WITH ops AS ( | ||
SELECT DISTINCT ON (buffer_id) buffer_id, epoch, lamport_timestamp, replica_id | ||
FROM buffer_operations | ||
ORDER BY buffer_id, epoch DESC, lamport_timestamp DESC, replica_id DESC | ||
) | ||
UPDATE buffers | ||
SET latest_operation_epoch = ops.epoch, | ||
latest_operation_lamport_timestamp = ops.lamport_timestamp, | ||
latest_operation_replica_id = ops.replica_id | ||
FROM ops | ||
WHERE buffers.id = ops.buffer_id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters