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: Non-unique secondary index #1450

Merged
merged 120 commits into from
Jun 19, 2023

Conversation

islamaliev
Copy link
Contributor

@islamaliev islamaliev commented May 4, 2023

Relevant issue(s)

Resolves #297

Description

This PR introduces first functionality for secondary indexes which includes:

  • specifying index for a collection as part of the collection schema and parsing it
  • mocks for interfaces the index functionality depends on
  • db methods to create, delete and retrieve indexes
  • storing index data in the system storage
  • storing indexed fields' values to data storage
  • change to the testing framework to allow testing of indexes

This PR doesn't include using indexes for fetching data for queries to keep the PR smaller.

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 tests

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

  • MacOS

@codecov
Copy link

codecov bot commented May 4, 2023

Codecov Report

Patch coverage: 97.23% and project coverage change: +1.16 🎉

Comparison is base (da7b3f9) 72.26% compared to head (3919472) 73.42%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1450      +/-   ##
===========================================
+ Coverage    72.26%   73.42%   +1.16%     
===========================================
  Files          185      187       +2     
  Lines        18478    19291     +813     
===========================================
+ Hits         13353    14164     +811     
+ Misses        4076     4075       -1     
- Partials      1049     1052       +3     
Flag Coverage Δ
all-tests 73.42% <97.23%> (+1.16%) ⬆️

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

Impacted Files Coverage Δ
request/graphql/schema/types/types.go 100.00% <ø> (ø)
db/collection.go 70.99% <89.47%> (+2.20%) ⬆️
request/graphql/schema/collection.go 91.80% <96.36%> (+4.86%) ⬆️
db/errors.go 87.58% <96.55%> (+9.69%) ⬆️
db/index.go 97.60% <97.60%> (ø)
db/collection_index.go 98.31% <98.31%> (ø)
client/descriptions.go 95.24% <100.00%> (+2.38%) ⬆️
core/key.go 89.67% <100.00%> (+3.59%) ⬆️
db/collection_get.go 81.25% <100.00%> (+31.25%) ⬆️
db/fetcher/encoded_doc.go 62.41% <100.00%> (+0.54%) ⬆️
... and 5 more

... and 8 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 ff81968...3919472. Read the comment docs.

@islamaliev islamaliev self-assigned this May 4, 2023
@islamaliev islamaliev added feature New feature or request area/api Related to the external API component labels May 4, 2023
@islamaliev islamaliev added this to the DefraDB v0.6 milestone May 4, 2023
db/errors.go Outdated Show resolved Hide resolved
db/errors.go Outdated Show resolved Hide resolved
db/index.go Show resolved Hide resolved
db/index.go Show resolved Hide resolved
client/index.go Outdated Show resolved Hide resolved
core/key.go Outdated Show resolved Hide resolved
core/key.go Show resolved Hide resolved
core/key.go Outdated Show resolved Hide resolved
core/key.go Show resolved Hide resolved
core/key.go Show resolved Hide resolved
client/collection.go Outdated Show resolved Hide resolved
core/key.go Outdated Show resolved Hide resolved
core/key.go Outdated Show resolved Hide resolved
@islamaliev islamaliev force-pushed the islam/feat/297-non-unique-secondary-index branch from 6e13d5a to 5fae460 Compare May 19, 2023 07:11
@islamaliev islamaliev force-pushed the islam/feat/297-non-unique-secondary-index branch 2 times, most recently from 6710210 to 106f7e0 Compare May 30, 2023 15:32
@islamaliev islamaliev marked this pull request as ready for review May 30, 2023 15:35
@jsimnz jsimnz changed the title Islam/feat/297 non unique secondary index feat: Non-unique secondary index May 31, 2023
@islamaliev islamaliev force-pushed the islam/feat/297-non-unique-secondary-index branch from 132dc53 to 53391ae Compare May 31, 2023 10:44
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.

Submitting a partial review for now, as I need a breather from it - it looks good in general, but I have have few low-scope todos so far

db/fetcher/encoded_doc.go Show resolved Hide resolved
.github/codecov.yml Show resolved Hide resolved
client/collection.go Outdated Show resolved Hide resolved
client/collection.go Show resolved Hide resolved
client/descriptions.go Outdated Show resolved Hide resolved
core/key.go Show resolved Hide resolved
core/key.go Outdated Show resolved Hide resolved
core/key.go Outdated Show resolved Hide resolved
core/key.go Outdated Show resolved Hide resolved
core/key.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.

Taking another break - added some more comments :)

db/collection_get.go Show resolved Hide resolved
db/collection_index.go Outdated Show resolved Hide resolved
db/index.go Show resolved Hide resolved
db/collection_index.go Show resolved Hide resolved
db/collection_index.go Show resolved Hide resolved
db/index.go Outdated Show resolved Hide resolved
db/index.go Outdated Show resolved Hide resolved
db/index.go Outdated Show resolved Hide resolved
db/index.go Outdated Show resolved Hide resolved
request/graphql/schema/collection.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

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

Overall I think you're on a good path. I've got a few comments to start. I haven't looked at the tests extensively yet but on first pass I like the mocks.

core/key.go Outdated Show resolved Hide resolved
core/key.go Outdated Show resolved Hide resolved
db/fetcher/encoded_doc.go Outdated Show resolved Hide resolved
db/fetcher/fetcher.go Show resolved Hide resolved
db/index.go Outdated Show resolved Hide resolved
db/index.go Outdated Show resolved Hide resolved
db/index.go Outdated Show resolved Hide resolved
db/index.go Outdated Show resolved Hide resolved
db/index.go Outdated Show resolved Hide resolved
request/graphql/parser.go Show resolved Hide resolved
db/collection.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.

Made it all the way through - looks good, but I think you really need to add some integration tests, and there are a few localised issues that need addressing.

db/index.go Outdated Show resolved Hide resolved
db/index.go Outdated Show resolved Hide resolved
db/index.go Outdated Show resolved Hide resolved
request/graphql/schema/collection.go Outdated Show resolved Hide resolved
request/graphql/schema/collection.go Outdated Show resolved Hide resolved
db/collection_index.go Outdated Show resolved Hide resolved
@islamaliev islamaliev force-pushed the islam/feat/297-non-unique-secondary-index branch from 19dff9e to 35802a4 Compare June 12, 2023 19:49
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.

Gave the integration tests a look over, will go over the prod code again once you re-quest review. Tests look great, thanks a bunch for adding them now, just left a couple of small comments.

tests/integration/index/create_test.go Outdated Show resolved Hide resolved
tests/integration/index/drop_test.go Outdated Show resolved Hide resolved
tests/integration/index/create_test.go Show resolved Hide resolved
tests/integration/index/drop_test.go Show resolved Hide resolved
tests/integration/index/create_test.go Show resolved Hide resolved
datastore/mocks/utils.go Outdated Show resolved Hide resolved
datastore/mocks/DAGStore.go Outdated Show resolved Hide resolved
client/index.go Outdated Show resolved Hide resolved
request/graphql/schema/index_test.go Outdated Show resolved Hide resolved
db/index_test.go Outdated Show resolved Hide resolved
db/indexed_docs_test.go Outdated Show resolved Hide resolved
db/index.go Outdated Show resolved Hide resolved
db/fetcher/mocks/utils.go Outdated Show resolved Hide resolved
db/collection_index.go Outdated Show resolved Hide resolved
request/graphql/parser/request.go Show resolved Hide resolved
@islamaliev islamaliev force-pushed the islam/feat/297-non-unique-secondary-index branch from f35622d to 6e24502 Compare June 19, 2023 14:00
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.

Really great work Islam, looks good to me :)

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

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

Just a few more todos before I approve. I noted a few methods that should have documentation as they are exported. I think there are a few others in your PR that are exported without documentation. I'm flagging them as this is good for internal devs when looking at the code but also because it adds useful information with intelisense in IDEs.

db/collection_index.go Show resolved Hide resolved
db/collection_index.go Show resolved Hide resolved
db/collection_index.go Show resolved Hide resolved
Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

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

LGTM! Great work Islam!

@islamaliev islamaliev dismissed shahzadlone’s stale review June 19, 2023 18:40

addressed all comments

@islamaliev islamaliev merged commit be619fd into develop Jun 19, 2023
13 checks passed
@islamaliev islamaliev deleted the islam/feat/297-non-unique-secondary-index branch June 19, 2023 18:44
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
Resolves sourcenetwork#297 

## Description

This change introduces first functionality for secondary indexes which
includes:
- specifying index for a collection as part of the collection schema and
parsing it
- mocks for interfaces the index functionality depends on
- db methods to create, delete and retrieve indexes
- storing index data in the system storage
- storing indexed fields' values to data storage
- change to the testing framework to allow testing of indexes

This change doesn't include using indexes for fetching data for queries to
keep the PR smaller.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api Related to the external API component feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sec. Indexes: Implement non-unique indexes (querying excluded)
5 participants