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

Introduce step cache to reduce load on deduplicate #2279

Merged
merged 35 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
dda1a23
Optimize access dedupe
benjie Dec 10, 2024
5239c76
Enable caching of steps
benjie Dec 10, 2024
b904578
Update snapshots due to access caching
benjie Dec 10, 2024
70cbc21
Loop backwards to find fewest deps faster
benjie Dec 10, 2024
3170642
stepsWithNoDependencies might as well track the constructor to save e…
benjie Dec 10, 2024
589f28f
Peerkey to exclude non-peers faster
benjie Dec 10, 2024
aae6506
Move some checks earlier
benjie Dec 10, 2024
f5190df
Cache should honour current LayerPlan
benjie Dec 10, 2024
8f94b81
Have pgSelectSingle use the step cache
benjie Dec 10, 2024
85116af
Update plans following previous change
benjie Dec 10, 2024
e2d01d3
resetCache on plan phase change
benjie Dec 10, 2024
10e08c1
Cache get on pgClassExpression
benjie Dec 10, 2024
cdf1b69
Object step now uses peerKey
benjie Dec 10, 2024
79a3a61
More caching
benjie Dec 10, 2024
e673b36
Update plans
benjie Dec 10, 2024
b805a37
Auto cache access steps
benjie Dec 10, 2024
843dce1
Update plans again
benjie Dec 10, 2024
e07b619
Add some peerKeys
benjie Dec 10, 2024
6878df5
Clarify scope for key
benjie Dec 10, 2024
25fcb08
Auto-cache some more builtin steps
benjie Dec 10, 2024
93be719
Lint
benjie Dec 10, 2024
b336a58
docs(changeset): Introduce step caching to reduce deduplication workl…
benjie Dec 10, 2024
07321f3
Missing _
benjie Dec 10, 2024
9998895
Unnecessary
benjie Dec 10, 2024
1253f0e
Move the access caching up to the parent step
benjie Dec 10, 2024
158c747
Have access cache even more accesses
benjie Dec 10, 2024
5577012
JSON stringify cannot handle symbols
benjie Dec 10, 2024
90132fd
Overhaul deduplicate on AccessStep
benjie Dec 10, 2024
cf1a156
Faster digest for keys
benjie Dec 10, 2024
ba8a172
Avoid the need for regexp through string length
benjie Dec 10, 2024
b8e7e4f
Slightly shorter
benjie Dec 10, 2024
57e05a7
Fix unnecessary template literal
benjie Dec 10, 2024
0d5c5f1
Fix bug in object step
benjie Dec 10, 2024
cc909c4
Use traditional loop
benjie Dec 10, 2024
ee30542
Get rid of keysString
benjie Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/thick-mugs-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"postgraphile": patch
"@dataplan/pg": patch
"grafast": patch
---

Introduce step caching to reduce deduplication workload safely, thereby reducing
planning time for many larger queries.
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,48 @@ graph TD
__Value4["__Value[4∈0] ➊<br />ᐸrootValueᐳ"]:::plan
Constant10{{"Constant[10∈0] ➊<br />ᐸ'POST'ᐳ"}}:::plan
Constant11{{"Constant[11∈0] ➊<br />ᐸ2ᐳ"}}:::plan
Constant34{{"Constant[34∈0] ➊<br />ᐸ'My Relational Post'ᐳ"}}:::plan
Constant35{{"Constant[35∈0] ➊<br />ᐸ'Such a great post.'ᐳ"}}:::plan
Constant33{{"Constant[33∈0] ➊<br />ᐸ'My Relational Post'ᐳ"}}:::plan
Constant34{{"Constant[34∈0] ➊<br />ᐸ'Such a great post.'ᐳ"}}:::plan
PgInsertSingle17[["PgInsertSingle[17∈1] ➊<br />ᐸrelational_posts(id,title,note)ᐳ"]]:::sideeffectplan
PgClassExpression16{{"PgClassExpression[16∈1] ➊<br />ᐸ__relation...ems__.”id”ᐳ"}}:::plan
Object15 & PgClassExpression16 & Constant34 & Constant35 --> PgInsertSingle17
Object15 & PgClassExpression16 & Constant33 & Constant34 --> PgInsertSingle17
PgInsertSingle12[["PgInsertSingle[12∈1] ➊<br />ᐸrelational_items(type,author_id)ᐳ"]]:::sideeffectplan
Object15 & Constant10 & Constant11 --> PgInsertSingle12
PgInsertSingle12 --> PgClassExpression16
PgClassExpression21{{"PgClassExpression[21∈1] ➊<br />ᐸ__relational_posts__ᐳ"}}:::plan
PgInsertSingle17 --> PgClassExpression21
PgSelect24[["PgSelect[24∈2] ➊<br />ᐸrelational_postsᐳ"]]:::plan
PgSelect23[["PgSelect[23∈2] ➊<br />ᐸrelational_postsᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈2] ➊<br />ᐸ(__relatio...ts__).”id”ᐳ"}}:::plan
Object15 & PgClassExpression22 --> PgSelect24
Object15 & PgClassExpression22 --> PgSelect23
PgInsertSingle17 --> PgClassExpression22
First28{{"First[28∈2] ➊"}}:::plan
PgSelect24 --> First28
PgSelectSingle29{{"PgSelectSingle[29∈2] ➊<br />ᐸrelational_postsᐳ"}}:::plan
First28 --> PgSelectSingle29
PgClassExpression30{{"PgClassExpression[30∈3] ➊<br />ᐸ__relation...sts__.”id”ᐳ"}}:::plan
PgSelectSingle29 --> PgClassExpression30
PgClassExpression31{{"PgClassExpression[31∈3] ➊<br />ᐸ__relation...__.”title”ᐳ"}}:::plan
PgSelectSingle29 --> PgClassExpression31
PgClassExpression32{{"PgClassExpression[32∈3] ➊<br />ᐸ__relation...scription”ᐳ"}}:::plan
PgSelectSingle29 --> PgClassExpression32
PgClassExpression33{{"PgClassExpression[33∈3] ➊<br />ᐸ__relation...s__.”note”ᐳ"}}:::plan
PgSelectSingle29 --> PgClassExpression33
First27{{"First[27∈2] ➊"}}:::plan
PgSelect23 --> First27
PgSelectSingle28{{"PgSelectSingle[28∈2] ➊<br />ᐸrelational_postsᐳ"}}:::plan
First27 --> PgSelectSingle28
PgClassExpression29{{"PgClassExpression[29∈3] ➊<br />ᐸ__relation...sts__.”id”ᐳ"}}:::plan
PgSelectSingle28 --> PgClassExpression29
PgClassExpression30{{"PgClassExpression[30∈3] ➊<br />ᐸ__relation...__.”title”ᐳ"}}:::plan
PgSelectSingle28 --> PgClassExpression30
PgClassExpression31{{"PgClassExpression[31∈3] ➊<br />ᐸ__relation...scription”ᐳ"}}:::plan
PgSelectSingle28 --> PgClassExpression31
PgClassExpression32{{"PgClassExpression[32∈3] ➊<br />ᐸ__relation...s__.”note”ᐳ"}}:::plan
PgSelectSingle28 --> PgClassExpression32

%% define steps

subgraph "Buckets for mutations/basics/create-relational-post-default-description"
Bucket0("Bucket 0 (root)"):::bucket
classDef bucket0 stroke:#696969
class Bucket0,__Value2,__Value4,Constant10,Constant11,Access13,Access14,Object15,Constant34,Constant35 bucket0
Bucket1("Bucket 1 (mutationField)<br />Deps: 15, 10, 11, 34, 35<br /><br />1: PgInsertSingle[12]<br />2: PgClassExpression[16]<br />3: PgInsertSingle[17]<br />4: <br />ᐳ: PgClassExpression[21]"):::bucket
class Bucket0,__Value2,__Value4,Constant10,Constant11,Access13,Access14,Object15,Constant33,Constant34 bucket0
Bucket1("Bucket 1 (mutationField)<br />Deps: 15, 10, 11, 33, 34<br /><br />1: PgInsertSingle[12]<br />2: PgClassExpression[16]<br />3: PgInsertSingle[17]<br />4: <br />ᐳ: PgClassExpression[21]"):::bucket
classDef bucket1 stroke:#00bfff
class Bucket1,PgInsertSingle12,PgClassExpression16,PgInsertSingle17,PgClassExpression21 bucket1
Bucket2("Bucket 2 (nullableBoundary)<br />Deps: 17, 15, 21<br /><br />ROOT PgClassExpression{1}ᐸ__relational_posts__ᐳ[21]<br />1: <br />ᐳ: PgClassExpression[22]<br />2: PgSelect[24]<br />ᐳ: First[28], PgSelectSingle[29]"):::bucket
Bucket2("Bucket 2 (nullableBoundary)<br />Deps: 17, 15, 21<br /><br />ROOT PgClassExpression{1}ᐸ__relational_posts__ᐳ[21]<br />1: <br />ᐳ: PgClassExpression[22]<br />2: PgSelect[23]<br />ᐳ: First[27], PgSelectSingle[28]"):::bucket
classDef bucket2 stroke:#7f007f
class Bucket2,PgClassExpression22,PgSelect24,First28,PgSelectSingle29 bucket2
Bucket3("Bucket 3 (nullableBoundary)<br />Deps: 29<br /><br />ROOT PgSelectSingle{2}ᐸrelational_postsᐳ[29]"):::bucket
class Bucket2,PgClassExpression22,PgSelect23,First27,PgSelectSingle28 bucket2
Bucket3("Bucket 3 (nullableBoundary)<br />Deps: 28<br /><br />ROOT PgSelectSingle{2}ᐸrelational_postsᐳ[28]"):::bucket
classDef bucket3 stroke:#ffa500
class Bucket3,PgClassExpression30,PgClassExpression31,PgClassExpression32,PgClassExpression33 bucket3
class Bucket3,PgClassExpression29,PgClassExpression30,PgClassExpression31,PgClassExpression32 bucket3
Bucket0 --> Bucket1
Bucket1 --> Bucket2
Bucket2 --> Bucket3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,48 @@ graph TD
__Value4["__Value[4∈0] ➊<br />ᐸrootValueᐳ"]:::plan
Constant10{{"Constant[10∈0] ➊<br />ᐸ'POST'ᐳ"}}:::plan
Constant11{{"Constant[11∈0] ➊<br />ᐸ2ᐳ"}}:::plan
Constant34{{"Constant[34∈0] ➊<br />ᐸ'My Relational Post'ᐳ"}}:::plan
Constant35{{"Constant[35∈0] ➊<br />ᐸ'Such a great post.'ᐳ"}}:::plan
Constant33{{"Constant[33∈0] ➊<br />ᐸ'My Relational Post'ᐳ"}}:::plan
Constant34{{"Constant[34∈0] ➊<br />ᐸ'Such a great post.'ᐳ"}}:::plan
PgInsertSingle17[["PgInsertSingle[17∈1] ➊<br />ᐸrelational_posts(id,title,note)ᐳ"]]:::sideeffectplan
PgClassExpression16{{"PgClassExpression[16∈1] ➊<br />ᐸ__relation...ems__.”id”ᐳ"}}:::plan
Object15 & PgClassExpression16 & Constant34 & Constant35 --> PgInsertSingle17
Object15 & PgClassExpression16 & Constant33 & Constant34 --> PgInsertSingle17
PgInsertSingle12[["PgInsertSingle[12∈1] ➊<br />ᐸrelational_items(type,author_id)ᐳ"]]:::sideeffectplan
Object15 & Constant10 & Constant11 --> PgInsertSingle12
PgInsertSingle12 --> PgClassExpression16
PgClassExpression21{{"PgClassExpression[21∈1] ➊<br />ᐸ__relational_posts__ᐳ"}}:::plan
PgInsertSingle17 --> PgClassExpression21
PgSelect24[["PgSelect[24∈2] ➊<br />ᐸrelational_postsᐳ"]]:::plan
PgSelect23[["PgSelect[23∈2] ➊<br />ᐸrelational_postsᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈2] ➊<br />ᐸ(__relatio...ts__).”id”ᐳ"}}:::plan
Object15 & PgClassExpression22 --> PgSelect24
Object15 & PgClassExpression22 --> PgSelect23
PgInsertSingle17 --> PgClassExpression22
First28{{"First[28∈2] ➊"}}:::plan
PgSelect24 --> First28
PgSelectSingle29{{"PgSelectSingle[29∈2] ➊<br />ᐸrelational_postsᐳ"}}:::plan
First28 --> PgSelectSingle29
PgClassExpression30{{"PgClassExpression[30∈3] ➊<br />ᐸ__relation...sts__.”id”ᐳ"}}:::plan
PgSelectSingle29 --> PgClassExpression30
PgClassExpression31{{"PgClassExpression[31∈3] ➊<br />ᐸ__relation...__.”title”ᐳ"}}:::plan
PgSelectSingle29 --> PgClassExpression31
PgClassExpression32{{"PgClassExpression[32∈3] ➊<br />ᐸ__relation...scription”ᐳ"}}:::plan
PgSelectSingle29 --> PgClassExpression32
PgClassExpression33{{"PgClassExpression[33∈3] ➊<br />ᐸ__relation...s__.”note”ᐳ"}}:::plan
PgSelectSingle29 --> PgClassExpression33
First27{{"First[27∈2] ➊"}}:::plan
PgSelect23 --> First27
PgSelectSingle28{{"PgSelectSingle[28∈2] ➊<br />ᐸrelational_postsᐳ"}}:::plan
First27 --> PgSelectSingle28
PgClassExpression29{{"PgClassExpression[29∈3] ➊<br />ᐸ__relation...sts__.”id”ᐳ"}}:::plan
PgSelectSingle28 --> PgClassExpression29
PgClassExpression30{{"PgClassExpression[30∈3] ➊<br />ᐸ__relation...__.”title”ᐳ"}}:::plan
PgSelectSingle28 --> PgClassExpression30
PgClassExpression31{{"PgClassExpression[31∈3] ➊<br />ᐸ__relation...scription”ᐳ"}}:::plan
PgSelectSingle28 --> PgClassExpression31
PgClassExpression32{{"PgClassExpression[32∈3] ➊<br />ᐸ__relation...s__.”note”ᐳ"}}:::plan
PgSelectSingle28 --> PgClassExpression32

