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

Feature request: Add Conditional Indexing Based on Attribute Presence #300

Closed
misterjoshua opened this issue Sep 22, 2023 · 2 comments · Fixed by #333
Closed

Feature request: Add Conditional Indexing Based on Attribute Presence #300

misterjoshua opened this issue Sep 22, 2023 · 2 comments · Fixed by #333

Comments

@misterjoshua
Copy link

misterjoshua commented Sep 22, 2023

Description
I'd like ElectroDB to have a conditional indexing feature to prevent unnecessary GSI writes & hot partitions for certain data models.

Use Case
I have a data model that supports up to five levels of hierarchical depth (lv1 through lv5). However, not all entities utilize all five levels. This leads to wasted GSI write capacity and creates hot partitions for GSIs.

Playground Link

Possible Solution
I envisioned extending the index definition to accept a condition field with a function that can evaluate whether or not to populate the index fields. The idea is that if the condition function is present and it returns false, the pk & sk for that GSI are not written.

In the following example, for instance, lv5pk and lv5sk would be left unset and the byLv5 index would not be populated unless the lv5 attribute is set:

byLv5: {
  index: 'byLv5',
  // This is the new function
  condition: (attrs) => attrs.lv5 !== '',
  pk: {
    field: 'lv5pk',
    composite: ['lv5'],
  },
  sk: {
    field: 'lv5sk',
    composite: ['lv1', 'lv2', 'lv3', 'lv4'],
  }
},
@tywalch
Copy link
Owner

tywalch commented Oct 2, 2023

This is a reasonable request, let me look into the work necessary to get something to solve for this case

This was linked to pull requests Nov 24, 2023
@misterjoshua
Copy link
Author

Thanks dude!!!

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 a pull request may close this issue.

2 participants