%%{init: {'themeVariables': { 'fontSize': '12px'}}}%%
graph TD
    classDef path fill:#eee,stroke:#000,color:#000
    classDef plan fill:#fff,stroke-width:1px,color:#000
    classDef itemplan fill:#fff,stroke-width:2px,color:#000
    classDef unbatchedplan fill:#dff,stroke-width:1px,color:#000
    classDef sideeffectplan fill:#fcc,stroke-width:2px,color:#000
    classDef bucket fill:#f6f6f6,color:#000,stroke-width:2px,text-align:left


    %% plan dependencies
    PgSelect7[["PgSelect[7∈0] ➊<br />ᐸunion_itemsᐳ"]]:::plan
    Object10{{"Object[10∈0] ➊<br />ᐸ{pgSettings,withPgClient}ᐳ"}}:::plan
    Constant130{{"Constant[130∈0] ➊<br />ᐸ987654321ᐳ"}}:::plan
    Object10 & Constant130 --> PgSelect7
    Access8{{"Access[8∈0] ➊<br />ᐸ2.pgSettingsᐳ"}}:::plan
    Access9{{"Access[9∈0] ➊<br />ᐸ2.withPgClientᐳ"}}:::plan
    Access8 & Access9 --> Object10
    PgPolymorphic14{{"PgPolymorphic[14∈0] ➊"}}:::plan
    PgSelectSingle12{{"PgSelectSingle[12∈0] ➊<br />ᐸunion_itemsᐳ"}}:::plan
    PgClassExpression13{{"PgClassExpression[13∈0] ➊<br />ᐸ__union_items__.”type”ᐳ"}}:::plan
    PgSelectSingle12 & PgClassExpression13 --> PgPolymorphic14
    PgUnionAll65[["PgUnionAll[65∈0] ➊"]]:::plan
    Object10 & Constant130 --> PgUnionAll65
    __Value2["__Value[2∈0] ➊<br />ᐸcontextᐳ"]:::plan
    __Value2 --> Access8
    __Value2 --> Access9
    First11{{"First[11∈0] ➊"}}:::plan
    PgSelect7 --> First11
    First11 --> PgSelectSingle12
    PgSelectSingle12 --> PgClassExpression13
    PgClassExpression15{{"PgClassExpression[15∈0] ➊<br />ᐸ__union_items__.”id”ᐳ"}}:::plan
    PgSelectSingle12 --> PgClassExpression15
    First69{{"First[69∈0] ➊"}}:::plan
    PgUnionAll65 --> First69
    PgUnionAllSingle70["PgUnionAllSingle[70∈0] ➊"]:::plan
    First69 --> PgUnionAllSingle70
    Access71{{"Access[71∈0] ➊<br />ᐸ70.1ᐳ"}}:::plan
    PgUnionAllSingle70 --> Access71
    __Value4["__Value[4∈0] ➊<br />ᐸrootValueᐳ"]:::plan
    PgSelect16[["PgSelect[16∈1] ➊<br />ᐸunion_topicsᐳ<br />ᐳUnionTopic"]]:::plan
    Object10 & PgClassExpression15 --> PgSelect16
    PgSelect25[["PgSelect[25∈1] ➊<br />ᐸunion_postsᐳ<br />ᐳUnionPost"]]:::plan
    Object10 & PgClassExpression15 --> PgSelect25
    PgSelect36[["PgSelect[36∈1] ➊<br />ᐸunion_dividersᐳ<br />ᐳUnionDivider"]]:::plan
    Object10 & PgClassExpression15 --> PgSelect36
    PgSelect46[["PgSelect[46∈1] ➊<br />ᐸunion_checklistsᐳ<br />ᐳUnionChecklist"]]:::plan
    Object10 & PgClassExpression15 --> PgSelect46
    PgSelect55[["PgSelect[55∈1] ➊<br />ᐸunion_checklist_itemsᐳ<br />ᐳUnionChecklistItem"]]:::plan
    Object10 & PgClassExpression15 --> PgSelect55
    First20{{"First[20∈1] ➊"}}:::plan
    PgSelect16 --> First20
    PgSelectSingle21{{"PgSelectSingle[21∈1] ➊<br />ᐸunion_topicsᐳ"}}:::plan
    First20 --> PgSelectSingle21
    PgClassExpression22{{"PgClassExpression[22∈1] ➊<br />ᐸ__union_topics__.”id”ᐳ"}}:::plan
    PgSelectSingle21 --> PgClassExpression22
    PgClassExpression23{{"PgClassExpression[23∈1] ➊<br />ᐸ__union_to...__.”title”ᐳ"}}:::plan
    PgSelectSingle21 --> PgClassExpression23
    First29{{"First[29∈1] ➊"}}:::plan
    PgSelect25 --> First29
    PgSelectSingle30{{"PgSelectSingle[30∈1] ➊<br />ᐸunion_postsᐳ"}}:::plan
    First29 --> PgSelectSingle30
    PgClassExpression31{{"PgClassExpression[31∈1] ➊<br />ᐸ__union_posts__.”id”ᐳ"}}:::plan
    PgSelectSingle30 --> PgClassExpression31
    PgClassExpression32{{"PgClassExpression[32∈1] ➊<br />ᐸ__union_posts__.”title”ᐳ"}}:::plan
    PgSelectSingle30 --> PgClassExpression32
    PgClassExpression33{{"PgClassExpression[33∈1] ➊<br />ᐸ__union_po...scription”ᐳ"}}:::plan
    PgSelectSingle30 --> PgClassExpression33
    PgClassExpression34{{"PgClassExpression[34∈1] ➊<br />ᐸ__union_posts__.”note”ᐳ"}}:::plan
    PgSelectSingle30 --> PgClassExpression34
    First40{{"First[40∈1] ➊"}}:::plan
    PgSelect36 --> First40
    PgSelectSingle41{{"PgSelectSingle[41∈1] ➊<br />ᐸunion_dividersᐳ"}}:::plan
    First40 --> PgSelectSingle41
    PgClassExpression42{{"PgClassExpression[42∈1] ➊<br />ᐸ__union_dividers__.”id”ᐳ"}}:::plan
    PgSelectSingle41 --> PgClassExpression42
    PgClassExpression43{{"PgClassExpression[43∈1] ➊<br />ᐸ__union_di...__.”title”ᐳ"}}:::plan
    PgSelectSingle41 --> PgClassExpression43
    PgClassExpression44{{"PgClassExpression[44∈1] ➊<br />ᐸ__union_di...__.”color”ᐳ"}}:::plan
    PgSelectSingle41 --> PgClassExpression44
    First50{{"First[50∈1] ➊"}}:::plan
    PgSelect46 --> First50
    PgSelectSingle51{{"PgSelectSingle[51∈1] ➊<br />ᐸunion_checklistsᐳ"}}:::plan
    First50 --> PgSelectSingle51
    PgClassExpression52{{"PgClassExpression[52∈1] ➊<br />ᐸ__union_ch...sts__.”id”ᐳ"}}:::plan
    PgSelectSingle51 --> PgClassExpression52
    PgClassExpression53{{"PgClassExpression[53∈1] ➊<br />ᐸ__union_ch...__.”title”ᐳ"}}:::plan
    PgSelectSingle51 --> PgClassExpression53
    First59{{"First[59∈1] ➊"}}:::plan
    PgSelect55 --> First59
    PgSelectSingle60{{"PgSelectSingle[60∈1] ➊<br />ᐸunion_checklist_itemsᐳ"}}:::plan
    First59 --> PgSelectSingle60
    PgClassExpression61{{"PgClassExpression[61∈1] ➊<br />ᐸ__union_ch...ems__.”id”ᐳ"}}:::plan
    PgSelectSingle60 --> PgClassExpression61
    PgClassExpression62{{"PgClassExpression[62∈1] ➊<br />ᐸ__union_ch...scription”ᐳ"}}:::plan
    PgSelectSingle60 --> PgClassExpression62
    PgClassExpression63{{"PgClassExpression[63∈1] ➊<br />ᐸ__union_ch...s__.”note”ᐳ"}}:::plan
    PgSelectSingle60 --> PgClassExpression63
    PgSelect74[["PgSelect[74∈2] ➊<br />ᐸunion_topicsᐳ<br />ᐳUnionTopic"]]:::plan
    Access73{{"Access[73∈2] ➊<br />ᐸ72.0ᐳ"}}:::plan
    Object10 & Access73 --> PgSelect74
    PgSelect85[["PgSelect[85∈2] ➊<br />ᐸunion_postsᐳ<br />ᐳUnionPost"]]:::plan
    Access84{{"Access[84∈2] ➊<br />ᐸ83.0ᐳ"}}:::plan
    Object10 & Access84 --> PgSelect85
    PgSelect98[["PgSelect[98∈2] ➊<br />ᐸunion_dividersᐳ<br />ᐳUnionDivider"]]:::plan
    Access97{{"Access[97∈2] ➊<br />ᐸ96.0ᐳ"}}:::plan
    Object10 & Access97 --> PgSelect98
    PgSelect110[["PgSelect[110∈2] ➊<br />ᐸunion_checklistsᐳ<br />ᐳUnionChecklist"]]:::plan
    Access109{{"Access[109∈2] ➊<br />ᐸ108.0ᐳ"}}:::plan
    Object10 & Access109 --> PgSelect110
    PgSelect121[["PgSelect[121∈2] ➊<br />ᐸunion_checklist_itemsᐳ<br />ᐳUnionChecklistItem"]]:::plan
    Access120{{"Access[120∈2] ➊<br />ᐸ119.0ᐳ"}}:::plan
    Object10 & Access120 --> PgSelect121
    JSONParse72[["JSONParse[72∈2] ➊<br />ᐸ71ᐳ<br />ᐳUnionTopic"]]:::plan
    Access71 --> JSONParse72
    JSONParse72 --> Access73
    First78{{"First[78∈2] ➊"}}:::plan
    PgSelect74 --> First78
    PgSelectSingle79{{"PgSelectSingle[79∈2] ➊<br />ᐸunion_topicsᐳ"}}:::plan
    First78 --> PgSelectSingle79
    PgClassExpression80{{"PgClassExpression[80∈2] ➊<br />ᐸ__union_topics__.”id”ᐳ"}}:::plan
    PgSelectSingle79 --> PgClassExpression80
    PgClassExpression81{{"PgClassExpression[81∈2] ➊<br />ᐸ__union_to...__.”title”ᐳ"}}:::plan
    PgSelectSingle79 --> PgClassExpression81
    JSONParse83[["JSONParse[83∈2] ➊<br />ᐸ71ᐳ<br />ᐳUnionPost"]]:::plan
    Access71 --> JSONParse83
    JSONParse83 --> Access84
    First89{{"First[89∈2] ➊"}}:::plan
    PgSelect85 --> First89
    PgSelectSingle90{{"PgSelectSingle[90∈2] ➊<br />ᐸunion_postsᐳ"}}:::plan
    First89 --> PgSelectSingle90
    PgClassExpression91{{"PgClassExpression[91∈2] ➊<br />ᐸ__union_posts__.”id”ᐳ"}}:::plan
    PgSelectSingle90 --> PgClassExpression91
    PgClassExpression92{{"PgClassExpression[92∈2] ➊<br />ᐸ__union_posts__.”title”ᐳ"}}:::plan
    PgSelectSingle90 --> PgClassExpression92
    PgClassExpression93{{"PgClassExpression[93∈2] ➊<br />ᐸ__union_po...scription”ᐳ"}}:::plan
    PgSelectSingle90 --> PgClassExpression93
    PgClassExpression94{{"PgClassExpression[94∈2] ➊<br />ᐸ__union_posts__.”note”ᐳ"}}:::plan
    PgSelectSingle90 --> PgClassExpression94
    JSONParse96[["JSONParse[96∈2] ➊<br />ᐸ71ᐳ<br />ᐳUnionDivider"]]:::plan
    Access71 --> JSONParse96
    JSONParse96 --> Access97
    First102{{"First[102∈2] ➊"}}:::plan
    PgSelect98 --> First102
    PgSelectSingle103{{"PgSelectSingle[103∈2] ➊<br />ᐸunion_dividersᐳ"}}:::plan
    First102 --> PgSelectSingle103
    PgClassExpression104{{"PgClassExpression[104∈2] ➊<br />ᐸ__union_dividers__.”id”ᐳ"}}:::plan
    PgSelectSingle103 --> PgClassExpression104
    PgClassExpression105{{"PgClassExpression[105∈2] ➊<br />ᐸ__union_di...__.”title”ᐳ"}}:::plan
    PgSelectSingle103 --> PgClassExpression105
    PgClassExpression106{{"PgClassExpression[106∈2] ➊<br />ᐸ__union_di...__.”color”ᐳ"}}:::plan
    PgSelectSingle103 --> PgClassExpression106
    JSONParse108[["JSONParse[108∈2] ➊<br />ᐸ71ᐳ<br />ᐳUnionChecklist"]]:::plan
    Access71 --> JSONParse108
    JSONParse108 --> Access109
    First114{{"First[114∈2] ➊"}}:::plan
    PgSelect110 --> First114
    PgSelectSingle115{{"PgSelectSingle[115∈2] ➊<br />ᐸunion_checklistsᐳ"}}:::plan
    First114 --> PgSelectSingle115
    PgClassExpression116{{"PgClassExpression[116∈2] ➊<br />ᐸ__union_ch...sts__.”id”ᐳ"}}:::plan
    PgSelectSingle115 --> PgClassExpression116
    PgClassExpression117{{"PgClassExpression[117∈2] ➊<br />ᐸ__union_ch...__.”title”ᐳ"}}:::plan
    PgSelectSingle115 --> PgClassExpression117
    JSONParse119[["JSONParse[119∈2] ➊<br />ᐸ71ᐳ<br />ᐳUnionChecklistItem"]]:::plan
    Access71 --> JSONParse119
    JSONParse119 --> Access120
    First125{{"First[125∈2] ➊"}}:::plan
    PgSelect121 --> First125
    PgSelectSingle126{{"PgSelectSingle[126∈2] ➊<br />ᐸunion_checklist_itemsᐳ"}}:::plan
    First125 --> PgSelectSingle126
    PgClassExpression127{{"PgClassExpression[127∈2] ➊<br />ᐸ__union_ch...ems__.”id”ᐳ"}}:::plan
    PgSelectSingle126 --> PgClassExpression127
    PgClassExpression128{{"PgClassExpression[128∈2] ➊<br />ᐸ__union_ch...scription”ᐳ"}}:::plan
    PgSelectSingle126 --> PgClassExpression128
    PgClassExpression129{{"PgClassExpression[129∈2] ➊<br />ᐸ__union_ch...s__.”note”ᐳ"}}:::plan
    PgSelectSingle126 --> PgClassExpression129

    %% define steps

    subgraph "Buckets for queries/unions-table/by-id-987654321"
    Bucket0("Bucket 0 (root)<br /><br />1: <br />ᐳ: 8, 9, 130, 10<br />2: PgSelect[7], PgUnionAll[65]<br />ᐳ: 11, 12, 13, 14, 15, 69<br />3: PgUnionAllSingle[70]<br />ᐳ: Access[71]"):::bucket
    classDef bucket0 stroke:#696969
    class Bucket0,__Value2,__Value4,PgSelect7,Access8,Access9,Object10,First11,PgSelectSingle12,PgClassExpression13,PgPolymorphic14,PgClassExpression15,PgUnionAll65,First69,PgUnionAllSingle70,Access71,Constant130 bucket0
    Bucket1("Bucket 1 (polymorphic)<br />UnionTopic,UnionPost,UnionDivider,UnionChecklist,UnionChecklistItem<br />Deps: 10, 15, 14<br />ᐳUnionTopic<br />ᐳUnionPost<br />ᐳUnionDivider<br />ᐳUnionChecklist<br />ᐳUnionChecklistItem"):::bucket
    classDef bucket1 stroke:#00bfff
    class Bucket1,PgSelect16,First20,PgSelectSingle21,PgClassExpression22,PgClassExpression23,PgSelect25,First29,PgSelectSingle30,PgClassExpression31,PgClassExpression32,PgClassExpression33,PgClassExpression34,PgSelect36,First40,PgSelectSingle41,PgClassExpression42,PgClassExpression43,PgClassExpression44,PgSelect46,First50,PgSelectSingle51,PgClassExpression52,PgClassExpression53,PgSelect55,First59,PgSelectSingle60,PgClassExpression61,PgClassExpression62,PgClassExpression63 bucket1
    Bucket2("Bucket 2 (polymorphic)<br />UnionTopic,UnionPost,UnionDivider,UnionChecklist,UnionChecklistItem<br />Deps: 71, 10, 70<br />ᐳUnionTopic<br />ᐳUnionPost<br />ᐳUnionDivider<br />ᐳUnionChecklist<br />ᐳUnionChecklistItem<br /><br />1: 72, 83, 96, 108, 119<br />ᐳ: 73, 84, 97, 109, 120<br />2: 74, 85, 98, 110, 121<br />ᐳ: 78, 79, 80, 81, 89, 90, 91, 92, 93, 94, 102, 103, 104, 105, 106, 114, 115, 116, 117, 125, 126, 127, 128, 129"):::bucket
    classDef bucket2 stroke:#7f007f
    class Bucket2,JSONParse72,Access73,PgSelect74,First78,PgSelectSingle79,PgClassExpression80,PgClassExpression81,JSONParse83,Access84,PgSelect85,First89,PgSelectSingle90,PgClassExpression91,PgClassExpression92,PgClassExpression93,PgClassExpression94,JSONParse96,Access97,PgSelect98,First102,PgSelectSingle103,PgClassExpression104,PgClassExpression105,PgClassExpression106,JSONParse108,Access109,PgSelect110,First114,PgSelectSingle115,PgClassExpression116,PgClassExpression117,JSONParse119,Access120,PgSelect121,First125,PgSelectSingle126,PgClassExpression127,PgClassExpression128,PgClassExpression129 bucket2
    Bucket0 --> Bucket1 & Bucket2
    end
