-
Notifications
You must be signed in to change notification settings - Fork 547
feat(mongodb): Create unique indexes for PKs #9851
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
feat(mongodb): Create unique indexes for PKs #9851
Conversation
| if c.spec.WriteMode == specs.WriteModeOverwriteDeleteStale { | ||
| delIndexName := "cq_del" | ||
| indexes = append(indexes, mongo.IndexModel{ | ||
| Keys: bson.D{{Key: schema.CqSourceNameColumn.Name, Value: 1}, {Key: schema.CqSyncTimeColumn.Name, Value: 1}}, |
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.
Not sure about the values here.
| func (c *Client) migrateTable(ctx context.Context, table *schema.Table) error { | ||
| indexModels := c.getIndexTemplates(table) | ||
| for _, mdl := range indexModels { | ||
| res, err := c.client.Database(c.pluginSpec.Database).Collection(table.Name).Indexes().CreateOne(ctx, mdl) |
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.
There's CreateMany as well but it would get complicated to do the error handling afterwards. It fails on the first error and you'd have to do re-runs to check/handle all.
| return false | ||
| } | ||
|
|
||
| // This is either "Index already exists with a different name: %s" error or due to uniqueness change |
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.
If they want non-unique indexes in cq_pk, they can have it?
🤖 I have created a release *beep* *boop* --- ## [2.0.0](plugins-destination-mongodb-v1.1.5...plugins-destination-mongodb-v2.0.0) (2023-04-25) ### ⚠ BREAKING CHANGES * This release introduces an internal change to our type system to use [Apache Arrow](https://arrow.apache.org/). This should not have any visible breaking changes, however due to the size of the change we are introducing it under a major version bump to communicate that it might have some bugs that we weren't able to catch during our internal tests. If you encounter an issue during the upgrade, please submit a [bug report](https://github.com/cloudquery/cloudquery/issues/new/choose). ### Features * **mongodb:** Create unique indexes for PKs ([#9851](#9851)) ([9e20642](9e20642)) * Update to use [Apache Arrow](https://arrow.apache.org/) type system ([9e74b76](9e74b76)) ### Bug Fixes * **deps:** Update module github.com/cloudquery/plugin-sdk to v1.45.0 ([#9863](#9863)) ([2799d62](2799d62)) * **deps:** Update module github.com/cloudquery/plugin-sdk/v2 to v2.4.0 ([#10278](#10278)) ([a0a713e](a0a713e)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Fixes #9614
Checking with
db.system.profile.find().limit(5).pretty()afterdb.setProfilingLevel(2)I don't see anyCOLLSCANs.We're not adding indexes for_cq_source_name,_cq_sync_timesoDeleteStaleis probably still slow.Verified with
db.system.profile.find({ "planSummary": "COLLSCAN", "ns": { "$ne": "mdb.system.profile" } })as well.