-
Notifications
You must be signed in to change notification settings - Fork 330
Put uuids in the vae and eav index #1326
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
Changes from all commits
f0806ca
7f704e4
a6d7755
775c8fb
961d33d
70c3eba
dc137c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| drop function public.json_uuid_to_uuid(v jsonb); | ||
|
|
||
| drop index vae_uuid_index; | ||
|
|
||
| drop index eav_uuid_index; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| create or replace function public.json_uuid_to_uuid(v jsonb) returns uuid | ||
| language sql | ||
| parallel safe | ||
| immutable | ||
| as $$ | ||
| select (v->>0)::uuid | ||
| end; | ||
| $$; | ||
|
|
||
| -- Create this index concurrently before running the migration | ||
| create index if not exists vae_uuid_index | ||
| on triples(app_id, public.json_uuid_to_uuid(value), attr_id, entity_id) | ||
| where vae; | ||
|
|
||
| -- Create this index concurrently before running the migration | ||
| create unique index if not exists eav_uuid_index | ||
| on triples(app_id, entity_id, attr_id, public.json_uuid_to_uuid(value)) | ||
| where eav; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -523,20 +523,20 @@ | |
| (string/replace (name x) "-" "_")) | ||
|
|
||
| (defn- match-table-cols | ||
| "Every match table returns entity-id, attr-id, value-blob, value-uuid, | ||
| "Every match table returns entity-id, attr-id, value-blob, is-ref-val, | ||
| and created-at columns. This is a quick helper to generate the column names" | ||
| [table-name] | ||
| [(kw table-name :-entity-id) | ||
| (kw table-name :-attr-id) | ||
| (kw table-name :-value-blob) | ||
| (kw table-name :-value-uuid) | ||
| (kw table-name :-is-ref-val) | ||
| (kw table-name :-created-at)]) | ||
|
|
||
| (defn- match-table-select | ||
| "This generates the select portion of the match table. " | ||
| [table-name] | ||
| (map vector [:entity-id :attr-id :value | ||
| [:case :eav [:cast [:->> :value :0] :uuid] :else :null] | ||
| :eav | ||
| :created-at] | ||
| (match-table-cols table-name))) | ||
|
|
||
|
|
@@ -722,14 +722,14 @@ | |
| {:name :ea_index | ||
| :cols [:e :a] | ||
| :idx-key :ea} | ||
| {:name :eav_index | ||
| {:name :eav_uuid_index | ||
| :cols [:e :a :v] | ||
| :idx-key :eav} | ||
| {:name :triples_string_trgm_gist_idx | ||
| :cols [:a :v] | ||
| :idx-key :ave | ||
| :data-type :string} | ||
| {:name :vae_index | ||
| {:name :vae_uuid_index | ||
| :cols [:v :a :e] | ||
| :idx-key :vae} | ||
| {:name :triples_created_at_idx | ||
|
|
@@ -808,7 +808,7 @@ | |
| For example: | ||
|
|
||
| [1 [:v :v]] => [:value :match-1-value-blob] | ||
| [1 [:e :v]] => [:entity-id :match-1-value-uuid] | ||
| [1 [:e :v]] => [:entity-id [:json_uuid_to_uuid :match-1-value-blob]] | ||
| [1 [:v :a]] => [:value [:to_jsonb :match-1-attr-id]]" | ||
| [prefix dest-idx [origin-ctype dest-ctype]] | ||
|
|
||
|
|
@@ -821,7 +821,7 @@ | |
| [:value [:to_jsonb (dest-col (component-type->col-name dest-ctype))]] | ||
|
|
||
| (= :v dest-ctype) | ||
| [(component-type->col-name origin-ctype) (dest-col :value-uuid)] | ||
| [(component-type->col-name origin-ctype) [:json_uuid_to_uuid (dest-col :value-blob)]] | ||
|
|
||
| :else | ||
| [(component-type->col-name origin-ctype) | ||
|
|
@@ -863,7 +863,7 @@ | |
|
|
||
| The second part joins the first on | ||
|
|
||
| [[:= :entity-id :match-0-value-uuid]]" | ||
| [[:= :entity-id [:json_uuid_to_uuid :match-0-value-blob]]]" | ||
| [prefix symbol-map named-p] | ||
| (->> named-p | ||
| variable-components | ||
|
|
@@ -1061,7 +1061,7 @@ | |
| (if (named-variable? x) | ||
| (assoc acc pat-idx {:sym sym | ||
| :ref-value? (and (= :v component) | ||
| (= :eav (idx-key (:idx named-p))))}) | ||
| (= :vae (idx-key (:idx named-p))))}) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also fixes a bug in the topics, where we weren't removing I don't think we actually encounter the bug in prod because we always invalidate the |
||
| acc))) | ||
| {} | ||
| [[:e 0] [:a 1] [:v 2]])) | ||
|
|
@@ -1747,20 +1747,21 @@ | |
| (parse-uuid x))) | ||
|
|
||
| (defn- sql-row->triple | ||
| "Converts the sql result, which returns value in either the | ||
| value-uuid or value-blob col, into our triple format. | ||
| "Converts the sql result into our triple format. | ||
| Optionally parses uuids, when handling batched results that return JSON" | ||
| [row [e-col a-col v-blob-col v-uuid-col t-col] coerce-uuids?] | ||
| [row [e-col a-col v-blob-col v-is-ref-val-col t-col] coerce-uuids?] | ||
| (if coerce-uuids? | ||
| [(safe-parse-uuid (get row e-col)) | ||
| (safe-parse-uuid (get row a-col)) | ||
| (or (safe-parse-uuid (get row v-uuid-col)) | ||
| (get row v-blob-col)) | ||
| (if (get row v-is-ref-val-col) | ||
| (safe-parse-uuid (get row v-blob-col)) | ||
| (get row v-blob-col)) | ||
| (get row t-col)] | ||
| [(get row e-col) | ||
| (get row a-col) | ||
| (or (get row v-uuid-col) | ||
| (get row v-blob-col)) | ||
| (if (get row v-is-ref-val-col) | ||
| (safe-parse-uuid (get row v-blob-col)) | ||
| (get row v-blob-col)) | ||
| (get row t-col)])) | ||
|
|
||
| (defn- ensure-default-symbol-values [symbol-fields symbol-values] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1188,6 +1188,16 @@ | |
| patterns)] | ||
| (collect-query-results ctx (:data datalog-result) forms))))) | ||
|
|
||
| (defn explain | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh heck yeah! |
||
| "Generates a nested datalog query, then runs explain." | ||
| [ctx o] | ||
| (let [query-hash (forms-hash o) | ||
| explain-fn (or (:datalog-explain-fn ctx) | ||
| d/explain) | ||
| {:keys [patterns]} (instaql-query->patterns ctx o)] | ||
| (explain-fn (assoc ctx :query-hash query-hash) | ||
| patterns))) | ||
|
|
||
| ;; BYOP InstaQL | ||
|
|
||
| (defn safe-table | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