Skip to content

Instantly share code, notes, and snippets.

@d6y
Created June 25, 2018 10:06
Show Gist options
  • Save d6y/81aa2ed6a34b0044fc9dd51545f49e96 to your computer and use it in GitHub Desktop.
Save d6y/81aa2ed6a34b0044fc9dd51545f49e96 to your computer and use it in GitHub Desktop.
filterQuery.length.result
-------- QUERY 1 (CORRECT):
DEBUG slick.compiler.QueryCompiler - Source:
| Apply Function count(*)
| 0: Filter s2
| from s2: TableExpansion
| table s3: Table a
| columns: TypeMapping
| 0: ProductNode
| 1: Path s3.id : Int'
| 2: Path s3.relatesTo : Option[Int']
| 3: Path s3.name : String'
| where: Apply Function exists
| 0: Filter s4
| from s4: TableExpansion
| table s3: Table a
| columns: TypeMapping
| 0: ProductNode
| 1: Path s3.id : Int'
| 2: Path s3.relatesTo : Option[Int']
| 3: Path s3.name : String'
| where: Apply Function =
| 0: Path s2.relatesTo : Option[Int']
| 1: Path s4.id : Int'
DEBUG slick.compiler.QueryCompiler - After phase assignUniqueSymbols:
| Apply Function count(*)
| 0: Filter s5
| from s5: TableExpansion
| table s6: Table a
| columns: TypeMapping
| 0: ProductNode
| 1: Path s6.id : Int'
| 2: Path s6.relatesTo : Option[Int']
| 3: Path s6.name : String'
| where: Apply Function exists
| 0: Filter s8
| from s8: TableExpansion
| table s9: Table a
| columns: TypeMapping
| 0: ProductNode
| 1: Path s9.id : Int'
| 2: Path s9.relatesTo : Option[Int']
| 3: Path s9.name : String'
| where: Apply Function =
| 0: Path s5.relatesTo : Option[Int']
| 1: Path s8.id : Int'
DEBUG slick.compiler.QueryCompiler - After phase unrollTailBinds: (no change)
DEBUG slick.compiler.QueryCompiler - After phase inferTypes: (no change)
DEBUG slick.compiler.QueryCompiler - After phase expandTables:
| Apply Function count(*) : Int
| 0: Filter s5 : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s5: Table a : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function exists : Boolean
| 0: Filter s8 : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s8: Table a : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function = : SOption[Boolean]
| 0: Path s5.relatesTo : Option[Int']
| 1: Path s8.id : Int'
DEBUG slick.compiler.QueryCompiler - After phase forceOuterBinds:
| First : t11<Int>
| 0: Bind : Vector[t11<Int>]
| from s12: Pure t13 : Vector[t13<()>]
| value: ProductNode : ()
| select: Pure t11 : Vector[t11<Int>]
| value: Apply Function count(*) : Int
| 0: Bind : Vector[t15<@t7<{id: Int', relatesTo: Option[Int'], name: String'}>>]
| from s14: Filter s5 : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s5: Table a : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function exists : Boolean
| 0: Bind : Vector[t17<@t10<{id: Int', relatesTo: Option[Int'], name: String'}>>]
| from s16: Filter s8 : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s8: Table a : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function = : SOption[Boolean]
| 0: Path s5.relatesTo : Option[Int']
| 1: Path s8.id : Int'
| select: Pure t17 : Vector[t17<@t10<{id: Int', relatesTo: Option[Int'], name: String'}>>]
| value: Ref s16 : @t10<{id: Int', relatesTo: Option[Int'], name: String'}>
| select: Pure t15 : Vector[t15<@t7<{id: Int', relatesTo: Option[Int'], name: String'}>>]
| value: Ref s14 : @t7<{id: Int', relatesTo: Option[Int'], name: String'}>
DEBUG slick.compiler.QueryCompiler - After phase removeMappedTypes: (no change)
DEBUG slick.compiler.QueryCompiler - After phase expandSums: (no change)
DEBUG slick.compiler.QueryCompiler - After phase emulateOuterJoins: (no change)
DEBUG slick.compiler.QueryCompiler - After phase expandRecords:
| First : t11<Int>
| 0: Bind : Vector[t11<Int>]
| from s12: Pure t13 : Vector[t13<()>]
| value: ProductNode : ()
| select: Pure t11 : Vector[t11<Int>]
| value: Apply Function count(*) : Int
| 0: Bind : Vector[t15<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s14: Filter s5 : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s5: Table a : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function exists : Boolean
| 0: Bind : Vector[t17<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s16: Filter s8 : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s8: Table a : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function = : SOption[Boolean]
| 0: Path s5.relatesTo : Option[Int']
| 1: Path s8.id : Int'
| select: Pure t17 : Vector[t17<{id: Int', relatesTo: Option[Int'], name: String'}>]
| value: StructNode : {id: Int', relatesTo: Option[Int'], name: String'}
| id: Path s16.id : Int'
| relatesTo: Path s16.relatesTo : Option[Int']
| name: Path s16.name : String'
| select: Pure t15 : Vector[t15<{id: Int', relatesTo: Option[Int'], name: String'}>]
| value: StructNode : {id: Int', relatesTo: Option[Int'], name: String'}
| id: Path s14.id : Int'
| relatesTo: Path s14.relatesTo : Option[Int']
| name: Path s14.name : String'
DEBUG slick.compiler.QueryCompiler - After phase flattenProjections:
| First : t11<{s18: Int}>
| 0: Bind : Vector[t11<{s18: Int}>]
| from s12: Pure t13 : Vector[t13<{}>]
| value: StructNode : {}
| select: Pure t11 : Vector[t11<{s18: Int}>]
| value: StructNode : {s18: Int}
| s18: Apply Function count(*) : Int
| 0: Bind : Vector[t15<{s19: Int', s20: Option[Int'], s21: String'}>]
| from s14: Filter s5 : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s5: Table a : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function exists : Boolean
| 0: Bind : Vector[t17<{s22: Int', s23: Option[Int'], s24: String'}>]
| from s16: Filter s8 : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s8: Table a : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function = : SOption[Boolean]
| 0: Path s5.relatesTo : Option[Int']
| 1: Path s8.id : Int'
| select: Pure t17 : Vector[t17<{s22: Int', s23: Option[Int'], s24: String'}>]
| value: StructNode : {s22: Int', s23: Option[Int'], s24: String'}
| s22: Path s16.id : Int'
| s23: Path s16.relatesTo : Option[Int']
| s24: Path s16.name : String'
| select: Pure t15 : Vector[t15<{s19: Int', s20: Option[Int'], s21: String'}>]
| value: StructNode : {s19: Int', s20: Option[Int'], s21: String'}
| s19: Path s14.id : Int'
| s20: Path s14.relatesTo : Option[Int']
| s21: Path s14.name : String'
DEBUG slick.compiler.QueryCompiler - After phase rewriteJoins:
| First : t11<{s18: Int}>
| 0: Bind : Vector[t11<{s18: Int}>]
| from s12: Pure t25 : Vector[t25<{}>]
| value: StructNode : {}
| select: Pure t11 : Vector[t11<{s18: Int}>]
| value: StructNode : {s18: Int}
| s18: Apply Function count(*) : Int
| 0: Bind : Vector[t15<{s19: Int', s20: Option[Int'], s21: String'}>]
| from s14: Filter s5 : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s5: Table a : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function exists : Boolean
| 0: Bind : Vector[t17<{s22: Int', s23: Option[Int'], s24: String'}>]
| from s16: Filter s8 : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s8: Table a : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function = : SOption[Boolean]
| 0: Path s5.relatesTo : Option[Int']
| 1: Path s8.id : Int'
| select: Pure t17 : Vector[t17<{s22: Int', s23: Option[Int'], s24: String'}>]
| value: StructNode : {s22: Int', s23: Option[Int'], s24: String'}
| s22: Path s16.id : Int'
| s23: Path s16.relatesTo : Option[Int']
| s24: Path s16.name : String'
| select: Pure t15 : Vector[t15<{s19: Int', s20: Option[Int'], s21: String'}>]
| value: StructNode : {s19: Int', s20: Option[Int'], s21: String'}
| s19: Path s14.id : Int'
| s20: Path s14.relatesTo : Option[Int']
| s21: Path s14.name : String'
DEBUG slick.compiler.QueryCompiler - After phase verifySymbols: (no change)
DEBUG slick.compiler.QueryCompiler - After phase relabelUnions: (no change)
DEBUG slick.compiler.QueryCompiler - After phase createAggregates:
| First : t11<{s18: Int}>
| 0: Bind : Vector[t11<{s18: Int}>]
| from s12: Pure t26 : Vector[t26<{s27: Int}>]
| value: Aggregate : {s27: Int}
| from s14: Filter s5 : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s5: Table a : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function exists : Boolean
| 0: Bind : Vector[t17<{s22: Int', s23: Option[Int'], s24: String'}>]
| from s16: Filter s8 : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s8: Table a : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function = : SOption[Boolean]
| 0: Path s5.relatesTo : Option[Int']
| 1: Path s8.id : Int'
| select: Pure t17 : Vector[t17<{s22: Int', s23: Option[Int'], s24: String'}>]
| value: StructNode : {s22: Int', s23: Option[Int'], s24: String'}
| s22: Path s16.id : Int'
| s23: Path s16.relatesTo : Option[Int']
| s24: Path s16.name : String'
| select: StructNode : {s27: Int}
| s27: Apply Function count(*) : Int
| 0: LiteralNode 1 (volatileHint=false) : Int
| select: Pure t11 : Vector[t11<{s18: Int}>]
| value: StructNode : {s18: Int}
| s18: Path s12.s27 : Int
DEBUG slick.compiler.QueryCompiler - After phase resolveZipJoins: (no change)
DEBUG slick.compiler.QueryCompiler - After phase pruneProjections: (no change)
DEBUG slick.compiler.QueryCompiler - After phase rewriteDistinct: (no change)
DEBUG slick.compiler.QueryCompiler - After phase createResultSetMapping:
| First : Int
| 0: ResultSetMapping : Vector[Int]
| from s28: Bind : Vector[t11<{s18: Int}>]
| from s12: Pure t26 : Vector[t26<{s27: Int}>]
| value: Aggregate : {s27: Int}
| from s14: Filter s5 : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s5: Table a : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function exists : Boolean
| 0: Bind : Vector[t17<{s22: Int', s23: Option[Int'], s24: String'}>]
| from s16: Filter s8 : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s8: Table a : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function = : SOption[Boolean]
| 0: Path s5.relatesTo : Option[Int']
| 1: Path s8.id : Int'
| select: Pure t17 : Vector[t17<{s22: Int', s23: Option[Int'], s24: String'}>]
| value: StructNode : {s22: Int', s23: Option[Int'], s24: String'}
| s22: Path s16.id : Int'
| s23: Path s16.relatesTo : Option[Int']
| s24: Path s16.name : String'
| select: StructNode : {s27: Int}
| s27: Apply Function count(*) : Int
| 0: LiteralNode 1 (volatileHint=false) : Int
| select: Pure t11 : Vector[t11<{s18: Int}>]
| value: StructNode : {s18: Int}
| s18: Path s12.s27 : Int
| map: Path s28.s18 : Int
DEBUG slick.compiler.QueryCompiler - After phase hoistClientOps:
| First : Int
| 0: ResultSetMapping : Vector[Int]
| from s28: Bind : Vector[t29<{s30: Int}>]
| from s12: Pure t26 : Vector[t26<{s27: Int}>]
| value: Aggregate : {s27: Int}
| from s14: Filter s5 : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s5: Table a : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function exists : Boolean
| 0: Bind : Vector[t17<{s22: Int', s23: Option[Int'], s24: String'}>]
| from s16: Filter s8 : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| from s8: Table a : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| where: Apply Function = : SOption[Boolean]
| 0: Path s5.relatesTo : Option[Int']
| 1: Path s8.id : Int'
| select: Pure t17 : Vector[t17<{s22: Int', s23: Option[Int'], s24: String'}>]
| value: StructNode : {s22: Int', s23: Option[Int'], s24: String'}
| s22: Path s16.id : Int'
| s23: Path s16.relatesTo : Option[Int']
| s24: Path s16.name : String'
| select: StructNode : {s27: Int}
| s27: Apply Function count(*) : Int
| 0: LiteralNode 1 (volatileHint=false) : Int
| select: Pure t29 : Vector[t29<{s30: Int}>]
| value: StructNode : {s30: Int}
| s30: Path s12.s27 : Int
| map: Path s28.s30 : Int
DEBUG slick.compiler.QueryCompiler - After phase reorderOperations: (no change)
DEBUG slick.compiler.QueryCompiler - After phase mergeToComprehensions:
| First : Int
| 0: ResultSetMapping : Vector[Int]
| from s28: Comprehension s31, Some(Apply Function exists), None, ConstArray(), None, None, None, None, false : Vector[t29<{s30: Int}>]
| from s31: Table a : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| select: Pure t29 : Vector[t29<{s30: Int}>]
| value: StructNode : {s30: Int}
| s30: Apply Function count(*) : Int
| 0: LiteralNode 1 (volatileHint=false) : Int
| where: Apply Function exists : Boolean
| 0: Comprehension s32, Some(Apply Function =), None, ConstArray(), None, None, None, None, false : Vector[t17<{s22: Int', s23: Option[Int'], s24: String'}>]
| from s32: Table a : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| select: Pure t17 : Vector[t17<{s22: Int', s23: Option[Int'], s24: String'}>]
| value: StructNode : {s22: Int', s23: Option[Int'], s24: String'}
| s22: Path s32.id : Int'
| s23: Path s32.relatesTo : Option[Int']
| s24: Path s32.name : String'
| where: Apply Function = : SOption[Boolean]
| 0: Path s31.relatesTo : Option[Int']
| 1: Path s32.id : Int'
| map: Path s28.s30 : Int
DEBUG slick.compiler.QueryCompiler - After phase optimizeScalar: (no change)
DEBUG slick.compiler.QueryCompiler - After phase removeFieldNames:
| First : Int
| 0: ResultSetMapping : Vector[Int]
| from s28: Comprehension s31, Some(Apply Function exists), None, ConstArray(), None, None, None, None, false : Vector[t29<(Int)>]
| from s31: Table a : Vector[@t7<{id: Int', relatesTo: Option[Int'], name: String'}>]
| select: Pure t29 : Vector[t29<(Int)>]
| value: ProductNode : (Int)
| 1: Apply Function count(*) : Int
| 0: LiteralNode 1 (volatileHint=false) : Int
| where: Apply Function exists : Boolean
| 0: Comprehension s32, Some(Apply Function =), None, ConstArray(), None, None, None, None, false : Vector[t17<(Int', Option[Int'], String')>]
| from s32: Table a : Vector[@t10<{id: Int', relatesTo: Option[Int'], name: String'}>]
| select: Pure t17 : Vector[t17<(Int', Option[Int'], String')>]
| value: ProductNode : (Int', Option[Int'], String')
| 1: Path s32.id : Int'
| 2: Path s32.relatesTo : Option[Int']
| 3: Path s32.name : String'
| where: Apply Function = : SOption[Boolean]
| 0: Path s31.relatesTo : Option[Int']
| 1: Path s32.id : Int'
| map: Path s28._1 : Int
DEBUG slick.compiler.QueryCompiler - After phase codeGen:
| First : Int
| 0: ResultSetMapping : Vector[Int]
| from s28: CompiledStatement "select count(1) from "a" s31 where exists(select "id", "relatesTo", "name" from "a" where s31."relatesTo" = "id")" : Vector[t29<(Int)>]
| map: CompiledMapping : Int
| converter: BaseResultConverter$mcI$sp idx=1, name=<computed> : Int'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment