hashintel / hash

🚀 The open-source, multi-tenant, self-building knowledge graph
https://hash.dev
Other
1.08k stars 83 forks source link

H-3429: Implement intersections for array constraints #5625

Closed TimDiekmann closed 4 days ago

TimDiekmann commented 6 days ago

🌟 What is the purpose of this PR?

Multiple array constraints may can be combined into a single one. This implements the intersection of array constraints (which includes tuples).

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

📜 Does this require a change to the docs?

The changes in this PR:

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

🛡 What tests cover this?

A number of tests were added

codecov[bot] commented 4 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 19.84%. Comparing base (311c4a9) to head (3cc36e6). Report is 22 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #5625 +/- ## ========================================== - Coverage 19.84% 19.84% -0.01% ========================================== Files 515 515 Lines 17322 17323 +1 Branches 2546 2547 +1 ========================================== Hits 3437 3437 - Misses 13847 13848 +1 Partials 38 38 ``` | [Flag](https://app.codecov.io/gh/hashintel/hash/pull/5625/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashintel) | Coverage Δ | | |---|---|---| | [apps.hash-ai-worker-ts](https://app.codecov.io/gh/hashintel/hash/pull/5625/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashintel) | `1.38% <ø> (ø)` | | | [apps.hash-api](https://app.codecov.io/gh/hashintel/hash/pull/5625/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashintel) | `1.17% <ø> (ø)` | | | [blockprotocol.type-system](https://app.codecov.io/gh/hashintel/hash/pull/5625/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashintel) | `47.40% <ø> (ø)` | | | [local.hash-backend-utils](https://app.codecov.io/gh/hashintel/hash/pull/5625/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashintel) | `8.80% <ø> (ø)` | | | [local.hash-graph-sdk](https://app.codecov.io/gh/hashintel/hash/pull/5625/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashintel) | `100.00% <ø> (ø)` | | | [local.hash-isomorphic-utils](https://app.codecov.io/gh/hashintel/hash/pull/5625/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashintel) | `1.05% <ø> (-0.01%)` | :arrow_down: | | [local.hash-subgraph](https://app.codecov.io/gh/hashintel/hash/pull/5625/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashintel) | `24.54% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashintel#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

github-actions[bot] commented 4 days ago

Benchmark results

@rust/hash-graph-benches – Integrations

## scaling_read_entity_complete_one_depth | Function | Value | Mean | Flame graphs | |----------|-------|------|--------------| | entity_by_id | 25 entities | $$73.8 \mathrm{ms} \pm 397 \mathrm{μs}\left({\color{red}7.15 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_complete_one_depth/entity_by_id/25+entities/flamegraph.svg) | | entity_by_id | 5 entities | $$25.5 \mathrm{ms} \pm 206 \mathrm{μs}\left({\color{gray}3.44 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_complete_one_depth/entity_by_id/5+entities/flamegraph.svg) | | entity_by_id | 1 entities | $$19.8 \mathrm{ms} \pm 122 \mathrm{μs}\left({\color{gray}-0.886 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_complete_one_depth/entity_by_id/1+entities/flamegraph.svg) | | entity_by_id | 10 entities | $$47.7 \mathrm{ms} \pm 2.25 \mathrm{ms}\left({\color{gray}-1.291 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_complete_one_depth/entity_by_id/10+entities/flamegraph.svg) | | entity_by_id | 50 entities | $$559 \mathrm{ms} \pm 4.37 \mathrm{ms}\left({\color{gray}4.12 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_complete_one_depth/entity_by_id/50+entities/flamegraph.svg) | ## representative_read_entity | Function | Value | Mean | Flame graphs | |----------|-------|------|--------------| | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/person/v/1` | $$16.5 \mathrm{ms} \pm 212 \mathrm{μs}\left({\color{gray}0.280 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_9/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/book/v/1` | $$16.7 \mathrm{ms} \pm 204 \mathrm{μs}\left({\color{gray}2.11 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_5/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1` | $$16.0 \mathrm{ms} \pm 195 \mathrm{μs}\left({\color{gray}-2.366 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_6/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/building/v/1` | $$15.5 \mathrm{ms} \pm 149 \mathrm{μs}\left({\color{lightgreen}-7.307 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_3/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/page/v/2` | $$16.2 \mathrm{ms} \pm 165 \mathrm{μs}\left({\color{gray}-4.086 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_7/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/song/v/1` | $$16.6 \mathrm{ms} \pm 213 \mathrm{μs}\left({\color{gray}-1.205 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_8/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/playlist/v/1` | $$16.0 \mathrm{ms} \pm 193 \mathrm{μs}\left({\color{gray}-0.729 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_4/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/organization/v/1` | $$16.4 \mathrm{ms} \pm 204 \mathrm{μs}\left({\color{gray}-3.778 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t/flamegraph.svg) | | entity_by_id | entity type ID: `https://blockprotocol.org/@alice/types/entity-type/block/v/1` | $$16.8 \mathrm{ms} \pm 150 \mathrm{μs}\left({\color{gray}-0.291 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_entity/entity_by_id/entity+type+ID_+`https___blockprotocol.org_@alice_types_entity-t_2/flamegraph.svg) | ## scaling_read_entity_complete_zero_depth | Function | Value | Mean | Flame graphs | |----------|-------|------|--------------| | entity_by_id | 25 entities | $$3.28 \mathrm{ms} \pm 11.7 \mathrm{μs}\left({\color{gray}-0.034 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_complete_zero_depth/entity_by_id/25+entities/flamegraph.svg) | | entity_by_id | 5 entities | $$1.88 \mathrm{ms} \pm 8.11 \mathrm{μs}\left({\color{gray}-1.234 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_complete_zero_depth/entity_by_id/5+entities/flamegraph.svg) | | entity_by_id | 1 entities | $$1.86 \mathrm{ms} \pm 6.95 \mathrm{μs}\left({\color{gray}-1.048 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_complete_zero_depth/entity_by_id/1+entities/flamegraph.svg) | | entity_by_id | 10 entities | $$2.11 \mathrm{ms} \pm 11.0 \mathrm{μs}\left({\color{gray}0.180 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_complete_zero_depth/entity_by_id/10+entities/flamegraph.svg) | | entity_by_id | 50 entities | $$5.29 \mathrm{ms} \pm 30.4 \mathrm{μs}\left({\color{red}28.9 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_complete_zero_depth/entity_by_id/50+entities/flamegraph.svg) | ## scaling_read_entity_linkless | Function | Value | Mean | Flame graphs | |----------|-------|------|--------------| | entity_by_id | 1 entities | $$1.84 \mathrm{ms} \pm 6.60 \mathrm{μs}\left({\color{gray}-0.682 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_linkless/entity_by_id/1+entities/flamegraph.svg) | | entity_by_id | 10000 entities | $$13.6 \mathrm{ms} \pm 111 \mathrm{μs}\left({\color{gray}0.277 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_linkless/entity_by_id/10000+entities/flamegraph.svg) | | entity_by_id | 100 entities | $$2.03 \mathrm{ms} \pm 12.2 \mathrm{μs}\left({\color{gray}-1.648 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_linkless/entity_by_id/100+entities/flamegraph.svg) | | entity_by_id | 1000 entities | $$2.80 \mathrm{ms} \pm 15.1 \mathrm{μs}\left({\color{gray}-0.337 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_linkless/entity_by_id/1000+entities/flamegraph.svg) | | entity_by_id | 10 entities | $$1.90 \mathrm{ms} \pm 7.55 \mathrm{μs}\left({\color{gray}0.036 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/scaling_read_entity_linkless/entity_by_id/10+entities/flamegraph.svg) | ## representative_read_multiple_entities | Function | Value | Mean | Flame graphs | |----------|-------|------|--------------| | link_by_source_by_property | depths: DT=255, PT=255, ET=255, E=255 | $$111 \mathrm{ms} \pm 653 \mathrm{μs}\left({\color{gray}3.79 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_multiple_entities/link_by_source_by_property/depths_+DT=255,+PT=255,+ET=255,+E=255/flamegraph.svg) | | link_by_source_by_property | depths: DT=0, PT=0, ET=2, E=2 | $$91.2 \mathrm{ms} \pm 451 \mathrm{μs}\left({\color{gray}3.13 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_multiple_entities/link_by_source_by_property/depths_+DT=0,+PT=0,+ET=2,+E=2/flamegraph.svg) | | link_by_source_by_property | depths: DT=2, PT=2, ET=2, E=2 | $$102 \mathrm{ms} \pm 650 \mathrm{μs}\left({\color{gray}4.80 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_multiple_entities/link_by_source_by_property/depths_+DT=2,+PT=2,+ET=2,+E=2/flamegraph.svg) | | link_by_source_by_property | depths: DT=0, PT=0, ET=0, E=0 | $$43.7 \mathrm{ms} \pm 247 \mathrm{μs}\left({\color{gray}4.01 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_multiple_entities/link_by_source_by_property/depths_+DT=0,+PT=0,+ET=0,+E=0/flamegraph.svg) | | link_by_source_by_property | depths: DT=0, PT=2, ET=2, E=2 | $$97.0 \mathrm{ms} \pm 752 \mathrm{μs}\left({\color{gray}4.41 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_multiple_entities/link_by_source_by_property/depths_+DT=0,+PT=2,+ET=2,+E=2/flamegraph.svg) | | link_by_source_by_property | depths: DT=0, PT=0, ET=0, E=2 | $$82.4 \mathrm{ms} \pm 414 \mathrm{μs}\left({\color{gray}3.21 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_multiple_entities/link_by_source_by_property/depths_+DT=0,+PT=0,+ET=0,+E=2/flamegraph.svg) | | entity_by_property | depths: DT=255, PT=255, ET=255, E=255 | $$70.5 \mathrm{ms} \pm 383 \mathrm{μs}\left({\color{gray}3.11 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_multiple_entities/entity_by_property/depths_+DT=255,+PT=255,+ET=255,+E=255/flamegraph.svg) | | entity_by_property | depths: DT=0, PT=0, ET=2, E=2 | $$50.6 \mathrm{ms} \pm 228 \mathrm{μs}\left({\color{gray}3.09 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_multiple_entities/entity_by_property/depths_+DT=0,+PT=0,+ET=2,+E=2/flamegraph.svg) | | entity_by_property | depths: DT=2, PT=2, ET=2, E=2 | $$59.5 \mathrm{ms} \pm 384 \mathrm{μs}\left({\color{gray}2.00 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_multiple_entities/entity_by_property/depths_+DT=2,+PT=2,+ET=2,+E=2/flamegraph.svg) | | entity_by_property | depths: DT=0, PT=0, ET=0, E=0 | $$40.6 \mathrm{ms} \pm 262 \mathrm{μs}\left({\color{gray}2.89 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_multiple_entities/entity_by_property/depths_+DT=0,+PT=0,+ET=0,+E=0/flamegraph.svg) | | entity_by_property | depths: DT=0, PT=2, ET=2, E=2 | $$55.4 \mathrm{ms} \pm 330 \mathrm{μs}\left({\color{gray}2.24 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_multiple_entities/entity_by_property/depths_+DT=0,+PT=2,+ET=2,+E=2/flamegraph.svg) | | entity_by_property | depths: DT=0, PT=0, ET=0, E=2 | $$45.1 \mathrm{ms} \pm 238 \mathrm{μs}\left({\color{gray}2.70 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_multiple_entities/entity_by_property/depths_+DT=0,+PT=0,+ET=0,+E=2/flamegraph.svg) | ## representative_read_entity_type | Function | Value | Mean | Flame graphs | |----------|-------|------|--------------| | get_entity_type_by_id | Account ID: `d4e16033-c281-4cde-aa35-9085bf2e7579` | $$1.38 \mathrm{ms} \pm 5.86 \mathrm{μs}\left({\color{gray}0.264 \mathrm{\\%}}\right) $$ | [Flame Graph](https://benchmarks.hash.dev/3cc36e6faee675bf9356878d26ddfce2c879f204/representative_read_entity_type/get_entity_type_by_id/Account+ID_+`d4e16033-c281-4cde-aa35-9085bf2e7579`/flamegraph.svg) |