%% define steps

subgraph "Buckets for mutations/basics/create-relational-post-default-description"
Bucket0("Bucket 0 (root)"):::bucket
classDef bucket0 stroke:#696969
class Bucket0,__Value2,__Value4,Constant10,Constant11,Access13,Access14,Object15,Constant34,Constant35 bucket0
Bucket1("Bucket 1 (mutationField)<br />Deps: 15, 10, 11, 34, 35<br /><br />1: PgInsertSingle[12]<br />2: PgClassExpression[16]<br />3: PgInsertSingle[17]<br />4: <br />ᐳ: PgClassExpression[21]"):::bucket
class Bucket0,__Value2,__Value4,Constant10,Constant11,Access13,Access14,Object15,Constant33,Constant34 bucket0
Bucket1("Bucket 1 (mutationField)<br />Deps: 15, 10, 11, 33, 34<br /><br />1: PgInsertSingle[12]<br />2: PgClassExpression[16]<br />3: PgInsertSingle[17]<br />4: <br />ᐳ: PgClassExpression[21]"):::bucket
classDef bucket1 stroke:#00bfff
class Bucket1,PgInsertSingle12,PgClassExpression16,PgInsertSingle17,PgClassExpression21 bucket1
Bucket2("Bucket 2 (nullableBoundary)<br />Deps: 17, 15, 21<br /><br />ROOT PgClassExpression{1}ᐸ__relational_posts__ᐳ[21]<br />1: <br />ᐳ: PgClassExpression[22]<br />2: PgSelect[24]<br />ᐳ: First[28], PgSelectSingle[29]"):::bucket
Bucket2("Bucket 2 (nullableBoundary)<br />Deps: 17, 15, 21<br /><br />ROOT PgClassExpression{1}ᐸ__relational_posts__ᐳ[21]<br />1: <br />ᐳ: PgClassExpression[22]<br />2: PgSelect[23]<br />ᐳ: First[27], PgSelectSingle[28]"):::bucket
classDef bucket2 stroke:#7f007f
class Bucket2,PgClassExpression22,PgSelect24,First28,PgSelectSingle29 bucket2
Bucket3("Bucket 3 (nullableBoundary)<br />Deps: 29<br /><br />ROOT PgSelectSingle{2}ᐸrelational_postsᐳ[29]"):::bucket
class Bucket2,PgClassExpression22,PgSelect23,First27,PgSelectSingle28 bucket2
Bucket3("Bucket 3 (nullableBoundary)<br />Deps: 28<br /><br />ROOT PgSelectSingle{2}ᐸrelational_postsᐳ[28]"):::bucket
classDef bucket3 stroke:#ffa500
class Bucket3,PgClassExpression30,PgClassExpression31,PgClassExpression32,PgClassExpression33 bucket3
class Bucket3,PgClassExpression29,PgClassExpression30,PgClassExpression31,PgClassExpression32 bucket3
Bucket0 --> Bucket1
Bucket1 --> Bucket2
Bucket2 --> Bucket3
Expand Down
Loading
Loading