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 primary directive for schema definitions (@primary) #650

Merged
merged 3 commits into from
Jul 22, 2022

Conversation

jsimnz
Copy link
Member

@jsimnz jsimnz commented Jul 22, 2022

Relevant issue(s)

Resolves #323

Description

Simple implementation, adds support for @primary directive on schema field definitions. During generate, we scan and manually apply client.Relation_Type_Primary if the directive is present. Only applies to one-to-one relationships. Change is minimal because the RelationManager already handles the case for manually setting the Primary bit on the relationship metadata type. It only automatically sets it if neither side of the relationship has it already set.

Also added a quick test (in the same test suite) for @relation(name: "...") to manually set the names of relationships, as they were missing.

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?

Added unit tests within the schema package for both @primary and @relation directives.

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

  • Debian Linux (via WSL2)

@jsimnz jsimnz added feature New feature or request area/schema Related to the schema system labels Jul 22, 2022
@jsimnz jsimnz added this to the DefraDB v0.3 milestone Jul 22, 2022
@jsimnz jsimnz requested a review from a team July 22, 2022 01:57
@jsimnz jsimnz self-assigned this Jul 22, 2022
@codecov
Copy link

codecov bot commented Jul 22, 2022

Codecov Report

Merging #650 (a75f2f4) into develop (dd28534) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #650      +/-   ##
===========================================
+ Coverage    57.11%   57.14%   +0.02%     
===========================================
  Files          122      122              
  Lines        14652    14662      +10     
===========================================
+ Hits          8368     8378      +10     
  Misses        5567     5567              
  Partials       717      717              
Impacted Files Coverage Δ
query/graphql/schema/types/types.go 100.00% <ø> (ø)
query/graphql/schema/generate.go 84.59% <100.00%> (+0.17%) ⬆️

@source-devs
Copy link

Benchmark Results

Summary

  • 113 Benchmarks successfully compared.
  • 45 Benchmarks were ✅ Better.
  • 68 Benchmarks were ❌ Worse .
  • 0 Benchmarks were ✨ Unchanged.
✅ See Better Results...
time/opdelta
_Collection_UserSimple_Create_Sync_0_100-4101ms ± 0%99ms ± 0%−1.57%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_10_10-4348µs ± 0%341µs ± 0%−1.93%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_1000_1000-439.2ms ± 0%39.0ms ± 0%−0.50%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_1000_100-43.91ms ± 0%3.88ms ± 0%−0.67%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_1000_10-4255µs ± 0%254µs ± 0%−0.36%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithFilter_Sync_10-4455µs ± 0%453µs ± 0%−0.44%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0256-4143µs ± 0%141µs ± 0%−1.30%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0512-4158µs ± 0%156µs ± 0%−1.04%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0256-415.3µs ± 0%15.2µs ± 0%−0.12%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0128-4143µs ± 0%141µs ± 0%−1.01%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0256-4149µs ± 0%146µs ± 0%−1.59%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0512-4164µs ± 0%158µs ± 0%−3.31%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:1024-4203µs ± 0%197µs ± 0%−2.61%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0512-453.9µs ± 0%53.8µs ± 0%−0.08%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0064-4119µs ± 0%117µs ± 0%−1.77%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0128-4121µs ± 0%118µs ± 0%−1.99%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0256-4124µs ± 0%118µs ± 0%−4.40%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0512-4126µs ± 0%126µs ± 0%−0.00%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:1024-4139µs ± 0%137µs ± 0%−1.30%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0064-41.21ms ± 0%1.17ms ± 0%−3.08%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0128-41.22ms ± 0%1.18ms ± 0%−3.15%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0256-41.26ms ± 0%1.17ms ± 0%−6.65%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0512-41.26ms ± 0%1.23ms ± 0%−1.89%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0064-4118µs ± 0%114µs ± 0%−2.74%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0128-4121µs ± 0%118µs ± 0%−2.86%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0064-41.22ms ± 0%1.14ms ± 0%−7.15%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0128-41.19ms ± 0%1.17ms ± 0%−1.18%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0256-41.20ms ± 0%1.19ms ± 0%−1.33%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:1024-41.35ms ± 0%1.31ms ± 0%−2.73%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0064-48.55µs ± 0%8.17µs ± 0%−4.36%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0128-48.99µs ± 0%8.44µs ± 0%−6.13%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0256-410.4µs ± 0%9.2µs ± 0%−11.26%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0512-411.4µs ± 0%10.9µs ± 0%−4.08%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:1024-414.7µs ± 0%14.5µs ± 0%−1.02%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0064-495.8µs ± 0%87.3µs ± 0%−8.89%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0128-493.4µs ± 0%91.2µs ± 0%−2.37%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0128-4128µs ± 0%128µs ± 0%−0.08%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0256-4128µs ± 0%122µs ± 0%−5.07%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0512-4130µs ± 0%128µs ± 0%−1.49%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:1024-4133µs ± 0%128µs ± 0%−3.69%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0064-41.27ms ± 0%1.21ms ± 0%−4.83%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0128-41.24ms ± 0%1.18ms ± 0%−4.86%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0256-41.25ms ± 0%1.20ms ± 0%−4.55%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0512-41.27ms ± 0%1.24ms ± 0%−2.41%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:1024-41.34ms ± 0%1.30ms ± 0%−2.54%(p=1.000 n=1+1)
 
❌ See Worse Results...
time/opdelta
_Collection_UserSimple_CreateMany_Sync_0_100-4228ms ± 0%229ms ± 0%+0.78%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Sync_0_10-49.84ms ± 0%10.29ms ± 0%+4.57%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Sync_0_1000-41.00s ± 0%1.06s ± 0%+5.85%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Async_0_100-443.7ms ± 0%46.2ms ± 0%+5.75%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Async_0_1000-4434ms ± 0%435ms ± 0%+0.35%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Async_0_10000-44.42s ± 0%4.53s ± 0%+2.52%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_100_100-43.67ms ± 0%3.81ms ± 0%+3.68%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_1000_10-4361µs ± 0%362µs ± 0%+0.18%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_10_10-4249µs ± 0%259µs ± 0%+3.92%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_100_100-41.77ms ± 0%1.82ms ± 0%+2.95%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_1000_1000-422.8ms ± 0%24.6ms ± 0%+7.93%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_1000_100-41.80ms ± 0%1.87ms ± 0%+4.06%(p=1.000 n=1+1)
_Query_UserSimple_Query_Sync_100-41.12ms ± 0%1.17ms ± 0%+4.06%(p=1.000 n=1+1)
_Query_UserSimple_Query_Sync_1000-49.34ms ± 0%9.47ms ± 0%+1.39%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithFilter_Sync_100-41.23ms ± 0%1.30ms ± 0%+6.11%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithFilter_Sync_1000-49.60ms ± 0%9.84ms ± 0%+2.57%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithLimitOffset_Sync_10-4400µs ± 0%432µs ± 0%+7.91%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithLimitOffset_Sync_100-4450µs ± 0%468µs ± 0%+4.02%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithLimitOffset_Sync_1000-4465µs ± 0%466µs ± 0%+0.22%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithMultiLookup_Sync_10-4675µs ± 0%692µs ± 0%+2.46%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithMultiLookup_Sync_100-4674µs ± 0%713µs ± 0%+5.83%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithMultiLookup_Sync_1000-4680µs ± 0%695µs ± 0%+2.23%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSort_Sync_10-4423µs ± 0%447µs ± 0%+5.61%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSort_Sync_100-41.22ms ± 0%1.28ms ± 0%+4.74%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSort_Sync_1000-49.64ms ± 0%10.16ms ± 0%+5.31%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSingleLookup_Sync_10-4296µs ± 0%301µs ± 0%+1.42%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSingleLookup_Sync_100-4301µs ± 0%304µs ± 0%+0.89%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSingleLookup_Sync_1000-4301µs ± 0%301µs ± 0%+0.24%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:0128-413.3µs ± 0%13.8µs ± 0%+3.55%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:0256-414.1µs ± 0%14.1µs ± 0%+0.40%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:0512-415.7µs ± 0%16.0µs ± 0%+2.18%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:1024-419.2µs ± 0%21.7µs ± 0%+13.06%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0064-4123µs ± 0%131µs ± 0%+6.20%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0128-4134µs ± 0%137µs ± 0%+1.84%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:1024-4196µs ± 0%197µs ± 0%+0.26%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0064-414.7µs ± 0%15.8µs ± 0%+7.40%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0128-414.9µs ± 0%15.3µs ± 0%+2.05%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0512-417.2µs ± 0%17.5µs ± 0%+2.10%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:1024-420.5µs ± 0%20.6µs ± 0%+0.61%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0064-4136µs ± 0%136µs ± 0%+0.09%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0064-443.7µs ± 0%53.5µs ± 0%+22.29%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0128-446.9µs ± 0%51.4µs ± 0%+9.72%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0256-450.0µs ± 0%51.7µs ± 0%+3.52%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0512-454.1µs ± 0%56.5µs ± 0%+4.39%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:1024-466.2µs ± 0%69.2µs ± 0%+4.53%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0064-4352µs ± 0%386µs ± 0%+9.70%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0128-4337µs ± 0%357µs ± 0%+6.13%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0256-4346µs ± 0%362µs ± 0%+4.44%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0512-4397µs ± 0%407µs ± 0%+2.33%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:1024-4474µs ± 0%504µs ± 0%+6.39%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0064-444.6µs ± 0%46.3µs ± 0%+3.62%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0128-445.6µs ± 0%47.1µs ± 0%+3.24%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0256-446.7µs ± 0%48.0µs ± 0%+2.65%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:1024-465.0µs ± 0%66.5µs ± 0%+2.35%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0064-4343µs ± 0%357µs ± 0%+4.05%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0128-4340µs ± 0%353µs ± 0%+3.68%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0256-4352µs ± 0%385µs ± 0%+9.46%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0512-4381µs ± 0%419µs ± 0%+9.84%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:1024-4482µs ± 0%503µs ± 0%+4.42%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:1024-41.37ms ± 0%1.39ms ± 0%+1.60%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0256-4119µs ± 0%122µs ± 0%+2.58%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0512-4125µs ± 0%129µs ± 0%+3.64%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:1024-4135µs ± 0%138µs ± 0%+2.41%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0512-41.24ms ± 0%1.25ms ± 0%+1.01%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0256-4101µs ± 0%106µs ± 0%+5.40%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0512-4113µs ± 0%141µs ± 0%+25.40%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:1024-4151µs ± 0%153µs ± 0%+1.42%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0064-4122µs ± 0%123µs ± 0%+1.12%(p=1.000 n=1+1)
 
