Skip to content

Fix deleteMany for bucket_parameters to use an index #244

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

Merged
merged 2 commits into from
Apr 19, 2025

Conversation

rkistner
Copy link
Contributor

@rkistner rkistner commented Apr 19, 2025

The deleteMany for clearning bucket_parameters data used a filter like this:

     "key": {
        "$gte": {
          "g": 3,
          "t": MinKey(),
          "k": MinKey()
        },
        "$lt": {
          "g": 3,
          "t": MaxKey(),
          "k": MaxKey()
        }
      }

This followed the same pattern as the _id filters on other collections. However, there is no direct index on key, only this index:

await database.bucket_parameters.createIndex(
      {
        'key.g': 1,
        lookup: 1,
        _id: 1
      },
      { name: 'lookup1' }
    );

So in this case we can just use a simpler filter on key.g, to achieve the same thing but using an index.

Copy link

changeset-bot bot commented Apr 19, 2025

🦋 Changeset detected

Latest commit: 08e6e92

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@powersync/service-module-mongodb-storage Patch
@powersync/service-core Patch
@powersync/service-image Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres Patch
@powersync/service-core-tests Patch
@powersync/service-module-postgres-storage Patch
test-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rkistner rkistner marked this pull request as ready for review April 19, 2025 14:42
@rkistner rkistner merged commit 4f7bd0f into hotfix/1.10 Apr 19, 2025
21 checks passed
@rkistner rkistner deleted the fix/clearing-bucket-parameters branch April 19, 2025 14:52
@rkistner rkistner restored the fix/clearing-bucket-parameters branch April 19, 2025 15:05
@@ -571,7 +571,7 @@ export class MongoSyncBucketStorage
);
await this.db.bucket_parameters.deleteMany(
{
key: idPrefixFilter<SourceKey>({ g: this.group_id }, ['t', 'k'])
'key.g': this.group_id
Copy link
Contributor

@Rentacookie Rentacookie Apr 22, 2025

Choose a reason for hiding this comment

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

Would a simpler filter + index like this not perhaps help with the clearing of the bucket_data collection?
I had a look and even though the index there is being used it still looked to be rather slow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding another index on bucket_data can significantly affect the performance for all writes there, and even make deletes slower because of that. The current filter is slightly complex, but it does efficiently use the _id index. I suspect the performance bottleneck is to a large extend just an overall write throughput bottleneck (although I haven't tested that properly).

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.

3 participants