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

feat: Add composite indexes #2226

Merged
merged 31 commits into from
Jan 22, 2024
Merged

feat: Add composite indexes #2226

merged 31 commits into from
Jan 22, 2024

Conversation

islamaliev
Copy link
Contributor

@islamaliev islamaliev commented Jan 17, 2024

Relevant issue(s)

Resolves #299

Description

This change introduces composite secondary indexes as well as unique-composite secondary indexes.
Note: different order direction for composite fields is not included in this change.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

Unit and integration tests.

Specify the platform(s) on which this was tested:

  • MacOS

@islamaliev islamaliev added feature New feature or request area/query Related to the query component perf Performance issue or suggestion labels Jan 17, 2024
@islamaliev islamaliev self-assigned this Jan 17, 2024
Copy link

codecov bot commented Jan 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (798a6f4) 74.08% compared to head (02bf8c8) 0.00%.
Report is 1 commits behind head on develop.

❗ Current head 02bf8c8 differs from pull request most recent head fbb69d2. Consider uploading reports for the commit fbb69d2 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #2226       +/-   ##
===========================================
- Coverage    74.08%       0   -74.08%     
===========================================
  Files          256       0      -256     
  Lines        25627       0    -25627     
===========================================
- Hits         18985       0    -18985     
+ Misses        5333       0     -5333     
+ Partials      1309       0     -1309     
Flag Coverage Δ
all-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

see 256 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4554bcc...fbb69d2. Read the comment docs.

Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

Part way through my review, submitting comments so far :)

client/index.go Outdated Show resolved Hide resolved
db/errors.go Outdated Show resolved Hide resolved
db/fetcher/indexer.go Show resolved Hide resolved
db/fetcher/indexer_iterators.go Outdated Show resolved Hide resolved
db/fetcher/indexer_iterators.go Show resolved Hide resolved
db/fetcher/indexer_iterators.go Show resolved Hide resolved
db/fetcher/indexer_iterators.go Show resolved Hide resolved
db/fetcher/indexer_iterators.go Outdated Show resolved Hide resolved
db/fetcher/indexer_iterators.go Outdated Show resolved Hide resolved
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

Nearly through it, submitting a few more comments.

db/index.go Outdated Show resolved Hide resolved
db/indexed_docs_test.go Outdated Show resolved Hide resolved
@@ -185,7 +185,12 @@ func normalizeProperties(parentKey connor.FilterKey, conditions []any) []any {
// if canMergeAnd is true, all _and groups will be merged
props := make(map[int][]any)
for _, c := range conditions {
for key, val := range c.(map[connor.FilterKey]any) {
cMap, ok := c.(map[connor.FilterKey]any)
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Why has this changed? What else could it be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

normalizeProperty method that calls this normalizeProperties checks is given condition is map[connor.FilterKey]any or an array of conditions which has a type of []any. But as it recursively checks all nested conditions and values one of the values (not conditions) can match []any (for example "_in" op). That's why we need to check if it's really a conditions or just value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah okay - this was a bug fix? Did you add an integration test that covers this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

an integration test found this bug :)

planner/select.go Outdated Show resolved Hide resolved
planner/select.go Outdated Show resolved Hide resolved
planner/select.go Outdated Show resolved Hide resolved
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks Islam :)

I'm approving now, as all but one of my remaining comments are very optional within this PR. I do think we need the following though before merge please:

Can you please make sure that there are integration tests that make sure that if there are multiple overlapping indexes (e.g. two composites, a simple and a composite) that queries still work (no need for explain test documenting this issue, but that would be nice if you can do it reliably without much effort too).

And preferably at least one for what looks like a bug fix in filter/normailze.go (if it is a bug fix :))

@islamaliev islamaliev force-pushed the feat/composite-indexes branch from 02bf8c8 to fbb69d2 Compare January 22, 2024 11:15
@islamaliev islamaliev merged commit 86caacc into develop Jan 22, 2024
27 of 28 checks passed
@islamaliev islamaliev deleted the feat/composite-indexes branch January 22, 2024 11:32
shahzadlone pushed a commit that referenced this pull request Jan 23, 2024
## Relevant issue(s)

Resolves #299 

## Description

This change introduces composite secondary indexes as well as
unique-composite secondary indexes.
Note: different order direction for composite fields is not included in
this change.
nasdf pushed a commit to nasdf/defradb that referenced this pull request Jan 23, 2024
## Relevant issue(s)

Resolves sourcenetwork#299 

## Description

This change introduces composite secondary indexes as well as
unique-composite secondary indexes.
Note: different order direction for composite fields is not included in
this change.
nasdf pushed a commit to nasdf/defradb that referenced this pull request Jan 23, 2024
## Relevant issue(s)

Resolves sourcenetwork#299 

## Description

This change introduces composite secondary indexes as well as
unique-composite secondary indexes.
Note: different order direction for composite fields is not included in
this change.
@fredcarle fredcarle added this to the DefraDB v0.10 milestone Feb 20, 2024
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
## Relevant issue(s)

Resolves sourcenetwork#299 

## Description

This change introduces composite secondary indexes as well as
unique-composite secondary indexes.
Note: different order direction for composite fields is not included in
this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/query Related to the query component feature New feature or request perf Performance issue or suggestion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sec. Indexes: Implement composite indexes
3 participants