✨ See Unchanged Results...
time/opdelta
 
🐋 See Full Results...
develop.txtcurrent.txt
time/opdelta
pkg:collection goos:linux goarch:amd64
_Collection_UserSimple_CreateMany_Sync_0_10-410.9ms ± 0%10.8ms ± 0%−1.13%(p=1.000 n=1+1)
_Collection_UserSimple_CreateMany_Sync_0_100-4228ms ± 0%229ms ± 0%+0.78%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Sync_0_10-49.84ms ± 0%10.29ms ± 0%+4.57%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Sync_0_100-4101ms ± 0%99ms ± 0%−1.57%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Sync_0_1000-41.00s ± 0%1.06s ± 0%+5.85%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Async_0_100-443.7ms ± 0%46.2ms ± 0%+5.75%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Async_0_1000-4434ms ± 0%435ms ± 0%+0.35%(p=1.000 n=1+1)
_Collection_UserSimple_Create_Async_0_10000-44.42s ± 0%4.53s ± 0%+2.52%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_10_10-4348µs ± 0%341µs ± 0%−1.93%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_100_100-43.67ms ± 0%3.81ms ± 0%+3.68%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_1000_1000-439.2ms ± 0%39.0ms ± 0%−0.50%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_1000_10-4361µs ± 0%362µs ± 0%+0.18%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Sync_1000_100-43.91ms ± 0%3.88ms ± 0%−0.67%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_10_10-4249µs ± 0%259µs ± 0%+3.92%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_100_100-41.77ms ± 0%1.82ms ± 0%+2.95%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_1000_1000-422.8ms ± 0%24.6ms ± 0%+7.93%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_1000_10-4255µs ± 0%254µs ± 0%−0.36%(p=1.000 n=1+1)
_Collection_UserSimple_Read_Async_1000_100-41.80ms ± 0%1.87ms ± 0%+4.06%(p=1.000 n=1+1)
pkg:query/simple goos:linux goarch:amd64
_Query_UserSimple_Query_Sync_10-4362µs ± 0%375µs ± 0%+3.49%(p=1.000 n=1+1)
_Query_UserSimple_Query_Sync_100-41.12ms ± 0%1.17ms ± 0%+4.06%(p=1.000 n=1+1)
_Query_UserSimple_Query_Sync_1000-49.34ms ± 0%9.47ms ± 0%+1.39%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithFilter_Sync_10-4455µs ± 0%453µs ± 0%−0.44%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithFilter_Sync_100-41.23ms ± 0%1.30ms ± 0%+6.11%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithFilter_Sync_1000-49.60ms ± 0%9.84ms ± 0%+2.57%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithLimitOffset_Sync_10-4400µs ± 0%432µs ± 0%+7.91%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithLimitOffset_Sync_100-4450µs ± 0%468µs ± 0%+4.02%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithLimitOffset_Sync_1000-4465µs ± 0%466µs ± 0%+0.22%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithMultiLookup_Sync_10-4675µs ± 0%692µs ± 0%+2.46%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithMultiLookup_Sync_100-4674µs ± 0%713µs ± 0%+5.83%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithMultiLookup_Sync_1000-4680µs ± 0%695µs ± 0%+2.23%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSort_Sync_10-4423µs ± 0%447µs ± 0%+5.61%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSort_Sync_100-41.22ms ± 0%1.28ms ± 0%+4.74%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSort_Sync_1000-49.64ms ± 0%10.16ms ± 0%+5.31%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSingleLookup_Sync_10-4296µs ± 0%301µs ± 0%+1.42%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSingleLookup_Sync_100-4301µs ± 0%304µs ± 0%+0.89%(p=1.000 n=1+1)
_Query_UserSimple_Query_WithSingleLookup_Sync_1000-4301µs ± 0%301µs ± 0%+0.24%(p=1.000 n=1+1)
pkg:storage goos:linux goarch:amd64
_Storage_Simple_Read_Sync_1_10/ValueSize:0064-414.0µs ± 0%12.8µs ± 0%−8.47%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:0128-413.3µs ± 0%13.8µs ± 0%+3.55%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:0256-414.1µs ± 0%14.1µs ± 0%+0.40%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:0512-415.7µs ± 0%16.0µs ± 0%+2.18%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_10/ValueSize:1024-419.2µs ± 0%21.7µs ± 0%+13.06%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0064-4123µs ± 0%131µs ± 0%+6.20%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0128-4134µs ± 0%137µs ± 0%+1.84%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0256-4143µs ± 0%141µs ± 0%−1.30%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:0512-4158µs ± 0%156µs ± 0%−1.04%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_1_100/ValueSize:1024-4196µs ± 0%197µs ± 0%+0.26%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0064-414.7µs ± 0%15.8µs ± 0%+7.40%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0128-414.9µs ± 0%15.3µs ± 0%+2.05%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0256-415.3µs ± 0%15.2µs ± 0%−0.12%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:0512-417.2µs ± 0%17.5µs ± 0%+2.10%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_10/ValueSize:1024-420.5µs ± 0%20.6µs ± 0%+0.61%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0064-4136µs ± 0%136µs ± 0%+0.09%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0128-4143µs ± 0%141µs ± 0%−1.01%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0256-4149µs ± 0%146µs ± 0%−1.59%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:0512-4164µs ± 0%158µs ± 0%−3.31%(p=1.000 n=1+1)
_Storage_Simple_Read_Sync_100_100/ValueSize:1024-4203µs ± 0%197µs ± 0%−2.61%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0064-443.7µs ± 0%53.5µs ± 0%+22.29%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0128-446.9µs ± 0%51.4µs ± 0%+9.72%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0256-450.0µs ± 0%51.7µs ± 0%+3.52%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:0512-454.1µs ± 0%56.5µs ± 0%+4.39%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_10/ValueSize:1024-466.2µs ± 0%69.2µs ± 0%+4.53%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0064-4352µs ± 0%386µs ± 0%+9.70%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0128-4337µs ± 0%357µs ± 0%+6.13%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0256-4346µs ± 0%362µs ± 0%+4.44%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:0512-4397µs ± 0%407µs ± 0%+2.33%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_0_100/ValueSize:1024-4474µs ± 0%504µs ± 0%+6.39%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0064-444.6µs ± 0%46.3µs ± 0%+3.62%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0128-445.6µs ± 0%47.1µs ± 0%+3.24%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0256-446.7µs ± 0%48.0µs ± 0%+2.65%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:0512-453.9µs ± 0%53.8µs ± 0%−0.08%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_10/ValueSize:1024-465.0µs ± 0%66.5µs ± 0%+2.35%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0064-4343µs ± 0%357µs ± 0%+4.05%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0128-4340µs ± 0%353µs ± 0%+3.68%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0256-4352µs ± 0%385µs ± 0%+9.46%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:0512-4381µs ± 0%419µs ± 0%+9.84%(p=1.000 n=1+1)
_Storage_Simple_WriteMany_Sync_100_100/ValueSize:1024-4482µs ± 0%503µs ± 0%+4.42%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0064-4119µs ± 0%117µs ± 0%−1.77%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0128-4121µs ± 0%118µs ± 0%−1.99%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0256-4124µs ± 0%118µs ± 0%−4.40%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:0512-4126µs ± 0%126µs ± 0%−0.00%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_10/ValueSize:1024-4139µs ± 0%137µs ± 0%−1.30%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0064-41.21ms ± 0%1.17ms ± 0%−3.08%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0128-41.22ms ± 0%1.18ms ± 0%−3.15%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0256-41.26ms ± 0%1.17ms ± 0%−6.65%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:0512-41.26ms ± 0%1.23ms ± 0%−1.89%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_0_100/ValueSize:1024-41.37ms ± 0%1.39ms ± 0%+1.60%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0064-4118µs ± 0%114µs ± 0%−2.74%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0128-4121µs ± 0%118µs ± 0%−2.86%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0256-4119µs ± 0%122µs ± 0%+2.58%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:0512-4125µs ± 0%129µs ± 0%+3.64%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_10/ValueSize:1024-4135µs ± 0%138µs ± 0%+2.41%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0064-41.22ms ± 0%1.14ms ± 0%−7.15%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0128-41.19ms ± 0%1.17ms ± 0%−1.18%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0256-41.20ms ± 0%1.19ms ± 0%−1.33%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:0512-41.24ms ± 0%1.25ms ± 0%+1.01%(p=1.000 n=1+1)
_Storage_Simple_Write_Sync_100_100/ValueSize:1024-41.35ms ± 0%1.31ms ± 0%−2.73%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0064-48.55µs ± 0%8.17µs ± 0%−4.36%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0128-48.99µs ± 0%8.44µs ± 0%−6.13%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0256-410.4µs ± 0%9.2µs ± 0%−11.26%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:0512-411.4µs ± 0%10.9µs ± 0%−4.08%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_10_10/ValueSize:1024-414.7µs ± 0%14.5µs ± 0%−1.02%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0064-495.8µs ± 0%87.3µs ± 0%−8.89%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0128-493.4µs ± 0%91.2µs ± 0%−2.37%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0256-4101µs ± 0%106µs ± 0%+5.40%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:0512-4113µs ± 0%141µs ± 0%+25.40%(p=1.000 n=1+1)
_Storage_Simple_Txn_Read_Sync_100_100/ValueSize:1024-4151µs ± 0%153µs ± 0%+1.42%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0064-4122µs ± 0%123µs ± 0%+1.12%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0128-4128µs ± 0%128µs ± 0%−0.08%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0256-4128µs ± 0%122µs ± 0%−5.07%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:0512-4130µs ± 0%128µs ± 0%−1.49%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_10_1_10/ValueSize:1024-4133µs ± 0%128µs ± 0%−3.69%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0064-41.27ms ± 0%1.21ms ± 0%−4.83%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0128-41.24ms ± 0%1.18ms ± 0%−4.86%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0256-41.25ms ± 0%1.20ms ± 0%−4.55%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:0512-41.27ms ± 0%1.24ms ± 0%−2.41%(p=1.000 n=1+1)
_Storage_Simple_Txn_Iterator_Sync_100_1_100/ValueSize:1024-41.34ms ± 0%1.30ms ± 0%−2.54%(p=1.000 n=1+1)
 

