%%{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
    Constant150{{"Constant[150∈0] ➊<br />ᐸ1ᐳ"}}:::plan
    Lambda60{{"Lambda[60∈0] ➊<br />ᐸcalculateShouldReverseOrderᐳ"}}:::plan
    Access64{{"Access[64∈0] ➊<br />ᐸ63.0ᐳ"}}:::plan
    Lambda144{{"Lambda[144∈0] ➊<br />ᐸcalculateOrderBySQLᐳ"}}:::plan
    Lambda149{{"Lambda[149∈0] ➊<br />ᐸcalculateOrderBySQLᐳ"}}:::plan
    Object10 & Constant150 & Lambda60 & Access64 & Lambda144 & Lambda149 --> PgSelect7
    Object68{{"Object[68∈0] ➊<br />ᐸ{reverse,orders,alias,codec}ᐳ"}}:::plan
    Constant65{{"Constant[65∈0] ➊<br />ᐸ[]ᐳ"}}:::plan
    Constant66{{"Constant[66∈0] ➊<br />ᐸsql.identifier(”union_topics”)ᐳ"}}:::plan
    Constant67{{"Constant[67∈0] ➊<br />ᐸRecordCodec(union_topics)ᐳ"}}:::plan
    Lambda60 & Constant65 & Constant66 & Constant67 --> Object68
    Object83{{"Object[83∈0] ➊<br />ᐸ{reverse,orders,alias,codec}ᐳ"}}:::plan
    Constant80{{"Constant[80∈0] ➊<br />ᐸ[]ᐳ"}}:::plan
    Constant81{{"Constant[81∈0] ➊<br />ᐸsql.identifier(”union_posts”)ᐳ"}}:::plan
    Constant82{{"Constant[82∈0] ➊<br />ᐸRecordCodec(union_posts)ᐳ"}}:::plan
    Lambda60 & Constant80 & Constant81 & Constant82 --> Object83
    Object98{{"Object[98∈0] ➊<br />ᐸ{reverse,orders,alias,codec}ᐳ"}}:::plan
    Constant95{{"Constant[95∈0] ➊<br />ᐸ[]ᐳ"}}:::plan
    Constant96{{"Constant[96∈0] ➊<br />ᐸsql.identifier(”union_dividers”)ᐳ"}}:::plan
    Constant97{{"Constant[97∈0] ➊<br />ᐸRecordCodec(union_dividers)ᐳ"}}:::plan
    Lambda60 & Constant95 & Constant96 & Constant97 --> Object98
    Object113{{"Object[113∈0] ➊<br />ᐸ{reverse,orders,alias,codec}ᐳ"}}:::plan
    Constant110{{"Constant[110∈0] ➊<br />ᐸ[]ᐳ"}}:::plan
    Constant111{{"Constant[111∈0] ➊<br />ᐸsql.identifier(”union_checklists”)ᐳ"}}:::plan
    Constant112{{"Constant[112∈0] ➊<br />ᐸRecordCodec(union_checklists)ᐳ"}}:::plan
    Lambda60 & Constant110 & Constant111 & Constant112 --> Object113
    Object128{{"Object[128∈0] ➊<br />ᐸ{reverse,orders,alias,codec}ᐳ"}}:::plan
    Constant125{{"Constant[125∈0] ➊<br />ᐸ[]ᐳ"}}:::plan
    Constant126{{"Constant[126∈0] ➊<br />ᐸsql.identifier(”union_checklist_items”)ᐳ"}}:::plan
    Constant127{{"Constant[127∈0] ➊<br />ᐸRecordCodec(union_checklist_items)ᐳ"}}:::plan
    Lambda60 & Constant125 & Constant126 & Constant127 --> Object128
    Object143{{"Object[143∈0] ➊<br />ᐸ{reverse,orders,alias,codec}ᐳ"}}:::plan
    Constant140{{"Constant[140∈0] ➊<br />ᐸ[]ᐳ"}}:::plan
    Constant141{{"Constant[141∈0] ➊<br />ᐸsql.identifier(”union_items”)ᐳ"}}:::plan
    Constant142{{"Constant[142∈0] ➊<br />ᐸRecordCodec(union_items)ᐳ"}}:::plan
    Lambda60 & Constant140 & Constant141 & Constant142 --> Object143
    Access8{{"Access[8∈0] ➊<br />ᐸ2.pgSettingsᐳ"}}:::plan
    Access9{{"Access[9∈0] ➊<br />ᐸ2.withPgClientᐳ"}}:::plan
    Access8 & Access9 --> Object10
    PgPolymorphic15{{"PgPolymorphic[15∈0] ➊"}}:::plan
    PgSelectSingle13{{"PgSelectSingle[13∈0] ➊<br />ᐸunion_itemsᐳ"}}:::plan
    PgClassExpression14{{"PgClassExpression[14∈0] ➊<br />ᐸ__union_items__.”type”ᐳ"}}:::plan
    PgSelectSingle13 & PgClassExpression14 --> PgPolymorphic15
    __Value2["__Value[2∈0] ➊<br />ᐸcontextᐳ"]:::plan
    __Value2 --> Access8
    __Value2 --> Access9
    First11{{"First[11∈0] ➊"}}:::plan
    PgSelectRows12[["PgSelectRows[12∈0] ➊"]]:::plan
    PgSelectRows12 --> First11
    PgSelect7 --> PgSelectRows12
    First11 --> PgSelectSingle13
    PgSelectSingle13 --> PgClassExpression14
    Constant151{{"Constant[151∈0] ➊<br />ᐸ§{ first: null, last: null, cursorLower: null, cursorUpper: ᐳ"}}:::plan
    Constant151 --> Lambda60
    Lambda63{{"Lambda[63∈0] ➊<br />ᐸcalculateLimitAndOffsetSQLᐳ"}}:::plan
    Constant152{{"Constant[152∈0] ➊<br />ᐸ§{ first: null, last: null, cursorLower: null, cursorUpper: ᐳ"}}:::plan
    Constant152 --> Lambda63
    Lambda63 --> Access64
    Lambda69{{"Lambda[69∈0] ➊<br />ᐸcalculateOrderBySQLᐳ"}}:::plan
    Object68 --> Lambda69
    Lambda74{{"Lambda[74∈0] ➊<br />ᐸcalculateOrderBySQLᐳ"}}:::plan
    Constant153{{"Constant[153∈0] ➊<br />ᐸ§{ reverse: false, orders: [], alias: sql.identifier(”union_ᐳ"}}:::plan
    Constant153 --> Lambda74
    Lambda84{{"Lambda[84∈0] ➊<br />ᐸcalculateOrderBySQLᐳ"}}:::plan
    Object83 --> Lambda84
    Lambda89{{"Lambda[89∈0] ➊<br />ᐸcalculateOrderBySQLᐳ"}}:::plan
    Constant154{{"Constant[154∈0] ➊<br />ᐸ§{ reverse: false, orders: [], alias: sql.identifier(”union_ᐳ"}}:::plan
    Constant154 --> Lambda89
    Lambda99{{"Lambda[99∈0] ➊<br />ᐸcalculateOrderBySQLᐳ"}}:::plan
    Object98 --> Lambda99
    Lambda104{{"Lambda[104∈0] ➊<br />ᐸcalculateOrderBySQLᐳ"}}:::plan
    Constant155{{"Constant[155∈0] ➊<br />ᐸ§{ reverse: false, orders: [], alias: sql.identifier(”union_ᐳ"}}:::plan
    Constant155 --> Lambda104
    Lambda114{{"Lambda[114∈0] ➊<br />ᐸcalculateOrderBySQLᐳ"}}:::plan
    Object113 --> Lambda114
    Lambda119{{"Lambda[119∈0] ➊<br />ᐸcalculateOrderBySQLᐳ"}}:::plan
    Constant156{{"Constant[156∈0] ➊<br />ᐸ§{ reverse: false, orders: [], alias: sql.identifier(”union_ᐳ"}}:::plan
    Constant156 --> Lambda119
    Lambda129{{"Lambda[129∈0] ➊<br />ᐸcalculateOrderBySQLᐳ"}}:::plan
    Object128 --> Lambda129
    Lambda134{{"Lambda[134∈0] ➊<br />ᐸcalculateOrderBySQLᐳ"}}:::plan
    Constant157{{"Constant[157∈0] ➊<br />ᐸ§{ reverse: false, orders: [], alias: sql.identifier(”union_ᐳ"}}:::plan
    Constant157 --> Lambda134
    Object143 --> Lambda144
    Constant158{{"Constant[158∈0] ➊<br />ᐸ§{ reverse: false, orders: [], alias: sql.identifier(”union_ᐳ"}}:::plan
    Constant158 --> Lambda149
    __Value4["__Value[4∈0] ➊<br />ᐸrootValueᐳ"]:::plan
    PgSelect17[["PgSelect[17∈1] ➊<br />ᐸunion_topicsᐳ<br />ᐳUnionTopic"]]:::plan
    PgClassExpression16{{"PgClassExpression[16∈1] ➊<br />ᐸ__union_items__.”id”ᐳ<br />ᐳUnionTopic"}}:::plan
    Object10 & PgClassExpression16 & Lambda60 & Access64 & Lambda69 & Lambda74 --> PgSelect17
    PgSelect26[["PgSelect[26∈1] ➊<br />ᐸunion_postsᐳ<br />ᐳUnionPost"]]:::plan
    Object10 & PgClassExpression16 & Lambda60 & Access64 & Lambda84 & Lambda89 --> PgSelect26
    PgSelect35[["PgSelect[35∈1] ➊<br />ᐸunion_dividersᐳ<br />ᐳUnionDivider"]]:::plan
    Object10 & PgClassExpression16 & Lambda60 & Access64 & Lambda99 & Lambda104 --> PgSelect35
    PgSelect43[["PgSelect[43∈1] ➊<br />ᐸunion_checklistsᐳ<br />ᐳUnionChecklist"]]:::plan
    Object10 & PgClassExpression16 & Lambda60 & Access64 & Lambda114 & Lambda119 --> PgSelect43
    PgSelect50[["PgSelect[50∈1] ➊<br />ᐸunion_checklist_itemsᐳ<br />ᐳUnionChecklistItem"]]:::plan
    Object10 & PgClassExpression16 & Lambda60 & Access64 & Lambda129 & Lambda134 --> PgSelect50
    PgSelectSingle13 --> PgClassExpression16
    First21{{"First[21∈1] ➊"}}:::plan
    PgSelectRows22[["PgSelectRows[22∈1] ➊"]]:::plan
    PgSelectRows22 --> First21
    PgSelect17 --> PgSelectRows22
    PgSelectSingle23{{"PgSelectSingle[23∈1] ➊<br />ᐸunion_topicsᐳ"}}:::plan
    First21 --> PgSelectSingle23
    PgClassExpression24{{"PgClassExpression[24∈1] ➊<br />ᐸ__union_topics__.”id”ᐳ"}}:::plan
    PgSelectSingle23 --> PgClassExpression24
    PgClassExpression25{{"PgClassExpression[25∈1] ➊<br />ᐸ__union_to...__.”title”ᐳ"}}:::plan
    PgSelectSingle23 --> PgClassExpression25
    First28{{"First[28∈1] ➊"}}:::plan
    PgSelectRows29[["PgSelectRows[29∈1] ➊"]]:::plan
    PgSelectRows29 --> First28
    PgSelect26 --> PgSelectRows29
    PgSelectSingle30{{"PgSelectSingle[30∈1] ➊<br />ᐸunion_postsᐳ"}}:::plan
    First28 --> 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
    First37{{"First[37∈1] ➊"}}:::plan
    PgSelectRows38[["PgSelectRows[38∈1] ➊"]]:::plan
    PgSelectRows38 --> First37
    PgSelect35 --> PgSelectRows38
    PgSelectSingle39{{"PgSelectSingle[39∈1] ➊<br />ᐸunion_dividersᐳ"}}:::plan
    First37 --> PgSelectSingle39
    PgClassExpression40{{"PgClassExpression[40∈1] ➊<br />ᐸ__union_dividers__.”id”ᐳ"}}:::plan
    PgSelectSingle39 --> PgClassExpression40
    PgClassExpression41{{"PgClassExpression[41∈1] ➊<br />ᐸ__union_di...__.”title”ᐳ"}}:::plan
    PgSelectSingle39 --> PgClassExpression41
    PgClassExpression42{{"PgClassExpression[42∈1] ➊<br />ᐸ__union_di...__.”color”ᐳ"}}:::plan
    PgSelectSingle39 --> PgClassExpression42
    First45{{"First[45∈1] ➊"}}:::plan
    PgSelectRows46[["PgSelectRows[46∈1] ➊"]]:::plan
    PgSelectRows46 --> First45
    PgSelect43 --> PgSelectRows46
    PgSelectSingle47{{"PgSelectSingle[47∈1] ➊<br />ᐸunion_checklistsᐳ"}}:::plan
    First45 --> PgSelectSingle47
    PgClassExpression48{{"PgClassExpression[48∈1] ➊<br />ᐸ__union_ch...sts__.”id”ᐳ"}}:::plan
    PgSelectSingle47 --> PgClassExpression48
    PgClassExpression49{{"PgClassExpression[49∈1] ➊<br />ᐸ__union_ch...__.”title”ᐳ"}}:::plan
    PgSelectSingle47 --> PgClassExpression49
    First52{{"First[52∈1] ➊"}}:::plan
    PgSelectRows53[["PgSelectRows[53∈1] ➊"]]:::plan
    PgSelectRows53 --> First52
    PgSelect50 --> PgSelectRows53
    PgSelectSingle54{{"PgSelectSingle[54∈1] ➊<br />ᐸunion_checklist_itemsᐳ"}}:::plan
    First52 --> PgSelectSingle54
    PgClassExpression55{{"PgClassExpression[55∈1] ➊<br />ᐸ__union_ch...ems__.”id”ᐳ"}}:::plan
    PgSelectSingle54 --> PgClassExpression55
    PgClassExpression56{{"PgClassExpression[56∈1] ➊<br />ᐸ__union_ch...scription”ᐳ"}}:::plan
    PgSelectSingle54 --> PgClassExpression56
    PgClassExpression57{{"PgClassExpression[57∈1] ➊<br />ᐸ__union_ch...s__.”note”ᐳ"}}:::plan
    PgSelectSingle54 --> PgClassExpression57

    %% define steps

    subgraph "Buckets for queries/unions-table/by-id-1"
    Bucket0("Bucket 0 (root)<br /><br />1: <br />ᐳ: 8, 9, 65, 66, 67, 80, 81, 82, 95, 96, 97, 110, 111, 112, 125, 126, 127, 140, 141, 142, 150, 151, 152, 153, 154, 155, 156, 157, 158, 10, 60, 63, 64, 68, 69, 74, 83, 84, 89, 98, 99, 104, 113, 114, 119, 128, 129, 134, 143, 144, 149<br />2: PgSelect[7]<br />3: PgSelectRows[12]<br />ᐳ: 11, 13, 14, 15"):::bucket
    classDef bucket0 stroke:#696969
    class Bucket0,__Value2,__Value4,PgSelect7,Access8,Access9,Object10,First11,PgSelectRows12,PgSelectSingle13,PgClassExpression14,PgPolymorphic15,Lambda60,Lambda63,Access64,Constant65,Constant66,Constant67,Object68,Lambda69,Lambda74,Constant80,Constant81,Constant82,Object83,Lambda84,Lambda89,Constant95,Constant96,Constant97,Object98,Lambda99,Lambda104,Constant110,Constant111,Constant112,Object113,Lambda114,Lambda119,Constant125,Constant126,Constant127,Object128,Lambda129,Lambda134,Constant140,Constant141,Constant142,Object143,Lambda144,Lambda149,Constant150,Constant151,Constant152,Constant153,Constant154,Constant155,Constant156,Constant157,Constant158 bucket0
    Bucket1("Bucket 1 (polymorphic)<br />UnionTopic,UnionPost,UnionDivider,UnionChecklist,UnionChecklistItem<br />Deps: 13, 10, 60, 64, 69, 74, 84, 89, 99, 104, 114, 119, 129, 134, 15<br />ᐳUnionTopic<br />ᐳUnionPost<br />ᐳUnionDivider<br />ᐳUnionChecklist<br />ᐳUnionChecklistItem<br /><br />1: <br />ᐳ: PgClassExpression[16]<br />2: 17, 26, 35, 43, 50<br />3: 22, 29, 38, 46, 53<br />ᐳ: 21, 23, 24, 25, 28, 30, 31, 32, 33, 34, 37, 39, 40, 41, 42, 45, 47, 48, 49, 52, 54, 55, 56, 57"):::bucket
    classDef bucket1 stroke:#00bfff
    class Bucket1,PgClassExpression16,PgSelect17,First21,PgSelectRows22,PgSelectSingle23,PgClassExpression24,PgClassExpression25,PgSelect26,First28,PgSelectRows29,PgSelectSingle30,PgClassExpression31,PgClassExpression32,PgClassExpression33,PgClassExpression34,PgSelect35,First37,PgSelectRows38,PgSelectSingle39,PgClassExpression40,PgClassExpression41,PgClassExpression42,PgSelect43,First45,PgSelectRows46,PgSelectSingle47,PgClassExpression48,PgClassExpression49,PgSelect50,First52,PgSelectRows53,PgSelectSingle54,PgClassExpression55,PgClassExpression56,PgClassExpression57 bucket1
    Bucket0 --> Bucket1
    end