@shahzadlone shahzadlone added the action/no-benchmark Skips the action that runs the benchmark. label Jul 22, 2022
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! Just a minor personal preference suggestion and one that is to follow idiomatic Go naming convention. Up to you to change or not.

@@ -432,11 +432,19 @@ func (g *Generator) buildTypesFromAST(
return nil, err
}

// set the primary relation bit on the relation type if the directive exists on the
// field
isPrimary := (findDirective(field, "primary") != nil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion (non-blocking): I think there shouldn't be any parentheses around the logical operation. But that is mostly a personal preference.

Copy link
Member Author

Choose a reason for hiding this comment

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

I casully use them in this instance to re-inforce the fact that the value is a bool encapsulated by the result of whatever is inside the parenthesis. But I'll remove

// set the primary relation bit on the relation type if the directive exists on the
// field
isPrimary := (findDirective(field, "primary") != nil)
reltype := client.Relation_Type_ONE
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: I think relType would be more idiomatic

Copy link
Member

Choose a reason for hiding this comment

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

+1

Name: RelationLabel,
Args: gql.FieldConfigArgument{
"name": &gql.ArgumentConfig{
Type: gql.String,
Copy link
Member

Choose a reason for hiding this comment

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

question: Just to confirm, if we only get @relation without a name: = ... argument we still don't want a default name value set.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thats a good points. I guess for now, if @relation is present with no name: argument, we do just want the default generated name. The alternative would be to throw an error.

Copy link
Member

Choose a reason for hiding this comment

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

What is the default generated name right now?

Comment on lines 1297 to 1318
func findDirective(field *ast.FieldDefinition, directiveName string) *ast.Directive {
for _, directive := range field.Directives {
if directive.Name.Value == directiveName {
return directive
}
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

thought: reminds me of this function I wrote in parser/query.go:

// parseExplainDirective returns true if we parsed / detected the explain directive label
// in this ast, and false otherwise.
func parseExplainDirective(directives []*ast.Directive) bool {
	// Iterate through all directives and ensure that the directive is at there.
	// - Note: the location we don't need to worry about as the schema takes care of it, as when
	//         request is made there will be a syntax error for directive usage at the wrong location,
	//         unless we add another directive named `@explain` at another location (which we should not).
	for _, directive := range directives {
		// The arguments pased to the directive are at `directive.Arguments`.
		if directive.Name.Value == parserTypes.ExplainLabel {
			return true
		}
	}

	return false
}

But the more I think about it I think it's okay to define it again here as you have done because this is at the schema step and the other at the parsing step.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did indeed see this one, but as you noted the diff between the parser and schema packages, and its simple enough.

isPrimary := (findDirective(field, "primary") != nil)
reltype := client.Relation_Type_ONE
if isPrimary {
reltype |= client.Relation_Type_Primary
Copy link
Member

@shahzadlone shahzadlone Jul 22, 2022

Choose a reason for hiding this comment

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

question: If I understand this correctly we have:

Relation_Type_Primary RelationType = 128 // 0b1000 0000
Relation_Type_ONE RelationType = 1 // 0b0000 0001

Bitwise OR of them will be = 0b1000 0001 = 129

So now the relType will be set to 129 instead of 128 == client.Relation_Type_Primary ?

I guess you then do client.Relation_Type_Primary | Relation_Type_ONE to check?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yupp basically.

To check, you just do some bit arithmetic, eg: if (relType & client.Relation_Type_Primary) > 0 will check if the correct bit is set

Copy link
Member

Choose a reason for hiding this comment

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

Reminds me of my embedded dev days haha. This works but just wondering what happens if someone defines a Relation_Type_ABC on client that might cause ambiguity to the binary bits.

// field
isPrimary := (findDirective(field, "primary") != nil)
reltype := client.Relation_Type_ONE
if isPrimary {
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: limit scope of isPrimary to if block or remove completely.

Suggested change
if isPrimary {
if findDirective(field, "primary") != nil {

nitpick: This could be even simpler if you just return bool instead from findDirective as you aren't using the returned value anyway (and it's the same value you put in, even if you do need it in future?).

Suggested change
if isPrimary {
if findDirective(field, "primary") {

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a good suggestion :)

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Name: "published_id",
Kind: client.FieldKind_DocKey,
Typ: client.LWW_REGISTER,
RelationType: client.Relation_Type_INTERNAL_ID,
Copy link
Member

Choose a reason for hiding this comment

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

question: Can relation type ever be only Relation_Type_Primary or Relation_Type_Primary | Relation_Type_One ? if so suggesting adding those test cases too?

Copy link
Member Author

Choose a reason for hiding this comment

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

They can't. Otherwise the finalize step of the relation manager would either error out, or hasn't been run, which case the finalized field would be false, which would cause an error.

Will think about defensive tests here, but not sure how to trigger it tbh.

Copy link
Member

Choose a reason for hiding this comment

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

In that case tests look good to me.

},
},
{
description: "Multiple types with relations (one-to-many)",
Copy link
Member

Choose a reason for hiding this comment

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

question: To confirm mostly for myself in the 1-N (one to many) case the 1 side will always be primary?

Copy link
Member Author

Choose a reason for hiding this comment

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

It matters less for the one-to-many case. We arbitrarily set the one side to be the primary at the moment. Can't 100% remember why. Usually, the primary side is whichever holds the reference to the foreign key, which is technically the many side. So not sure. Will look into this, but its fine for now.

// set the primary relation bit on the relation type if the directive exists on the
// field
isPrimary := (findDirective(field, "primary") != nil)
reltype := client.Relation_Type_ONE
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
reltype := client.Relation_Type_ONE
relType := client.Relation_Type_ONE

Copy link
Member

Choose a reason for hiding this comment

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

Ops nvm I see fred had the same suggestion.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

Neat stuff, just some non-blocking suggestions and lots of questions and thoughts mostly for myself.

Also would like the first word of the PR title to be Add instead of Added when you merge =D

LGTM!

For bonus marks maybe you can fix Relation_Type_Primary -> Relation_Type_PRIMARY as part of this PR?

@jsimnz jsimnz force-pushed the jsimnz/feat/primary-directive branch from bb21a62 to a6c8f41 Compare July 22, 2022 18:49
Also, added tests for relation directive as those were missing.
@jsimnz jsimnz force-pushed the jsimnz/feat/primary-directive branch from a6c8f41 to a75f2f4 Compare July 22, 2022 18:52
@jsimnz jsimnz changed the title feat: Added primary directive for schema definitions (@primary) feat: Add primary directive for schema definitions (@primary) Jul 22, 2022
@jsimnz jsimnz merged commit a0332b7 into develop Jul 22, 2022
@jsimnz jsimnz deleted the jsimnz/feat/primary-directive branch July 22, 2022 19:00
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
…network#650)

* Added primary directive support for schemas

* Tests for primary directive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/schema Related to the schema system feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle @primary directive properly
4 participants