tpch_select.slt 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. # Plans for the TPC-H workload modeled as plain old SELECT statements.
  10. # PRIMARY KEY annotations (which are in the spec) are currently
  11. # removed from this slt, because we don't support them at the moment.
  12. # (Note that _in slts_ they are actually supported, but it's better
  13. # to match the plans of real runs more closely.)
  14. statement ok
  15. CREATE TABLE nation (
  16. n_nationkey integer,
  17. n_name char(25) NOT NULL,
  18. n_regionkey integer NOT NULL,
  19. n_comment varchar(152)
  20. );
  21. statement ok
  22. CREATE INDEX pk_nation_nationkey ON nation (n_nationkey ASC);
  23. statement ok
  24. CREATE INDEX fk_nation_regionkey ON nation (n_regionkey ASC);
  25. statement ok
  26. CREATE TABLE region (
  27. r_regionkey integer,
  28. r_name char(25) NOT NULL,
  29. r_comment varchar(152)
  30. );
  31. statement ok
  32. CREATE INDEX pk_region_regionkey ON region (r_regionkey ASC);
  33. statement ok
  34. CREATE TABLE part (
  35. p_partkey integer,
  36. p_name varchar(55) NOT NULL,
  37. p_mfgr char(25) NOT NULL,
  38. p_brand char(10) NOT NULL,
  39. p_type varchar(25) NOT NULL,
  40. p_size integer NOT NULL,
  41. p_container char(10) NOT NULL,
  42. p_retailprice decimal(15, 2) NOT NULL,
  43. p_comment varchar(23) NOT NULL
  44. );
  45. statement ok
  46. CREATE INDEX pk_part_partkey ON part (p_partkey ASC);
  47. statement ok
  48. CREATE TABLE supplier (
  49. s_suppkey integer,
  50. s_name char(25) NOT NULL,
  51. s_address varchar(40) NOT NULL,
  52. s_nationkey integer NOT NULL,
  53. s_phone char(15) NOT NULL,
  54. s_acctbal decimal(15, 2) NOT NULL,
  55. s_comment varchar(101) NOT NULL
  56. );
  57. statement ok
  58. CREATE INDEX pk_supplier_suppkey ON supplier (s_suppkey ASC);
  59. statement ok
  60. CREATE INDEX fk_supplier_nationkey ON supplier (s_nationkey ASC);
  61. statement ok
  62. CREATE TABLE partsupp (
  63. ps_partkey integer NOT NULL,
  64. ps_suppkey integer NOT NULL,
  65. ps_availqty integer NOT NULL,
  66. ps_supplycost decimal(15, 2) NOT NULL,
  67. ps_comment varchar(199) NOT NULL
  68. );
  69. statement ok
  70. CREATE INDEX pk_partsupp_partkey_suppkey ON partsupp (ps_partkey ASC, ps_suppkey ASC);
  71. statement ok
  72. CREATE INDEX fk_partsupp_partkey ON partsupp (ps_partkey ASC);
  73. statement ok
  74. CREATE INDEX fk_partsupp_suppkey ON partsupp (ps_suppkey ASC);
  75. statement ok
  76. CREATE TABLE customer (
  77. c_custkey integer,
  78. c_name varchar(25) NOT NULL,
  79. c_address varchar(40) NOT NULL,
  80. c_nationkey integer NOT NULL,
  81. c_phone char(15) NOT NULL,
  82. c_acctbal decimal(15, 2) NOT NULL,
  83. c_mktsegment char(10) NOT NULL,
  84. c_comment varchar(117) NOT NULL
  85. );
  86. statement ok
  87. CREATE INDEX pk_customer_custkey ON customer (c_custkey ASC);
  88. statement ok
  89. CREATE INDEX fk_customer_nationkey ON customer (c_nationkey ASC);
  90. statement ok
  91. CREATE TABLE orders (
  92. o_orderkey integer,
  93. o_custkey integer NOT NULL,
  94. o_orderstatus char(1) NOT NULL,
  95. o_totalprice decimal(15, 2) NOT NULL,
  96. o_orderdate DATE NOT NULL,
  97. o_orderpriority char(15) NOT NULL,
  98. o_clerk char(15) NOT NULL,
  99. o_shippriority integer NOT NULL,
  100. o_comment varchar(79) NOT NULL
  101. );
  102. statement ok
  103. CREATE INDEX pk_orders_orderkey ON orders (o_orderkey ASC);
  104. statement ok
  105. CREATE INDEX fk_orders_custkey ON orders (o_custkey ASC);
  106. statement ok
  107. CREATE TABLE lineitem (
  108. l_orderkey integer NOT NULL,
  109. l_partkey integer NOT NULL,
  110. l_suppkey integer NOT NULL,
  111. l_linenumber integer NOT NULL,
  112. l_quantity decimal(15, 2) NOT NULL,
  113. l_extendedprice decimal(15, 2) NOT NULL,
  114. l_discount decimal(15, 2) NOT NULL,
  115. l_tax decimal(15, 2) NOT NULL,
  116. l_returnflag char(1) NOT NULL,
  117. l_linestatus char(1) NOT NULL,
  118. l_shipdate date NOT NULL,
  119. l_commitdate date NOT NULL,
  120. l_receiptdate date NOT NULL,
  121. l_shipinstruct char(25) NOT NULL,
  122. l_shipmode char(10) NOT NULL,
  123. l_comment varchar(44) NOT NULL
  124. );
  125. statement ok
  126. CREATE INDEX pk_lineitem_orderkey_linenumber ON lineitem (l_orderkey ASC, l_linenumber ASC);
  127. statement ok
  128. CREATE INDEX fk_lineitem_orderkey ON lineitem (l_orderkey ASC);
  129. statement ok
  130. CREATE INDEX fk_lineitem_partkey ON lineitem (l_partkey ASC);
  131. statement ok
  132. CREATE INDEX fk_lineitem_suppkey ON lineitem (l_suppkey ASC);
  133. statement ok
  134. CREATE INDEX fk_lineitem_partsuppkey ON lineitem (l_partkey ASC, l_suppkey ASC);
  135. query T multiline
  136. -- Query 01
  137. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  138. SELECT
  139. l_returnflag,
  140. l_linestatus,
  141. sum(l_quantity) AS sum_qty,
  142. sum(l_extendedprice) AS sum_base_price,
  143. sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price,
  144. sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge,
  145. avg(l_quantity) AS avg_qty,
  146. avg(l_extendedprice) AS avg_price,
  147. avg(l_discount) AS avg_disc,
  148. count(*) AS count_order
  149. FROM
  150. lineitem
  151. WHERE
  152. l_shipdate <= DATE '1998-12-01' - INTERVAL '60' day
  153. GROUP BY
  154. l_returnflag,
  155. l_linestatus
  156. ORDER BY
  157. l_returnflag,
  158. l_linestatus;
  159. ----
  160. Explained Query:
  161. Finish order_by=[#0{l_returnflag} asc nulls_last, #1{l_linestatus} asc nulls_last] output=[#0..=#9]
  162. Project (#0{l_returnflag}..=#5{sum}, #9..=#11, #6{count}) // { arity: 10 }
  163. Map (bigint_to_numeric(case when (#6{count} = 0) then null else #6{count} end), (#2{sum_l_quantity} / #8), (#3{sum_l_extendedprice} / #8), (#7{sum_l_discount} / #8)) // { arity: 12 }
  164. Reduce group_by=[#4{l_returnflag}, #5{l_linestatus}] aggregates=[sum(#0{l_quantity}), sum(#1{l_extendedprice}), sum((#1{l_extendedprice} * (1 - #2{l_discount}))), sum(((#1{l_extendedprice} * (1 - #2{l_discount})) * (1 + #3{l_tax}))), count(*), sum(#2{l_discount})] // { arity: 8 }
  165. Project (#4{l_quantity}..=#9{l_linestatus}) // { arity: 6 }
  166. Filter (date_to_timestamp(#10{l_shipdate}) <= 1998-10-02 00:00:00) // { arity: 16 }
  167. ReadIndex on=lineitem pk_lineitem_orderkey_linenumber=[*** full scan ***] // { arity: 16 }
  168. Used Indexes:
  169. - materialize.public.pk_lineitem_orderkey_linenumber (*** full scan ***)
  170. Target cluster: quickstart
  171. EOF
  172. query T multiline
  173. -- Query 02
  174. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  175. SELECT
  176. s_acctbal,
  177. s_name,
  178. n_name,
  179. p_partkey,
  180. p_mfgr,
  181. s_address,
  182. s_phone,
  183. s_comment
  184. FROM
  185. part, supplier, partsupp, nation, region
  186. WHERE
  187. p_partkey = ps_partkey
  188. AND s_suppkey = ps_suppkey
  189. AND p_size = CAST (15 AS smallint)
  190. AND p_type LIKE '%BRASS'
  191. AND s_nationkey = n_nationkey
  192. AND n_regionkey = r_regionkey
  193. AND r_name = 'EUROPE'
  194. AND ps_supplycost
  195. = (
  196. SELECT
  197. min(ps_supplycost)
  198. FROM
  199. partsupp, supplier, nation, region
  200. WHERE
  201. p_partkey = ps_partkey
  202. AND s_suppkey = ps_suppkey
  203. AND s_nationkey = n_nationkey
  204. AND n_regionkey = r_regionkey
  205. AND r_name = 'EUROPE'
  206. )
  207. ORDER BY
  208. s_acctbal DESC, n_name, s_name, p_partkey;
  209. ----
  210. Explained Query:
  211. Finish order_by=[#0{s_acctbal} desc nulls_first, #2{n_name} asc nulls_last, #1{s_name} asc nulls_last, #3{p_partkey} asc nulls_last] output=[#0..=#7]
  212. With
  213. cte l0 =
  214. ArrangeBy keys=[[#0{s_suppkey}], [#3{s_nationkey}]] // { arity: 7 }
  215. ReadIndex on=supplier pk_supplier_suppkey=[delta join lookup] fk_supplier_nationkey=[delta join lookup] // { arity: 7 }
  216. cte l1 =
  217. ArrangeBy keys=[[#0{ps_partkey}], [#1{ps_suppkey}]] // { arity: 5 }
  218. ReadIndex on=partsupp fk_partsupp_partkey=[delta join lookup] fk_partsupp_suppkey=[delta join lookup] // { arity: 5 }
  219. cte l2 =
  220. ArrangeBy keys=[[#0{n_nationkey}], [#2{n_regionkey}]] // { arity: 4 }
  221. ReadIndex on=nation pk_nation_nationkey=[delta join lookup] fk_nation_regionkey=[delta join lookup] // { arity: 4 }
  222. cte l3 =
  223. ArrangeBy keys=[[#0{r_regionkey}]] // { arity: 3 }
  224. ReadIndex on=region pk_region_regionkey=[delta join lookup] // { arity: 3 }
  225. cte l4 =
  226. Project (#0{p_partkey}, #2{p_mfgr}, #10{s_name}, #11{s_address}, #13{s_phone}..=#15{s_comment}, #19{ps_supplycost}, #22{n_name}) // { arity: 9 }
  227. Filter (#5{p_size} = 15) AND (#26{r_name} = "EUROPE") AND like["%BRASS"](varchar_to_text(#4{p_type})) // { arity: 28 }
  228. Join on=(#0{p_partkey} = #16{ps_partkey} AND #9{s_suppkey} = #17{ps_suppkey} AND #12{s_nationkey} = #21{n_nationkey} AND #23{n_regionkey} = #25{r_regionkey}) type=delta // { arity: 28 }
  229. implementation
  230. %0:part » %2:l1[#0{ps_partkey}]KA » %1:l0[#0{s_suppkey}]KA » %3:l2[#0{n_nationkey}]KA » %4:l3[#0{r_regionkey}]KAef
  231. %1:l0 » %2:l1[#1{ps_suppkey}]KA » %0:part[#0{p_partkey}]KAelf » %3:l2[#0{n_nationkey}]KA » %4:l3[#0{r_regionkey}]KAef
  232. %2:l1 » %0:part[#0{p_partkey}]KAelf » %1:l0[#0{s_suppkey}]KA » %3:l2[#0{n_nationkey}]KA » %4:l3[#0{r_regionkey}]KAef
  233. %3:l2 » %4:l3[#0{r_regionkey}]KAef » %1:l0[#3{s_nationkey}]KA » %2:l1[#1{ps_suppkey}]KA » %0:part[#0{p_partkey}]KAelf
  234. %4:l3 » %3:l2[#2{n_regionkey}]KA » %1:l0[#3{s_nationkey}]KA » %2:l1[#1{ps_suppkey}]KA » %0:part[#0{p_partkey}]KAelf
  235. ArrangeBy keys=[[#0{p_partkey}]] // { arity: 9 }
  236. ReadIndex on=part pk_part_partkey=[delta join 1st input (full scan)] // { arity: 9 }
  237. Get l0 // { arity: 7 }
  238. Get l1 // { arity: 5 }
  239. Get l2 // { arity: 4 }
  240. Get l3 // { arity: 3 }
  241. Return // { arity: 8 }
  242. Project (#5{s_acctbal}, #2{s_name}, #8{n_name}, #0{p_partkey}, #1{p_mfgr}, #3{s_address}, #4{s_phone}, #6{s_comment}) // { arity: 8 }
  243. Join on=(#0{p_partkey} = #9{p_partkey} AND #7{ps_supplycost} = #10{min_ps_supplycost}) type=differential // { arity: 11 }
  244. implementation
  245. %1[#0, #1]UKK » %0:l4[#0, #7{ps_supplycost}]KK
  246. ArrangeBy keys=[[#0{p_partkey}, #7{ps_supplycost}]] // { arity: 9 }
  247. Get l4 // { arity: 9 }
  248. ArrangeBy keys=[[#0{p_partkey}, #1{min_ps_supplycost}]] // { arity: 2 }
  249. Reduce group_by=[#0{p_partkey}] aggregates=[min(#1{ps_supplycost})] // { arity: 2 }
  250. Project (#0{p_partkey}, #4{ps_supplycost}) // { arity: 2 }
  251. Filter (#18{r_name} = "EUROPE") // { arity: 20 }
  252. Join on=(#0{p_partkey} = #1{ps_partkey} AND #2{ps_suppkey} = #6{s_suppkey} AND #9{s_nationkey} = #13{n_nationkey} AND #15{n_regionkey} = #17{r_regionkey}) type=delta // { arity: 20 }
  253. implementation
  254. %0 » %1:l1[#0{ps_partkey}]KA » %2:l0[#0{s_suppkey}]KA » %3:l2[#0{n_nationkey}]KA » %4:l3[#0{r_regionkey}]KAef
  255. %1:l1 » %0[#0]UKA » %2:l0[#0{s_suppkey}]KA » %3:l2[#0{n_nationkey}]KA » %4:l3[#0{r_regionkey}]KAef
  256. %2:l0 » %1:l1[#1{ps_suppkey}]KA » %0[#0]UKA » %3:l2[#0{n_nationkey}]KA » %4:l3[#0{r_regionkey}]KAef
  257. %3:l2 » %4:l3[#0{r_regionkey}]KAef » %2:l0[#3{s_nationkey}]KA » %1:l1[#1{ps_suppkey}]KA » %0[#0]UKA
  258. %4:l3 » %3:l2[#2{n_regionkey}]KA » %2:l0[#3{s_nationkey}]KA » %1:l1[#1{ps_suppkey}]KA » %0[#0]UKA
  259. ArrangeBy keys=[[#0{p_partkey}]] // { arity: 1 }
  260. Distinct project=[#0{p_partkey}] // { arity: 1 }
  261. Project (#0{p_partkey}) // { arity: 1 }
  262. Get l4 // { arity: 9 }
  263. Get l1 // { arity: 5 }
  264. Get l0 // { arity: 7 }
  265. Get l2 // { arity: 4 }
  266. Get l3 // { arity: 3 }
  267. Used Indexes:
  268. - materialize.public.pk_nation_nationkey (delta join lookup)
  269. - materialize.public.fk_nation_regionkey (delta join lookup)
  270. - materialize.public.pk_region_regionkey (delta join lookup)
  271. - materialize.public.pk_part_partkey (delta join 1st input (full scan))
  272. - materialize.public.pk_supplier_suppkey (delta join lookup)
  273. - materialize.public.fk_supplier_nationkey (delta join lookup)
  274. - materialize.public.fk_partsupp_partkey (delta join lookup)
  275. - materialize.public.fk_partsupp_suppkey (delta join lookup)
  276. Target cluster: quickstart
  277. EOF
  278. query T multiline
  279. -- Query 03
  280. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  281. SELECT
  282. l_orderkey,
  283. sum(l_extendedprice * (1 - l_discount)) AS revenue,
  284. o_orderdate,
  285. o_shippriority
  286. FROM
  287. customer,
  288. orders,
  289. lineitem
  290. WHERE
  291. c_mktsegment = 'BUILDING'
  292. AND c_custkey = o_custkey
  293. AND l_orderkey = o_orderkey
  294. AND o_orderdate < DATE '1995-03-15'
  295. AND l_shipdate > DATE '1995-03-15'
  296. GROUP BY
  297. l_orderkey,
  298. o_orderdate,
  299. o_shippriority
  300. ORDER BY
  301. revenue DESC,
  302. o_orderdate;
  303. ----
  304. Explained Query:
  305. Finish order_by=[#1{sum} desc nulls_first, #2{o_orderdate} asc nulls_last] output=[#0..=#3]
  306. Project (#0{o_orderkey}, #3{sum}, #1{o_orderdate}, #2{o_shippriority}) // { arity: 4 }
  307. Reduce group_by=[#0{o_orderkey}..=#2{o_shippriority}] aggregates=[sum((#3{l_extendedprice} * (1 - #4{l_discount})))] // { arity: 4 }
  308. Project (#8{o_orderkey}, #12{o_orderdate}, #15{o_shippriority}, #22{l_extendedprice}, #23{l_discount}) // { arity: 5 }
  309. Filter (#6{c_mktsegment} = "BUILDING") AND (#12{o_orderdate} < 1995-03-15) AND (#27{l_shipdate} > 1995-03-15) // { arity: 33 }
  310. Join on=(#0{c_custkey} = #9{o_custkey} AND #8{o_orderkey} = #17{l_orderkey}) type=delta // { arity: 33 }
  311. implementation
  312. %0:customer » %1:orders[#1{o_custkey}]KAif » %2:lineitem[#0{l_orderkey}]KAif
  313. %1:orders » %0:customer[#0{c_custkey}]KAef » %2:lineitem[#0{l_orderkey}]KAif
  314. %2:lineitem » %1:orders[#0{o_orderkey}]KAif » %0:customer[#0{c_custkey}]KAef
  315. ArrangeBy keys=[[#0{c_custkey}]] // { arity: 8 }
  316. ReadIndex on=customer pk_customer_custkey=[delta join 1st input (full scan)] // { arity: 8 }
  317. ArrangeBy keys=[[#0{o_orderkey}], [#1{o_custkey}]] // { arity: 9 }
  318. ReadIndex on=orders pk_orders_orderkey=[delta join lookup] fk_orders_custkey=[delta join lookup] // { arity: 9 }
  319. ArrangeBy keys=[[#0{l_orderkey}]] // { arity: 16 }
  320. ReadIndex on=lineitem fk_lineitem_orderkey=[delta join lookup] // { arity: 16 }
  321. Used Indexes:
  322. - materialize.public.pk_customer_custkey (delta join 1st input (full scan))
  323. - materialize.public.pk_orders_orderkey (delta join lookup)
  324. - materialize.public.fk_orders_custkey (delta join lookup)
  325. - materialize.public.fk_lineitem_orderkey (delta join lookup)
  326. Target cluster: quickstart
  327. EOF
  328. query T multiline
  329. -- Query 04
  330. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  331. SELECT
  332. o_orderpriority,
  333. count(*) AS order_count
  334. FROM
  335. orders
  336. WHERE
  337. o_orderdate >= DATE '1993-07-01'
  338. AND o_orderdate < DATE '1993-07-01' + INTERVAL '3' month
  339. AND EXISTS (
  340. SELECT
  341. *
  342. FROM
  343. lineitem
  344. WHERE
  345. l_orderkey = o_orderkey
  346. AND l_commitdate < l_receiptdate
  347. )
  348. GROUP BY
  349. o_orderpriority
  350. ORDER BY
  351. o_orderpriority;
  352. ----
  353. Explained Query:
  354. Finish order_by=[#0{o_orderpriority} asc nulls_last] output=[#0, #1]
  355. Reduce group_by=[#0{o_orderpriority}] aggregates=[count(*)] // { arity: 2 }
  356. Project (#5{o_orderpriority}) // { arity: 1 }
  357. Filter (#4{o_orderdate} >= 1993-07-01) AND (date_to_timestamp(#4{o_orderdate}) < 1993-10-01 00:00:00) // { arity: 10 }
  358. Join on=(#0{o_orderkey} = #9{l_orderkey}) type=differential // { arity: 10 }
  359. implementation
  360. %1[#0]UKA » %0:orders[#0{o_orderkey}]KAiif
  361. ArrangeBy keys=[[#0{o_orderkey}]] // { arity: 9 }
  362. ReadIndex on=orders pk_orders_orderkey=[differential join] // { arity: 9 }
  363. ArrangeBy keys=[[#0{l_orderkey}]] // { arity: 1 }
  364. Distinct project=[#0{l_orderkey}] // { arity: 1 }
  365. Project (#0{l_orderkey}) // { arity: 1 }
  366. Filter (#11{l_commitdate} < #12{l_receiptdate}) // { arity: 16 }
  367. ReadIndex on=lineitem pk_lineitem_orderkey_linenumber=[*** full scan ***] // { arity: 16 }
  368. Used Indexes:
  369. - materialize.public.pk_orders_orderkey (differential join)
  370. - materialize.public.pk_lineitem_orderkey_linenumber (*** full scan ***)
  371. Target cluster: quickstart
  372. EOF
  373. query T multiline
  374. -- Query 05
  375. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  376. SELECT
  377. n_name,
  378. sum(l_extendedprice * (1 - l_discount)) AS revenue
  379. FROM
  380. customer,
  381. orders,
  382. lineitem,
  383. supplier,
  384. nation,
  385. region
  386. WHERE
  387. c_custkey = o_custkey
  388. AND l_orderkey = o_orderkey
  389. AND l_suppkey = s_suppkey
  390. AND c_nationkey = s_nationkey
  391. AND s_nationkey = n_nationkey
  392. AND n_regionkey = r_regionkey
  393. AND r_name = 'ASIA'
  394. AND o_orderdate >= DATE '1994-01-01'
  395. AND o_orderdate < DATE '1995-01-01'
  396. GROUP BY
  397. n_name
  398. ORDER BY
  399. revenue DESC;
  400. ----
  401. Explained Query:
  402. Finish order_by=[#1{sum} desc nulls_first] output=[#0, #1]
  403. Reduce group_by=[#2{n_name}] aggregates=[sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 2 }
  404. Project (#19{l_extendedprice}, #20{l_discount}, #24{n_name}) // { arity: 3 }
  405. Filter (#28{r_name} = "ASIA") AND (#12{o_orderdate} < 1995-01-01) AND (#12{o_orderdate} >= 1994-01-01) // { arity: 30 }
  406. Join on=(#0{c_custkey} = #9{o_custkey} AND #3{c_nationkey} = #22{s_nationkey} = #23{n_nationkey} AND #8{o_orderkey} = #17{l_orderkey} AND #18{l_suppkey} = #21{s_suppkey} AND #25{n_regionkey} = #27{r_regionkey}) type=delta // { arity: 30 }
  407. implementation
  408. %0:customer » %1:orders[#1{o_custkey}]KAiif » %2:lineitem[#0{l_orderkey}]KA » %3:supplier[#0{s_suppkey}, #1{s_nationkey}]KK » %4:nation[#0{n_nationkey}]KA » %5:region[#0{r_regionkey}]KAef
  409. %1:orders » %0:customer[#0{c_custkey}]KA » %2:lineitem[#0{l_orderkey}]KA » %3:supplier[#0{s_suppkey}, #1{s_nationkey}]KK » %4:nation[#0{n_nationkey}]KA » %5:region[#0{r_regionkey}]KAef
  410. %2:lineitem » %1:orders[#0{o_orderkey}]KAiif » %0:customer[#0{c_custkey}]KA » %3:supplier[#0{s_suppkey}, #1{s_nationkey}]KK » %4:nation[#0{n_nationkey}]KA » %5:region[#0{r_regionkey}]KAef
  411. %3:supplier » %0:customer[#3{c_nationkey}]KA » %1:orders[#1{o_custkey}]KAiif » %2:lineitem[#0{l_orderkey}, #1{l_suppkey}]KK » %4:nation[#0{n_nationkey}]KA » %5:region[#0{r_regionkey}]KAef
  412. %4:nation » %5:region[#0{r_regionkey}]KAef » %0:customer[#3{c_nationkey}]KA » %1:orders[#1{o_custkey}]KAiif » %2:lineitem[#0{l_orderkey}]KA » %3:supplier[#0{s_suppkey}, #1{s_nationkey}]KK
  413. %5:region » %4:nation[#2{n_regionkey}]KA » %0:customer[#3{c_nationkey}]KA » %1:orders[#1{o_custkey}]KAiif » %2:lineitem[#0{l_orderkey}]KA » %3:supplier[#0{s_suppkey}, #1{s_nationkey}]KK
  414. ArrangeBy keys=[[#0{c_custkey}], [#3{c_nationkey}]] // { arity: 8 }
  415. ReadIndex on=customer pk_customer_custkey=[delta join 1st input (full scan)] fk_customer_nationkey=[delta join lookup] // { arity: 8 }
  416. ArrangeBy keys=[[#0{o_orderkey}], [#1{o_custkey}]] // { arity: 9 }
  417. ReadIndex on=orders pk_orders_orderkey=[delta join lookup] fk_orders_custkey=[delta join lookup] // { arity: 9 }
  418. ArrangeBy keys=[[#0{l_orderkey}], [#0{l_orderkey}, #1{l_suppkey}]] // { arity: 4 }
  419. Project (#0{l_orderkey}, #2{l_suppkey}, #5{l_extendedprice}, #6{l_discount}) // { arity: 4 }
  420. ReadIndex on=lineitem pk_lineitem_orderkey_linenumber=[*** full scan ***] // { arity: 16 }
  421. ArrangeBy keys=[[#0{s_suppkey}, #1{s_nationkey}]] // { arity: 2 }
  422. Project (#0{s_suppkey}, #3{s_nationkey}) // { arity: 2 }
  423. Filter (#0{s_suppkey}) IS NOT NULL // { arity: 7 }
  424. ReadIndex on=supplier pk_supplier_suppkey=[*** full scan ***] // { arity: 7 }
  425. ArrangeBy keys=[[#0{n_nationkey}], [#2{n_regionkey}]] // { arity: 4 }
  426. ReadIndex on=nation pk_nation_nationkey=[delta join lookup] fk_nation_regionkey=[delta join lookup] // { arity: 4 }
  427. ArrangeBy keys=[[#0{r_regionkey}]] // { arity: 3 }
  428. ReadIndex on=region pk_region_regionkey=[delta join lookup] // { arity: 3 }
  429. Used Indexes:
  430. - materialize.public.pk_nation_nationkey (delta join lookup)
  431. - materialize.public.fk_nation_regionkey (delta join lookup)
  432. - materialize.public.pk_region_regionkey (delta join lookup)
  433. - materialize.public.pk_supplier_suppkey (*** full scan ***)
  434. - materialize.public.pk_customer_custkey (delta join 1st input (full scan))
  435. - materialize.public.fk_customer_nationkey (delta join lookup)
  436. - materialize.public.pk_orders_orderkey (delta join lookup)
  437. - materialize.public.fk_orders_custkey (delta join lookup)
  438. - materialize.public.pk_lineitem_orderkey_linenumber (*** full scan ***)
  439. Target cluster: quickstart
  440. EOF
  441. query T multiline
  442. -- Query 06
  443. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  444. SELECT
  445. sum(l_extendedprice * l_discount) AS revenue
  446. FROM
  447. lineitem
  448. WHERE
  449. l_quantity < 24
  450. AND l_shipdate >= DATE '1994-01-01'
  451. AND l_shipdate < DATE '1994-01-01' + INTERVAL '1' year
  452. AND l_discount BETWEEN 0.06 - 0.01 AND 0.07;
  453. ----
  454. Explained Query:
  455. With
  456. cte l0 =
  457. Reduce aggregates=[sum((#0{l_extendedprice} * #1{l_discount}))] // { arity: 1 }
  458. Project (#5{l_extendedprice}, #6{l_discount}) // { arity: 2 }
  459. Filter (#4{l_quantity} < 24) AND (#6{l_discount} <= 0.07) AND (#6{l_discount} >= 0.05) AND (#10{l_shipdate} >= 1994-01-01) AND (date_to_timestamp(#10{l_shipdate}) < 1995-01-01 00:00:00) // { arity: 16 }
  460. ReadIndex on=lineitem pk_lineitem_orderkey_linenumber=[*** full scan ***] // { arity: 16 }
  461. Return // { arity: 1 }
  462. Union // { arity: 1 }
  463. Get l0 // { arity: 1 }
  464. Map (null) // { arity: 1 }
  465. Union // { arity: 0 }
  466. Negate // { arity: 0 }
  467. Project () // { arity: 0 }
  468. Get l0 // { arity: 1 }
  469. Constant // { arity: 0 }
  470. - ()
  471. Used Indexes:
  472. - materialize.public.pk_lineitem_orderkey_linenumber (*** full scan ***)
  473. Target cluster: quickstart
  474. EOF
  475. query T multiline
  476. -- Query 07
  477. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  478. SELECT
  479. supp_nation,
  480. cust_nation,
  481. l_year,
  482. sum(volume) AS revenue
  483. FROM
  484. (
  485. SELECT
  486. n1.n_name AS supp_nation,
  487. n2.n_name AS cust_nation,
  488. extract(year FROM l_shipdate) AS l_year,
  489. l_extendedprice * (1 - l_discount) AS volume
  490. FROM
  491. supplier,
  492. lineitem,
  493. orders,
  494. customer,
  495. nation n1,
  496. nation n2
  497. WHERE
  498. s_suppkey = l_suppkey
  499. AND o_orderkey = l_orderkey
  500. AND c_custkey = o_custkey
  501. AND s_nationkey = n1.n_nationkey
  502. AND c_nationkey = n2.n_nationkey
  503. AND (
  504. (n1.n_name = 'FRANCE' AND n2.n_name = 'GERMANY')
  505. or (n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE')
  506. )
  507. AND l_shipdate BETWEEN DATE '1995-01-01' AND DATE '1996-12-31'
  508. ) AS shipping
  509. GROUP BY
  510. supp_nation,
  511. cust_nation,
  512. l_year
  513. ORDER BY
  514. supp_nation,
  515. cust_nation,
  516. l_year;
  517. ----
  518. Explained Query:
  519. Finish order_by=[#0{n_name} asc nulls_last, #1{n_name} asc nulls_last, #2 asc nulls_last] output=[#0..=#3]
  520. With
  521. cte l0 =
  522. ArrangeBy keys=[[#0{n_nationkey}]] // { arity: 4 }
  523. ReadIndex on=nation pk_nation_nationkey=[delta join lookup] // { arity: 4 }
  524. Return // { arity: 4 }
  525. Reduce group_by=[#3{n_name}, #4{n_name}, extract_year_d(#2{l_shipdate})] aggregates=[sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 4 }
  526. Project (#12{l_extendedprice}, #13{l_discount}, #17{l_shipdate}, #41{n_name}, #45{n_name}) // { arity: 5 }
  527. Filter (#17{l_shipdate} <= 1996-12-31) AND (#17{l_shipdate} >= 1995-01-01) AND (#48 OR #49) AND (#50 OR #51) AND ((#48 AND #51) OR (#49 AND #50)) // { arity: 52 }
  528. Map ((#41{n_name} = "FRANCE"), (#41{n_name} = "GERMANY"), (#45{n_name} = "FRANCE"), (#45{n_name} = "GERMANY")) // { arity: 52 }
  529. Join on=(#0{s_suppkey} = #9{l_suppkey} AND #3{s_nationkey} = #40{n_nationkey} AND #7{l_orderkey} = #23{o_orderkey} AND #24{o_custkey} = #32{c_custkey} AND #35{c_nationkey} = #44{n_nationkey}) type=delta // { arity: 48 }
  530. implementation
  531. %0:supplier » %4:l0[#0{n_nationkey}]KAef » %1:lineitem[#2{l_suppkey}]KAiif » %2:orders[#0{o_orderkey}]KA » %3:customer[#0{c_custkey}]KA » %5:l0[#0{n_nationkey}]KAef
  532. %1:lineitem » %0:supplier[#0{s_suppkey}]KA » %4:l0[#0{n_nationkey}]KAef » %2:orders[#0{o_orderkey}]KA » %3:customer[#0{c_custkey}]KA » %5:l0[#0{n_nationkey}]KAef
  533. %2:orders » %1:lineitem[#0{l_orderkey}]KAiif » %0:supplier[#0{s_suppkey}]KA » %4:l0[#0{n_nationkey}]KAef » %3:customer[#0{c_custkey}]KA » %5:l0[#0{n_nationkey}]KAef
  534. %3:customer » %5:l0[#0{n_nationkey}]KAef » %2:orders[#1{o_custkey}]KA » %1:lineitem[#0{l_orderkey}]KAiif » %0:supplier[#0{s_suppkey}]KA » %4:l0[#0{n_nationkey}]KAef
  535. %4:l0 » %0:supplier[#3{s_nationkey}]KA » %1:lineitem[#2{l_suppkey}]KAiif » %2:orders[#0{o_orderkey}]KA » %3:customer[#0{c_custkey}]KA » %5:l0[#0{n_nationkey}]KAef
  536. %5:l0 » %3:customer[#3{c_nationkey}]KA » %2:orders[#1{o_custkey}]KA » %1:lineitem[#0{l_orderkey}]KAiif » %0:supplier[#0{s_suppkey}]KA » %4:l0[#0{n_nationkey}]KAef
  537. ArrangeBy keys=[[#0{s_suppkey}], [#3{s_nationkey}]] // { arity: 7 }
  538. ReadIndex on=supplier pk_supplier_suppkey=[delta join 1st input (full scan)] fk_supplier_nationkey=[delta join lookup] // { arity: 7 }
  539. ArrangeBy keys=[[#0{l_orderkey}], [#2{l_suppkey}]] // { arity: 16 }
  540. ReadIndex on=lineitem fk_lineitem_orderkey=[delta join lookup] fk_lineitem_suppkey=[delta join lookup] // { arity: 16 }
  541. ArrangeBy keys=[[#0{o_orderkey}], [#1{o_custkey}]] // { arity: 9 }
  542. ReadIndex on=orders pk_orders_orderkey=[delta join lookup] fk_orders_custkey=[delta join lookup] // { arity: 9 }
  543. ArrangeBy keys=[[#0{c_custkey}], [#3{c_nationkey}]] // { arity: 8 }
  544. ReadIndex on=customer pk_customer_custkey=[delta join lookup] fk_customer_nationkey=[delta join lookup] // { arity: 8 }
  545. Get l0 // { arity: 4 }
  546. Get l0 // { arity: 4 }
  547. Used Indexes:
  548. - materialize.public.pk_nation_nationkey (delta join lookup)
  549. - materialize.public.pk_supplier_suppkey (delta join 1st input (full scan))
  550. - materialize.public.fk_supplier_nationkey (delta join lookup)
  551. - materialize.public.pk_customer_custkey (delta join lookup)
  552. - materialize.public.fk_customer_nationkey (delta join lookup)
  553. - materialize.public.pk_orders_orderkey (delta join lookup)
  554. - materialize.public.fk_orders_custkey (delta join lookup)
  555. - materialize.public.fk_lineitem_orderkey (delta join lookup)
  556. - materialize.public.fk_lineitem_suppkey (delta join lookup)
  557. Target cluster: quickstart
  558. EOF
  559. query T multiline
  560. -- Query 08
  561. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  562. SELECT
  563. o_year,
  564. sum(case
  565. when nation = 'BRAZIL' then volume
  566. else 0
  567. end) / sum(volume) AS mkt_share
  568. FROM
  569. (
  570. SELECT
  571. extract(year FROM o_orderdate) AS o_year,
  572. l_extendedprice * (1 - l_discount) AS volume,
  573. n2.n_name AS nation
  574. FROM
  575. part,
  576. supplier,
  577. lineitem,
  578. orders,
  579. customer,
  580. nation n1,
  581. nation n2,
  582. region
  583. WHERE
  584. p_partkey = l_partkey
  585. AND s_suppkey = l_suppkey
  586. AND l_orderkey = o_orderkey
  587. AND o_custkey = c_custkey
  588. AND c_nationkey = n1.n_nationkey
  589. AND n1.n_regionkey = r_regionkey
  590. AND r_name = 'AMERICA'
  591. AND s_nationkey = n2.n_nationkey
  592. AND o_orderdate BETWEEN DATE '1995-01-01' AND DATE '1996-12-31'
  593. AND p_type = 'ECONOMY ANODIZED STEEL'
  594. ) AS all_nations
  595. GROUP BY
  596. o_year
  597. ORDER BY
  598. o_year;
  599. ----
  600. Explained Query:
  601. Finish order_by=[#0 asc nulls_last] output=[#0, #1]
  602. Project (#0, #3) // { arity: 2 }
  603. Map ((#1{sum} / #2{sum})) // { arity: 4 }
  604. Reduce group_by=[extract_year_d(#2{o_orderdate})] aggregates=[sum(case when (#3{n_name} = "BRAZIL") then (#0{l_extendedprice} * (1 - #1{l_discount})) else 0 end), sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 3 }
  605. Project (#21{l_extendedprice}, #22{l_discount}, #36{o_orderdate}, #54{n_name}) // { arity: 4 }
  606. Filter (#58{r_name} = "AMERICA") AND (#36{o_orderdate} <= 1996-12-31) AND (#36{o_orderdate} >= 1995-01-01) AND ("ECONOMY ANODIZED STEEL" = varchar_to_text(#4{p_type})) // { arity: 60 }
  607. Join on=(#0{p_partkey} = #17{l_partkey} AND #9{s_suppkey} = #18{l_suppkey} AND #12{s_nationkey} = #53{n_nationkey} AND #16{l_orderkey} = #32{o_orderkey} AND #33{o_custkey} = #41{c_custkey} AND #44{c_nationkey} = #49{n_nationkey} AND #51{n_regionkey} = #57{r_regionkey}) type=delta // { arity: 60 }
  608. implementation
  609. %0:part » %2:lineitem[#1{l_partkey}]KA » %3:orders[#0{o_orderkey}]KAiif » %1:supplier[#0{s_suppkey}]KA » %4:customer[#0{c_custkey}]KA » %5:nation[#0{n_nationkey}]KA » %7:region[#0{r_regionkey}]KAef » %6:nation[#0{n_nationkey}]KA
  610. %1:supplier » %2:lineitem[#2{l_suppkey}]KA » %0:part[#0{p_partkey}]KAef » %3:orders[#0{o_orderkey}]KAiif » %4:customer[#0{c_custkey}]KA » %5:nation[#0{n_nationkey}]KA » %7:region[#0{r_regionkey}]KAef » %6:nation[#0{n_nationkey}]KA
  611. %2:lineitem » %0:part[#0{p_partkey}]KAef » %3:orders[#0{o_orderkey}]KAiif » %1:supplier[#0{s_suppkey}]KA » %4:customer[#0{c_custkey}]KA » %5:nation[#0{n_nationkey}]KA » %7:region[#0{r_regionkey}]KAef » %6:nation[#0{n_nationkey}]KA
  612. %3:orders » %2:lineitem[#0{l_orderkey}]KA » %0:part[#0{p_partkey}]KAef » %1:supplier[#0{s_suppkey}]KA » %4:customer[#0{c_custkey}]KA » %5:nation[#0{n_nationkey}]KA » %7:region[#0{r_regionkey}]KAef » %6:nation[#0{n_nationkey}]KA
  613. %4:customer » %3:orders[#1{o_custkey}]KAiif » %2:lineitem[#0{l_orderkey}]KA » %0:part[#0{p_partkey}]KAef » %1:supplier[#0{s_suppkey}]KA » %5:nation[#0{n_nationkey}]KA » %7:region[#0{r_regionkey}]KAef » %6:nation[#0{n_nationkey}]KA
  614. %5:nation » %7:region[#0{r_regionkey}]KAef » %4:customer[#3{c_nationkey}]KA » %3:orders[#1{o_custkey}]KAiif » %2:lineitem[#0{l_orderkey}]KA » %0:part[#0{p_partkey}]KAef » %1:supplier[#0{s_suppkey}]KA » %6:nation[#0{n_nationkey}]KA
  615. %6:nation » %1:supplier[#3{s_nationkey}]KA » %2:lineitem[#2{l_suppkey}]KA » %0:part[#0{p_partkey}]KAef » %3:orders[#0{o_orderkey}]KAiif » %4:customer[#0{c_custkey}]KA » %5:nation[#0{n_nationkey}]KA » %7:region[#0{r_regionkey}]KAef
  616. %7:region » %5:nation[#2{n_regionkey}]KA » %4:customer[#3{c_nationkey}]KA » %3:orders[#1{o_custkey}]KAiif » %2:lineitem[#0{l_orderkey}]KA » %0:part[#0{p_partkey}]KAef » %1:supplier[#0{s_suppkey}]KA » %6:nation[#0{n_nationkey}]KA
  617. ArrangeBy keys=[[#0{p_partkey}]] // { arity: 9 }
  618. ReadIndex on=part pk_part_partkey=[delta join 1st input (full scan)] // { arity: 9 }
  619. ArrangeBy keys=[[#0{s_suppkey}], [#3{s_nationkey}]] // { arity: 7 }
  620. ReadIndex on=supplier pk_supplier_suppkey=[delta join lookup] fk_supplier_nationkey=[delta join lookup] // { arity: 7 }
  621. ArrangeBy keys=[[#0{l_orderkey}], [#1{l_partkey}], [#2{l_suppkey}]] // { arity: 16 }
  622. ReadIndex on=lineitem fk_lineitem_orderkey=[delta join lookup] fk_lineitem_partkey=[delta join lookup] fk_lineitem_suppkey=[delta join lookup] // { arity: 16 }
  623. ArrangeBy keys=[[#0{o_orderkey}], [#1{o_custkey}]] // { arity: 9 }
  624. ReadIndex on=orders pk_orders_orderkey=[delta join lookup] fk_orders_custkey=[delta join lookup] // { arity: 9 }
  625. ArrangeBy keys=[[#0{c_custkey}], [#3{c_nationkey}]] // { arity: 8 }
  626. ReadIndex on=customer pk_customer_custkey=[delta join lookup] fk_customer_nationkey=[delta join lookup] // { arity: 8 }
  627. ArrangeBy keys=[[#0{n_nationkey}], [#2{n_regionkey}]] // { arity: 4 }
  628. ReadIndex on=nation pk_nation_nationkey=[delta join lookup] fk_nation_regionkey=[delta join lookup] // { arity: 4 }
  629. ArrangeBy keys=[[#0{n_nationkey}]] // { arity: 4 }
  630. ReadIndex on=nation pk_nation_nationkey=[delta join lookup] // { arity: 4 }
  631. ArrangeBy keys=[[#0{r_regionkey}]] // { arity: 3 }
  632. ReadIndex on=region pk_region_regionkey=[delta join lookup] // { arity: 3 }
  633. Used Indexes:
  634. - materialize.public.pk_nation_nationkey (delta join lookup)
  635. - materialize.public.fk_nation_regionkey (delta join lookup)
  636. - materialize.public.pk_region_regionkey (delta join lookup)
  637. - materialize.public.pk_part_partkey (delta join 1st input (full scan))
  638. - materialize.public.pk_supplier_suppkey (delta join lookup)
  639. - materialize.public.fk_supplier_nationkey (delta join lookup)
  640. - materialize.public.pk_customer_custkey (delta join lookup)
  641. - materialize.public.fk_customer_nationkey (delta join lookup)
  642. - materialize.public.pk_orders_orderkey (delta join lookup)
  643. - materialize.public.fk_orders_custkey (delta join lookup)
  644. - materialize.public.fk_lineitem_orderkey (delta join lookup)
  645. - materialize.public.fk_lineitem_partkey (delta join lookup)
  646. - materialize.public.fk_lineitem_suppkey (delta join lookup)
  647. Target cluster: quickstart
  648. EOF
  649. query T multiline
  650. -- Query 09
  651. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  652. SELECT
  653. nation,
  654. o_year,
  655. sum(amount) AS sum_profit
  656. FROM
  657. (
  658. SELECT
  659. n_name AS nation,
  660. extract(year FROM o_orderdate) AS o_year,
  661. l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity AS amount
  662. FROM
  663. part,
  664. supplier,
  665. lineitem,
  666. partsupp,
  667. orders,
  668. nation
  669. WHERE
  670. s_suppkey = l_suppkey
  671. AND ps_suppkey = l_suppkey
  672. AND ps_partkey = l_partkey
  673. AND p_partkey = l_partkey
  674. AND o_orderkey = l_orderkey
  675. AND s_nationkey = n_nationkey
  676. AND p_name like '%green%'
  677. ) AS profit
  678. GROUP BY
  679. nation,
  680. o_year
  681. ORDER BY
  682. nation,
  683. o_year DESC;
  684. ----
  685. Explained Query:
  686. Finish order_by=[#0{n_name} asc nulls_last, #1 desc nulls_first] output=[#0..=#2]
  687. Reduce group_by=[#5{n_name}, extract_year_d(#4{o_orderdate})] aggregates=[sum(((#1{l_extendedprice} * (1 - #2{l_discount})) - (#3{ps_supplycost} * #0{l_quantity})))] // { arity: 3 }
  688. Project (#20{l_quantity}..=#22{l_discount}, #35{ps_supplycost}, #41{o_orderdate}, #47{n_name}) // { arity: 6 }
  689. Filter like["%green%"](varchar_to_text(#1{p_name})) // { arity: 50 }
  690. Join on=(#0{p_partkey} = #17{l_partkey} = #32{ps_partkey} AND #9{s_suppkey} = #18{l_suppkey} = #33{ps_suppkey} AND #12{s_nationkey} = #46{n_nationkey} AND #16{l_orderkey} = #37{o_orderkey}) type=delta // { arity: 50 }
  691. implementation
  692. %0:part » %2:lineitem[#1{l_partkey}]KA » %3:partsupp[#0{ps_partkey}, #1{ps_suppkey}]KKA » %1:supplier[#0{s_suppkey}]KA » %4:orders[#0{o_orderkey}]KA » %5:nation[#0{n_nationkey}]KA
  693. %1:supplier » %2:lineitem[#2{l_suppkey}]KA » %3:partsupp[#0{ps_partkey}, #1{ps_suppkey}]KKA » %0:part[#0{p_partkey}]KAlf » %4:orders[#0{o_orderkey}]KA » %5:nation[#0{n_nationkey}]KA
  694. %2:lineitem » %3:partsupp[#0{ps_partkey}, #1{ps_suppkey}]KKA » %0:part[#0{p_partkey}]KAlf » %1:supplier[#0{s_suppkey}]KA » %4:orders[#0{o_orderkey}]KA » %5:nation[#0{n_nationkey}]KA
  695. %3:partsupp » %2:lineitem[#1{l_partkey}, #2{l_suppkey}]KKA » %0:part[#0{p_partkey}]KAlf » %1:supplier[#0{s_suppkey}]KA » %4:orders[#0{o_orderkey}]KA » %5:nation[#0{n_nationkey}]KA
  696. %4:orders » %2:lineitem[#0{l_orderkey}]KA » %3:partsupp[#0{ps_partkey}, #1{ps_suppkey}]KKA » %0:part[#0{p_partkey}]KAlf » %1:supplier[#0{s_suppkey}]KA » %5:nation[#0{n_nationkey}]KA
  697. %5:nation » %1:supplier[#3{s_nationkey}]KA » %2:lineitem[#2{l_suppkey}]KA » %3:partsupp[#0{ps_partkey}, #1{ps_suppkey}]KKA » %0:part[#0{p_partkey}]KAlf » %4:orders[#0{o_orderkey}]KA
  698. ArrangeBy keys=[[#0{p_partkey}]] // { arity: 9 }
  699. ReadIndex on=part pk_part_partkey=[delta join 1st input (full scan)] // { arity: 9 }
  700. ArrangeBy keys=[[#0{s_suppkey}], [#3{s_nationkey}]] // { arity: 7 }
  701. ReadIndex on=supplier pk_supplier_suppkey=[delta join lookup] fk_supplier_nationkey=[delta join lookup] // { arity: 7 }
  702. ArrangeBy keys=[[#0{l_orderkey}], [#1{l_partkey}], [#1{l_partkey}, #2{l_suppkey}], [#2{l_suppkey}]] // { arity: 16 }
  703. ReadIndex on=lineitem fk_lineitem_orderkey=[delta join lookup] fk_lineitem_partkey=[delta join lookup] fk_lineitem_suppkey=[delta join lookup] fk_lineitem_partsuppkey=[delta join lookup] // { arity: 16 }
  704. ArrangeBy keys=[[#0{ps_partkey}, #1{ps_suppkey}]] // { arity: 5 }
  705. ReadIndex on=partsupp pk_partsupp_partkey_suppkey=[delta join lookup] // { arity: 5 }
  706. ArrangeBy keys=[[#0{o_orderkey}]] // { arity: 9 }
  707. ReadIndex on=orders pk_orders_orderkey=[delta join lookup] // { arity: 9 }
  708. ArrangeBy keys=[[#0{n_nationkey}]] // { arity: 4 }
  709. ReadIndex on=nation pk_nation_nationkey=[delta join lookup] // { arity: 4 }
  710. Used Indexes:
  711. - materialize.public.pk_nation_nationkey (delta join lookup)
  712. - materialize.public.pk_part_partkey (delta join 1st input (full scan))
  713. - materialize.public.pk_supplier_suppkey (delta join lookup)
  714. - materialize.public.fk_supplier_nationkey (delta join lookup)
  715. - materialize.public.pk_partsupp_partkey_suppkey (delta join lookup)
  716. - materialize.public.pk_orders_orderkey (delta join lookup)
  717. - materialize.public.fk_lineitem_orderkey (delta join lookup)
  718. - materialize.public.fk_lineitem_partkey (delta join lookup)
  719. - materialize.public.fk_lineitem_suppkey (delta join lookup)
  720. - materialize.public.fk_lineitem_partsuppkey (delta join lookup)
  721. Target cluster: quickstart
  722. EOF
  723. query T multiline
  724. -- Query 10
  725. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  726. SELECT
  727. c_custkey,
  728. c_name,
  729. sum(l_extendedprice * (1 - l_discount)) AS revenue,
  730. c_acctbal,
  731. n_name,
  732. c_address,
  733. c_phone,
  734. c_comment
  735. FROM
  736. customer,
  737. orders,
  738. lineitem,
  739. nation
  740. WHERE
  741. c_custkey = o_custkey
  742. AND l_orderkey = o_orderkey
  743. AND o_orderdate >= DATE '1993-10-01'
  744. AND o_orderdate < DATE '1994-01-01'
  745. AND o_orderdate < DATE '1993-10-01' + INTERVAL '3' month
  746. AND l_returnflag = 'R'
  747. AND c_nationkey = n_nationkey
  748. GROUP BY
  749. c_custkey,
  750. c_name,
  751. c_acctbal,
  752. c_phone,
  753. n_name,
  754. c_address,
  755. c_comment
  756. ORDER BY
  757. revenue DESC;
  758. ----
  759. Explained Query:
  760. Finish order_by=[#2{sum} desc nulls_first] output=[#0..=#7]
  761. Project (#0{c_custkey}, #1{c_name}, #7{sum}, #2{c_acctbal}, #4{n_name}, #5{c_address}, #3{c_phone}, #6{c_comment}) // { arity: 8 }
  762. Reduce group_by=[#0{c_custkey}, #1{c_name}, #4{c_acctbal}, #3{c_phone}, #8{n_name}, #2{c_address}, #5{c_comment}] aggregates=[sum((#6{l_extendedprice} * (1 - #7{l_discount})))] // { arity: 8 }
  763. Project (#0{c_custkey}..=#2{c_address}, #4{c_phone}, #5{c_acctbal}, #7{c_comment}, #22{l_extendedprice}, #23{l_discount}, #34{n_name}) // { arity: 9 }
  764. Filter (#25{l_returnflag} = "R") AND (#12{o_orderdate} < 1994-01-01) AND (#12{o_orderdate} >= 1993-10-01) AND (date_to_timestamp(#12{o_orderdate}) < 1994-01-01 00:00:00) // { arity: 37 }
  765. Join on=(#0{c_custkey} = #9{o_custkey} AND #3{c_nationkey} = #33{n_nationkey} AND #8{o_orderkey} = #17{l_orderkey}) type=delta // { arity: 37 }
  766. implementation
  767. %0:customer » %1:orders[#1{o_custkey}]KAiiif » %2:lineitem[#0{l_orderkey}]KAef » %3:nation[#0{n_nationkey}]KA
  768. %1:orders » %2:lineitem[#0{l_orderkey}]KAef » %0:customer[#0{c_custkey}]KA » %3:nation[#0{n_nationkey}]KA
  769. %2:lineitem » %1:orders[#0{o_orderkey}]KAiiif » %0:customer[#0{c_custkey}]KA » %3:nation[#0{n_nationkey}]KA
  770. %3:nation » %0:customer[#3{c_nationkey}]KA » %1:orders[#1{o_custkey}]KAiiif » %2:lineitem[#0{l_orderkey}]KAef
  771. ArrangeBy keys=[[#0{c_custkey}], [#3{c_nationkey}]] // { arity: 8 }
  772. ReadIndex on=customer pk_customer_custkey=[delta join 1st input (full scan)] fk_customer_nationkey=[delta join lookup] // { arity: 8 }
  773. ArrangeBy keys=[[#0{o_orderkey}], [#1{o_custkey}]] // { arity: 9 }
  774. ReadIndex on=orders pk_orders_orderkey=[delta join lookup] fk_orders_custkey=[delta join lookup] // { arity: 9 }
  775. ArrangeBy keys=[[#0{l_orderkey}]] // { arity: 16 }
  776. ReadIndex on=lineitem fk_lineitem_orderkey=[delta join lookup] // { arity: 16 }
  777. ArrangeBy keys=[[#0{n_nationkey}]] // { arity: 4 }
  778. ReadIndex on=nation pk_nation_nationkey=[delta join lookup] // { arity: 4 }
  779. Used Indexes:
  780. - materialize.public.pk_nation_nationkey (delta join lookup)
  781. - materialize.public.pk_customer_custkey (delta join 1st input (full scan))
  782. - materialize.public.fk_customer_nationkey (delta join lookup)
  783. - materialize.public.pk_orders_orderkey (delta join lookup)
  784. - materialize.public.fk_orders_custkey (delta join lookup)
  785. - materialize.public.fk_lineitem_orderkey (delta join lookup)
  786. Target cluster: quickstart
  787. EOF
  788. query T multiline
  789. -- Query 11
  790. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  791. SELECT
  792. ps_partkey,
  793. sum(ps_supplycost * ps_availqty) AS value
  794. FROM
  795. partsupp,
  796. supplier,
  797. nation
  798. WHERE
  799. ps_suppkey = s_suppkey
  800. AND s_nationkey = n_nationkey
  801. AND n_name = 'GERMANY'
  802. GROUP BY
  803. ps_partkey having
  804. sum(ps_supplycost * ps_availqty) > (
  805. SELECT
  806. sum(ps_supplycost * ps_availqty) * 0.0001
  807. FROM
  808. partsupp,
  809. supplier,
  810. nation
  811. WHERE
  812. ps_suppkey = s_suppkey
  813. AND s_nationkey = n_nationkey
  814. AND n_name = 'GERMANY'
  815. )
  816. ORDER BY
  817. value DESC;
  818. ----
  819. Explained Query:
  820. Finish order_by=[#1{sum} desc nulls_first] output=[#0, #1]
  821. With
  822. cte l0 =
  823. Project (#0{ps_partkey}, #2{ps_availqty}, #3{ps_supplycost}) // { arity: 3 }
  824. Filter (#13{n_name} = "GERMANY") // { arity: 16 }
  825. Join on=(#1{ps_suppkey} = #5{s_suppkey} AND #8{s_nationkey} = #12{n_nationkey}) type=delta // { arity: 16 }
  826. implementation
  827. %0:partsupp » %1:supplier[#0{s_suppkey}]KA » %2:nation[#0{n_nationkey}]KAef
  828. %1:supplier » %2:nation[#0{n_nationkey}]KAef » %0:partsupp[#1{ps_suppkey}]KA
  829. %2:nation » %1:supplier[#3{s_nationkey}]KA » %0:partsupp[#1{ps_suppkey}]KA
  830. ArrangeBy keys=[[#1{ps_suppkey}]] // { arity: 5 }
  831. ReadIndex on=partsupp fk_partsupp_suppkey=[delta join 1st input (full scan)] // { arity: 5 }
  832. ArrangeBy keys=[[#0{s_suppkey}], [#3{s_nationkey}]] // { arity: 7 }
  833. ReadIndex on=supplier pk_supplier_suppkey=[delta join lookup] fk_supplier_nationkey=[delta join lookup] // { arity: 7 }
  834. ArrangeBy keys=[[#0{n_nationkey}]] // { arity: 4 }
  835. ReadIndex on=nation pk_nation_nationkey=[delta join lookup] // { arity: 4 }
  836. Return // { arity: 2 }
  837. Project (#0{ps_partkey}, #1{sum}) // { arity: 2 }
  838. Filter (#1{sum} > (#2{sum} * 0.0001)) // { arity: 3 }
  839. CrossJoin type=differential // { arity: 3 }
  840. implementation
  841. %1[×]UA » %0[×]
  842. ArrangeBy keys=[[]] // { arity: 2 }
  843. Reduce group_by=[#0{ps_partkey}] aggregates=[sum((#2{ps_supplycost} * integer_to_numeric(#1{ps_availqty})))] // { arity: 2 }
  844. Get l0 // { arity: 3 }
  845. ArrangeBy keys=[[]] // { arity: 1 }
  846. Reduce aggregates=[sum((#1{ps_supplycost} * integer_to_numeric(#0{ps_availqty})))] // { arity: 1 }
  847. Project (#1{ps_availqty}, #2{ps_supplycost}) // { arity: 2 }
  848. Get l0 // { arity: 3 }
  849. Used Indexes:
  850. - materialize.public.pk_nation_nationkey (delta join lookup)
  851. - materialize.public.pk_supplier_suppkey (delta join lookup)
  852. - materialize.public.fk_supplier_nationkey (delta join lookup)
  853. - materialize.public.fk_partsupp_suppkey (delta join 1st input (full scan))
  854. Target cluster: quickstart
  855. EOF
  856. query T multiline
  857. -- Query 12
  858. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  859. SELECT
  860. l_shipmode,
  861. sum(case
  862. when o_orderpriority = '1-URGENT'
  863. or o_orderpriority = '2-HIGH'
  864. then 1
  865. else 0
  866. end) AS high_line_count,
  867. sum(case
  868. when o_orderpriority <> '1-URGENT'
  869. AND o_orderpriority <> '2-HIGH'
  870. then 1
  871. else 0
  872. end) AS low_line_count
  873. FROM
  874. orders,
  875. lineitem
  876. WHERE
  877. o_orderkey = l_orderkey
  878. AND l_shipmode IN ('MAIL', 'SHIP')
  879. AND l_commitdate < l_receiptdate
  880. AND l_shipdate < l_commitdate
  881. AND l_receiptdate >= DATE '1994-01-01'
  882. AND l_receiptdate < DATE '1994-01-01' + INTERVAL '1' year
  883. GROUP BY
  884. l_shipmode
  885. ORDER BY
  886. l_shipmode;
  887. ----
  888. Explained Query:
  889. Finish order_by=[#0{l_shipmode} asc nulls_last] output=[#0..=#2]
  890. Reduce group_by=[#1{l_shipmode}] aggregates=[sum(case when ((#0{o_orderpriority} = "2-HIGH") OR (#0{o_orderpriority} = "1-URGENT")) then 1 else 0 end), sum(case when ((#0{o_orderpriority} != "2-HIGH") AND (#0{o_orderpriority} != "1-URGENT")) then 1 else 0 end)] // { arity: 3 }
  891. Project (#5{o_orderpriority}, #23{l_shipmode}) // { arity: 2 }
  892. Filter (#21{l_receiptdate} >= 1994-01-01) AND (#19{l_shipdate} < #20{l_commitdate}) AND (#20{l_commitdate} < #21{l_receiptdate}) AND (date_to_timestamp(#21{l_receiptdate}) < 1995-01-01 00:00:00) AND ((#23{l_shipmode} = "MAIL") OR (#23{l_shipmode} = "SHIP")) // { arity: 25 }
  893. Join on=(#0{o_orderkey} = #9{l_orderkey}) type=differential // { arity: 25 }
  894. implementation
  895. %1:lineitem[#0{l_orderkey}]KAeiif » %0:orders[#0{o_orderkey}]KAeiif
  896. ArrangeBy keys=[[#0{o_orderkey}]] // { arity: 9 }
  897. ReadIndex on=orders pk_orders_orderkey=[differential join] // { arity: 9 }
  898. ArrangeBy keys=[[#0{l_orderkey}]] // { arity: 16 }
  899. ReadIndex on=lineitem fk_lineitem_orderkey=[differential join] // { arity: 16 }
  900. Used Indexes:
  901. - materialize.public.pk_orders_orderkey (differential join)
  902. - materialize.public.fk_lineitem_orderkey (differential join)
  903. Target cluster: quickstart
  904. EOF
  905. query T multiline
  906. -- Query 13
  907. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  908. SELECT
  909. c_count,
  910. count(*) AS custdist
  911. FROM
  912. (
  913. SELECT
  914. c_custkey,
  915. count(o_orderkey) c_count -- workaround for no column aliases
  916. FROM
  917. customer LEFT OUTER JOIN orders ON
  918. c_custkey = o_custkey
  919. AND o_comment NOT LIKE '%special%requests%'
  920. GROUP BY
  921. c_custkey
  922. ) AS c_orders -- (c_custkey, c_count) -- no column aliases yet
  923. GROUP BY
  924. c_count
  925. ORDER BY
  926. custdist DESC,
  927. c_count DESC;
  928. ----
  929. Explained Query:
  930. Finish order_by=[#1{count} desc nulls_first, #0{count_o_orderkey} desc nulls_first] output=[#0, #1]
  931. With
  932. cte l0 =
  933. ArrangeBy keys=[[#0{c_custkey}]] // { arity: 8 }
  934. ReadIndex on=customer pk_customer_custkey=[differential join] // { arity: 8 }
  935. cte l1 =
  936. Project (#0{c_custkey}, #8{o_orderkey}) // { arity: 2 }
  937. Filter NOT(like["%special%requests%"](varchar_to_text(#16{o_comment}))) // { arity: 17 }
  938. Join on=(#0{c_custkey} = #9{o_custkey}) type=differential // { arity: 17 }
  939. implementation
  940. %1:orders[#1{o_custkey}]KAf » %0:l0[#0{c_custkey}]KAf
  941. Get l0 // { arity: 8 }
  942. ArrangeBy keys=[[#1{o_custkey}]] // { arity: 9 }
  943. ReadIndex on=orders fk_orders_custkey=[differential join] // { arity: 9 }
  944. Return // { arity: 2 }
  945. Reduce group_by=[#0{count_o_orderkey}] aggregates=[count(*)] // { arity: 2 }
  946. Project (#1{count_o_orderkey}) // { arity: 1 }
  947. Reduce group_by=[#0{c_custkey}] aggregates=[count(#1{o_orderkey})] // { arity: 2 }
  948. Union // { arity: 2 }
  949. Map (null) // { arity: 2 }
  950. Union // { arity: 1 }
  951. Negate // { arity: 1 }
  952. Project (#0{c_custkey}) // { arity: 1 }
  953. Join on=(#0{c_custkey} = #8{c_custkey}) type=differential // { arity: 9 }
  954. implementation
  955. %1[#0]UKA » %0:l0[#0{c_custkey}]KA
  956. Get l0 // { arity: 8 }
  957. ArrangeBy keys=[[#0{c_custkey}]] // { arity: 1 }
  958. Distinct project=[#0{c_custkey}] // { arity: 1 }
  959. Project (#0{c_custkey}) // { arity: 1 }
  960. Get l1 // { arity: 2 }
  961. Project (#0{c_custkey}) // { arity: 1 }
  962. ReadIndex on=customer pk_customer_custkey=[*** full scan ***] // { arity: 8 }
  963. Get l1 // { arity: 2 }
  964. Used Indexes:
  965. - materialize.public.pk_customer_custkey (*** full scan ***, differential join)
  966. - materialize.public.fk_orders_custkey (differential join)
  967. Target cluster: quickstart
  968. EOF
  969. query T multiline
  970. -- Query 14
  971. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  972. SELECT
  973. 100.00 * sum(case
  974. when p_type like 'PROMO%'
  975. then l_extendedprice * (1 - l_discount)
  976. else 0
  977. end) / sum(l_extendedprice * (1 - l_discount)) AS promo_revenue
  978. FROM
  979. lineitem,
  980. part
  981. WHERE
  982. l_partkey = p_partkey
  983. AND l_shipdate >= DATE '1995-09-01'
  984. AND l_shipdate < DATE '1995-09-01' + INTERVAL '1' month;
  985. ----
  986. Explained Query:
  987. With
  988. cte l0 =
  989. Reduce aggregates=[sum(case when like["PROMO%"](varchar_to_text(#2{p_type})) then (#0{l_extendedprice} * (1 - #1{l_discount})) else 0 end), sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 2 }
  990. Project (#5{l_extendedprice}, #6{l_discount}, #20{p_type}) // { arity: 3 }
  991. Filter (#10{l_shipdate} >= 1995-09-01) AND (date_to_timestamp(#10{l_shipdate}) < 1995-10-01 00:00:00) // { arity: 25 }
  992. Join on=(#1{l_partkey} = #16{p_partkey}) type=differential // { arity: 25 }
  993. implementation
  994. %0:lineitem[#1{l_partkey}]KAiif » %1:part[#0{p_partkey}]KAiif
  995. ArrangeBy keys=[[#1{l_partkey}]] // { arity: 16 }
  996. ReadIndex on=lineitem fk_lineitem_partkey=[differential join] // { arity: 16 }
  997. ArrangeBy keys=[[#0{p_partkey}]] // { arity: 9 }
  998. ReadIndex on=part pk_part_partkey=[differential join] // { arity: 9 }
  999. Return // { arity: 1 }
  1000. Project (#2) // { arity: 1 }
  1001. Map (((100 * #0{sum}) / #1{sum})) // { arity: 3 }
  1002. Union // { arity: 2 }
  1003. Get l0 // { arity: 2 }
  1004. Map (null, null) // { arity: 2 }
  1005. Union // { arity: 0 }
  1006. Negate // { arity: 0 }
  1007. Project () // { arity: 0 }
  1008. Get l0 // { arity: 2 }
  1009. Constant // { arity: 0 }
  1010. - ()
  1011. Used Indexes:
  1012. - materialize.public.pk_part_partkey (differential join)
  1013. - materialize.public.fk_lineitem_partkey (differential join)
  1014. Target cluster: quickstart
  1015. EOF
  1016. statement ok
  1017. create view revenue (supplier_no, total_revenue) as
  1018. SELECT
  1019. l_suppkey,
  1020. sum(l_extendedprice * (1 - l_discount))
  1021. FROM
  1022. lineitem
  1023. WHERE
  1024. l_shipdate >= DATE '1996-01-01'
  1025. AND l_shipdate < DATE '1996-01-01' + INTERVAL '3' month
  1026. GROUP BY
  1027. l_suppkey
  1028. query T multiline
  1029. -- Query 15
  1030. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  1031. SELECT
  1032. s_suppkey,
  1033. s_name,
  1034. s_address,
  1035. s_phone,
  1036. total_revenue
  1037. FROM
  1038. supplier,
  1039. revenue
  1040. WHERE
  1041. s_suppkey = supplier_no
  1042. AND total_revenue = (
  1043. SELECT
  1044. max(total_revenue)
  1045. FROM
  1046. revenue
  1047. )
  1048. ORDER BY
  1049. s_suppkey;
  1050. ----
  1051. Explained Query:
  1052. Finish order_by=[#0{s_suppkey} asc nulls_last] output=[#0..=#4]
  1053. With
  1054. cte l0 =
  1055. Reduce group_by=[#0{l_suppkey}] aggregates=[sum((#1{l_extendedprice} * (1 - #2{l_discount})))] // { arity: 2 }
  1056. Project (#2{l_suppkey}, #5{l_extendedprice}, #6{l_discount}) // { arity: 3 }
  1057. Filter (#10{l_shipdate} >= 1996-01-01) AND (date_to_timestamp(#10{l_shipdate}) < 1996-04-01 00:00:00) // { arity: 16 }
  1058. ReadIndex on=lineitem pk_lineitem_orderkey_linenumber=[*** full scan ***] // { arity: 16 }
  1059. Return // { arity: 5 }
  1060. Project (#0{s_suppkey}..=#2{s_address}, #4{s_phone}, #8{sum}) // { arity: 5 }
  1061. Join on=(#0{s_suppkey} = #7{l_suppkey} AND #8{sum} = #9{max_sum}) type=delta // { arity: 10 }
  1062. implementation
  1063. %0:supplier » %1:l0[#0]UKA » %2[#0]UK
  1064. %1:l0 » %2[#0]UK » %0:supplier[#0{s_suppkey}]KA
  1065. %2 » %1:l0[#1{total_revenue}]K » %0:supplier[#0{s_suppkey}]KA
  1066. ArrangeBy keys=[[#0{s_suppkey}]] // { arity: 7 }
  1067. ReadIndex on=supplier pk_supplier_suppkey=[delta join 1st input (full scan)] // { arity: 7 }
  1068. ArrangeBy keys=[[#0{l_suppkey}], [#1{sum}]] // { arity: 2 }
  1069. Get l0 // { arity: 2 }
  1070. ArrangeBy keys=[[#0{max_sum}]] // { arity: 1 }
  1071. Reduce aggregates=[max(#0{sum})] // { arity: 1 }
  1072. Project (#1{sum}) // { arity: 1 }
  1073. Get l0 // { arity: 2 }
  1074. Used Indexes:
  1075. - materialize.public.pk_supplier_suppkey (delta join 1st input (full scan))
  1076. - materialize.public.pk_lineitem_orderkey_linenumber (*** full scan ***)
  1077. Target cluster: quickstart
  1078. EOF
  1079. statement ok
  1080. drop view revenue
  1081. query T multiline
  1082. -- Query 16
  1083. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  1084. SELECT
  1085. p_brand,
  1086. p_type,
  1087. p_size,
  1088. count(DISTINCT ps_suppkey) AS supplier_cnt
  1089. FROM
  1090. partsupp,
  1091. part
  1092. WHERE
  1093. p_partkey = ps_partkey
  1094. AND p_brand <> 'Brand#45'
  1095. AND p_type NOT LIKE 'MEDIUM POLISHED%'
  1096. AND p_size IN (49, 14, 23, 45, 19, 3, 36, 9)
  1097. AND ps_suppkey NOT IN (
  1098. SELECT
  1099. s_suppkey
  1100. FROM
  1101. supplier
  1102. WHERE
  1103. s_comment like '%Customer%Complaints%'
  1104. )
  1105. GROUP BY
  1106. p_brand,
  1107. p_type,
  1108. p_size
  1109. ORDER BY
  1110. supplier_cnt DESC,
  1111. p_brand,
  1112. p_type,
  1113. p_size;
  1114. ----
  1115. Explained Query:
  1116. Finish order_by=[#3{count_ps_suppkey} desc nulls_first, #0{p_brand} asc nulls_last, #1{p_type} asc nulls_last, #2{p_size} asc nulls_last] output=[#0..=#3]
  1117. With
  1118. cte l0 =
  1119. Project (#1{ps_suppkey}, #8{p_brand}..=#10{p_size}) // { arity: 4 }
  1120. Filter (#8{p_brand} != "Brand#45") AND NOT(like["MEDIUM POLISHED%"](varchar_to_text(#9{p_type}))) AND ((#10{p_size} = 3) OR (#10{p_size} = 9) OR (#10{p_size} = 14) OR (#10{p_size} = 19) OR (#10{p_size} = 23) OR (#10{p_size} = 36) OR (#10{p_size} = 45) OR (#10{p_size} = 49)) // { arity: 14 }
  1121. Join on=(#0{ps_partkey} = #5{p_partkey}) type=differential // { arity: 14 }
  1122. implementation
  1123. %1:part[#0{p_partkey}]KAef » %0:partsupp[#0{ps_partkey}]KAef
  1124. ArrangeBy keys=[[#0{ps_partkey}]] // { arity: 5 }
  1125. ReadIndex on=partsupp fk_partsupp_partkey=[differential join] // { arity: 5 }
  1126. ArrangeBy keys=[[#0{p_partkey}]] // { arity: 9 }
  1127. ReadIndex on=part pk_part_partkey=[differential join] // { arity: 9 }
  1128. cte l1 =
  1129. Distinct project=[#0{ps_suppkey}] // { arity: 1 }
  1130. Project (#0{ps_suppkey}) // { arity: 1 }
  1131. Get l0 // { arity: 4 }
  1132. Return // { arity: 4 }
  1133. Reduce group_by=[#1{p_brand}..=#3{p_size}] aggregates=[count(distinct #0{ps_suppkey})] // { arity: 4 }
  1134. Project (#0{ps_suppkey}..=#3{p_size}) // { arity: 4 }
  1135. Join on=(#0{ps_suppkey} = #4{ps_suppkey}) type=differential // { arity: 5 }
  1136. implementation
  1137. %0:l0[#0]K » %1[#0]K
  1138. ArrangeBy keys=[[#0{ps_suppkey}]] // { arity: 4 }
  1139. Get l0 // { arity: 4 }
  1140. ArrangeBy keys=[[#0{ps_suppkey}]] // { arity: 1 }
  1141. Union // { arity: 1 }
  1142. Negate // { arity: 1 }
  1143. Distinct project=[#0{ps_suppkey}] // { arity: 1 }
  1144. Project (#0{ps_suppkey}) // { arity: 1 }
  1145. Filter ((#1{s_suppkey}) IS NULL OR (#0{ps_suppkey} = #1{s_suppkey})) // { arity: 2 }
  1146. CrossJoin type=differential // { arity: 2 }
  1147. implementation
  1148. %1:supplier[×]lf » %0:l1[×]lf
  1149. ArrangeBy keys=[[]] // { arity: 1 }
  1150. Get l1 // { arity: 1 }
  1151. ArrangeBy keys=[[]] // { arity: 1 }
  1152. Project (#0{s_suppkey}) // { arity: 1 }
  1153. Filter like["%Customer%Complaints%"](varchar_to_text(#6{s_comment})) // { arity: 7 }
  1154. ReadIndex on=supplier pk_supplier_suppkey=[*** full scan ***] // { arity: 7 }
  1155. Get l1 // { arity: 1 }
  1156. Used Indexes:
  1157. - materialize.public.pk_part_partkey (differential join)
  1158. - materialize.public.pk_supplier_suppkey (*** full scan ***)
  1159. - materialize.public.fk_partsupp_partkey (differential join)
  1160. Target cluster: quickstart
  1161. EOF
  1162. query T multiline
  1163. -- Query 17
  1164. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  1165. SELECT
  1166. sum(l_extendedprice) / 7.0 AS avg_yearly
  1167. FROM
  1168. lineitem,
  1169. part
  1170. WHERE
  1171. p_partkey = l_partkey
  1172. AND p_brand = 'Brand#23'
  1173. AND p_container = 'MED BOX'
  1174. AND l_quantity < (
  1175. SELECT
  1176. 0.2 * avg(l_quantity)
  1177. FROM
  1178. lineitem
  1179. WHERE
  1180. l_partkey = p_partkey
  1181. );
  1182. ----
  1183. Explained Query:
  1184. With
  1185. cte l0 =
  1186. ArrangeBy keys=[[#1{l_partkey}]] // { arity: 16 }
  1187. ReadIndex on=lineitem fk_lineitem_partkey=[differential join] // { arity: 16 }
  1188. cte l1 =
  1189. Project (#1{l_partkey}, #4{l_quantity}, #5{l_extendedprice}) // { arity: 3 }
  1190. Filter (#19{p_brand} = "Brand#23") AND (#22{p_container} = "MED BOX") // { arity: 25 }
  1191. Join on=(#1{l_partkey} = #16{p_partkey}) type=differential // { arity: 25 }
  1192. implementation
  1193. %1:part[#0{p_partkey}]KAef » %0:l0[#1{l_partkey}]KAef
  1194. Get l0 // { arity: 16 }
  1195. ArrangeBy keys=[[#0{p_partkey}]] // { arity: 9 }
  1196. ReadIndex on=part pk_part_partkey=[differential join] // { arity: 9 }
  1197. cte l2 =
  1198. Reduce aggregates=[sum(#0{l_extendedprice})] // { arity: 1 }
  1199. Project (#2{l_extendedprice}) // { arity: 1 }
  1200. Filter (#1{l_quantity} < (0.2 * (#4{sum_l_quantity} / bigint_to_numeric(case when (#5{count} = 0) then null else #5{count} end)))) // { arity: 6 }
  1201. Join on=(#0{l_partkey} = #3{l_partkey}) type=differential // { arity: 6 }
  1202. implementation
  1203. %1[#0]UKA » %0:l1[#0]K
  1204. ArrangeBy keys=[[#0{l_partkey}]] // { arity: 3 }
  1205. Get l1 // { arity: 3 }
  1206. ArrangeBy keys=[[#0{l_partkey}]] // { arity: 3 }
  1207. Reduce group_by=[#0{l_partkey}] aggregates=[sum(#1{l_quantity}), count(*)] // { arity: 3 }
  1208. Project (#0{l_partkey}, #5{l_quantity}) // { arity: 2 }
  1209. Join on=(#0{l_partkey} = #2{l_partkey}) type=differential // { arity: 17 }
  1210. implementation
  1211. %0[#0{p_partkey}]UKA » %1:l0[#1{l_partkey}]KA
  1212. ArrangeBy keys=[[#0{l_partkey}]] // { arity: 1 }
  1213. Distinct project=[#0{l_partkey}] // { arity: 1 }
  1214. Project (#0{l_partkey}) // { arity: 1 }
  1215. Get l1 // { arity: 3 }
  1216. Get l0 // { arity: 16 }
  1217. Return // { arity: 1 }
  1218. Project (#1) // { arity: 1 }
  1219. Map ((#0{sum_l_extendedprice} / 7)) // { arity: 2 }
  1220. Union // { arity: 1 }
  1221. Get l2 // { arity: 1 }
  1222. Map (null) // { arity: 1 }
  1223. Union // { arity: 0 }
  1224. Negate // { arity: 0 }
  1225. Project () // { arity: 0 }
  1226. Get l2 // { arity: 1 }
  1227. Constant // { arity: 0 }
  1228. - ()
  1229. Used Indexes:
  1230. - materialize.public.pk_part_partkey (differential join)
  1231. - materialize.public.fk_lineitem_partkey (differential join)
  1232. Target cluster: quickstart
  1233. EOF
  1234. query T multiline
  1235. -- Query 18
  1236. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  1237. SELECT
  1238. c_name,
  1239. c_custkey,
  1240. o_orderkey,
  1241. o_orderdate,
  1242. o_totalprice,
  1243. sum(l_quantity)
  1244. FROM
  1245. customer,
  1246. orders,
  1247. lineitem
  1248. WHERE
  1249. o_orderkey IN (
  1250. SELECT
  1251. l_orderkey
  1252. FROM
  1253. lineitem
  1254. GROUP BY
  1255. l_orderkey having
  1256. sum(l_quantity) > 300
  1257. )
  1258. AND c_custkey = o_custkey
  1259. AND o_orderkey = l_orderkey
  1260. GROUP BY
  1261. c_name,
  1262. c_custkey,
  1263. o_orderkey,
  1264. o_orderdate,
  1265. o_totalprice
  1266. ORDER BY
  1267. o_totalprice DESC,
  1268. o_orderdate;
  1269. ----
  1270. Explained Query:
  1271. Finish order_by=[#4{o_totalprice} desc nulls_first, #3{o_orderdate} asc nulls_last] output=[#0..=#5]
  1272. With
  1273. cte l0 =
  1274. ArrangeBy keys=[[#0{l_orderkey}]] // { arity: 16 }
  1275. ReadIndex on=lineitem fk_lineitem_orderkey=[differential join, delta join lookup] // { arity: 16 }
  1276. cte l1 =
  1277. Project (#0{c_custkey}, #1{c_name}, #8{o_orderkey}, #11{o_totalprice}, #12{o_orderdate}, #21{l_quantity}) // { arity: 6 }
  1278. Join on=(#0{c_custkey} = #9{o_custkey} AND #8{o_orderkey} = #17{l_orderkey}) type=delta // { arity: 33 }
  1279. implementation
  1280. %0:customer » %1:orders[#1{o_custkey}]KA » %2:l0[#0{l_orderkey}]KA
  1281. %1:orders » %0:customer[#0{c_custkey}]KA » %2:l0[#0{l_orderkey}]KA
  1282. %2:l0 » %1:orders[#0{o_orderkey}]KA » %0:customer[#0{c_custkey}]KA
  1283. ArrangeBy keys=[[#0{c_custkey}]] // { arity: 8 }
  1284. ReadIndex on=customer pk_customer_custkey=[delta join 1st input (full scan)] // { arity: 8 }
  1285. ArrangeBy keys=[[#0{o_orderkey}], [#1{o_custkey}]] // { arity: 9 }
  1286. ReadIndex on=orders pk_orders_orderkey=[delta join lookup] fk_orders_custkey=[delta join lookup] // { arity: 9 }
  1287. Get l0 // { arity: 16 }
  1288. Return // { arity: 6 }
  1289. Reduce group_by=[#1{c_name}, #0{c_custkey}, #2{o_orderkey}, #4{o_orderdate}, #3{o_totalprice}] aggregates=[sum(#5{l_quantity})] // { arity: 6 }
  1290. Project (#0{c_custkey}..=#5{l_quantity}) // { arity: 6 }
  1291. Filter (#7{sum_l_quantity} > 300) // { arity: 8 }
  1292. Join on=(#2{o_orderkey} = #6{o_orderkey}) type=differential // { arity: 8 }
  1293. implementation
  1294. %1[#0]UKAif » %0:l1[#2]Kif
  1295. ArrangeBy keys=[[#2{o_orderkey}]] // { arity: 6 }
  1296. Get l1 // { arity: 6 }
  1297. ArrangeBy keys=[[#0{o_orderkey}]] // { arity: 2 }
  1298. Reduce group_by=[#0{o_orderkey}] aggregates=[sum(#1{l_quantity})] // { arity: 2 }
  1299. Project (#0{o_orderkey}, #5{l_quantity}) // { arity: 2 }
  1300. Join on=(#0{o_orderkey} = #1{l_orderkey}) type=differential // { arity: 17 }
  1301. implementation
  1302. %0[#0]UKA » %1:l0[#0{l_orderkey}]KA
  1303. ArrangeBy keys=[[#0{o_orderkey}]] // { arity: 1 }
  1304. Distinct project=[#0{o_orderkey}] // { arity: 1 }
  1305. Project (#2{o_orderkey}) // { arity: 1 }
  1306. Get l1 // { arity: 6 }
  1307. Get l0 // { arity: 16 }
  1308. Used Indexes:
  1309. - materialize.public.pk_customer_custkey (delta join 1st input (full scan))
  1310. - materialize.public.pk_orders_orderkey (delta join lookup)
  1311. - materialize.public.fk_orders_custkey (delta join lookup)
  1312. - materialize.public.fk_lineitem_orderkey (differential join, delta join lookup)
  1313. Target cluster: quickstart
  1314. EOF
  1315. query T multiline
  1316. -- Query 19
  1317. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  1318. SELECT
  1319. sum(l_extendedprice* (1 - l_discount)) AS revenue
  1320. FROM
  1321. lineitem,
  1322. part
  1323. WHERE
  1324. (
  1325. p_partkey = l_partkey
  1326. AND p_brand = 'Brand#12'
  1327. AND p_container IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')
  1328. AND l_quantity >= CAST (1 AS smallint) AND l_quantity <= CAST (1 + 10 AS smallint)
  1329. AND p_size BETWEEN CAST (1 AS smallint) AND CAST (5 AS smallint)
  1330. AND l_shipmode IN ('AIR', 'AIR REG')
  1331. AND l_shipinstruct = 'DELIVER IN PERSON'
  1332. )
  1333. or
  1334. (
  1335. p_partkey = l_partkey
  1336. AND p_brand = 'Brand#23'
  1337. AND p_container IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')
  1338. AND l_quantity >= CAST (10 AS smallint) AND l_quantity <= CAST (10 + 10 AS smallint)
  1339. AND p_size BETWEEN CAST (1 AS smallint) AND CAST (10 AS smallint)
  1340. AND l_shipmode IN ('AIR', 'AIR REG')
  1341. AND l_shipinstruct = 'DELIVER IN PERSON'
  1342. )
  1343. or
  1344. (
  1345. p_partkey = l_partkey
  1346. AND p_brand = 'Brand#34'
  1347. AND p_container IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')
  1348. AND l_quantity >= CAST (20 AS smallint) AND l_quantity <= CAST (20 + 10 AS smallint)
  1349. AND p_size BETWEEN CAST (1 AS smallint) AND CAST (15 AS smallint)
  1350. AND l_shipmode IN ('AIR', 'AIR REG')
  1351. AND l_shipinstruct = 'DELIVER IN PERSON'
  1352. );
  1353. ----
  1354. Explained Query:
  1355. With
  1356. cte l0 =
  1357. Reduce aggregates=[sum((#0{l_extendedprice} * (1 - #1{l_discount})))] // { arity: 1 }
  1358. Project (#5{l_extendedprice}, #6{l_discount}) // { arity: 2 }
  1359. Filter (#13{l_shipinstruct} = "DELIVER IN PERSON") AND (#21{p_size} >= 1) AND ((#14{l_shipmode} = "AIR") OR (#14{l_shipmode} = "AIR REG")) AND ((#25 AND #26) OR (#27 AND #28) OR (#29 AND #30)) AND ((#31 AND #32 AND #33) OR (#34 AND #35 AND #36) OR (#37 AND #38 AND #39)) AND ((#25 AND #26 AND #34 AND #35 AND #36) OR (#27 AND #28 AND #37 AND #38 AND #39) OR (#29 AND #30 AND #31 AND #32 AND #33)) // { arity: 40 }
  1360. Map ((#4{l_quantity} <= 20), (#4{l_quantity} >= 10), (#4{l_quantity} <= 30), (#4{l_quantity} >= 20), (#4{l_quantity} <= 11), (#4{l_quantity} >= 1), (#19{p_brand} = "Brand#12"), (#21{p_size} <= 5), ((#22{p_container} = "SM BOX") OR (#22{p_container} = "SM PKG") OR (#22{p_container} = "SM CASE") OR (#22{p_container} = "SM PACK")), (#19{p_brand} = "Brand#23"), (#21{p_size} <= 10), ((#22{p_container} = "MED BAG") OR (#22{p_container} = "MED BOX") OR (#22{p_container} = "MED PKG") OR (#22{p_container} = "MED PACK")), (#19{p_brand} = "Brand#34"), (#21{p_size} <= 15), ((#22{p_container} = "LG BOX") OR (#22{p_container} = "LG PKG") OR (#22{p_container} = "LG CASE") OR (#22{p_container} = "LG PACK"))) // { arity: 40 }
  1361. Join on=(#1{l_partkey} = #16{p_partkey}) type=differential // { arity: 25 }
  1362. implementation
  1363. %1:part[#0{p_partkey}]KAeiiif » %0:lineitem[#1{l_partkey}]KAeiiiiif
  1364. ArrangeBy keys=[[#1{l_partkey}]] // { arity: 16 }
  1365. ReadIndex on=lineitem fk_lineitem_partkey=[differential join] // { arity: 16 }
  1366. ArrangeBy keys=[[#0{p_partkey}]] // { arity: 9 }
  1367. ReadIndex on=part pk_part_partkey=[differential join] // { arity: 9 }
  1368. Return // { arity: 1 }
  1369. Union // { arity: 1 }
  1370. Get l0 // { arity: 1 }
  1371. Map (null) // { arity: 1 }
  1372. Union // { arity: 0 }
  1373. Negate // { arity: 0 }
  1374. Project () // { arity: 0 }
  1375. Get l0 // { arity: 1 }
  1376. Constant // { arity: 0 }
  1377. - ()
  1378. Used Indexes:
  1379. - materialize.public.pk_part_partkey (differential join)
  1380. - materialize.public.fk_lineitem_partkey (differential join)
  1381. Target cluster: quickstart
  1382. EOF
  1383. query T multiline
  1384. -- Query 20
  1385. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  1386. SELECT
  1387. s_name,
  1388. s_address
  1389. FROM
  1390. supplier,
  1391. nation
  1392. WHERE
  1393. s_suppkey IN (
  1394. SELECT
  1395. ps_suppkey
  1396. FROM
  1397. partsupp
  1398. WHERE
  1399. ps_partkey IN (
  1400. SELECT
  1401. p_partkey
  1402. FROM
  1403. part
  1404. WHERE
  1405. p_name like 'forest%'
  1406. )
  1407. AND ps_availqty > (
  1408. SELECT
  1409. 0.5 * sum(l_quantity)
  1410. FROM
  1411. lineitem
  1412. WHERE
  1413. l_partkey = ps_partkey
  1414. AND l_suppkey = ps_suppkey
  1415. AND l_shipdate >= DATE '1995-01-01'
  1416. AND l_shipdate < DATE '1995-01-01' + INTERVAL '1' year
  1417. )
  1418. )
  1419. AND s_nationkey = n_nationkey
  1420. AND n_name = 'CANADA'
  1421. ORDER BY
  1422. s_name;
  1423. ----
  1424. Explained Query:
  1425. Finish order_by=[#0{s_name} asc nulls_last] output=[#0, #1]
  1426. With
  1427. cte l0 =
  1428. Project (#0{s_suppkey}..=#2{s_address}) // { arity: 3 }
  1429. Filter (#8{n_name} = "CANADA") // { arity: 11 }
  1430. Join on=(#3{s_nationkey} = #7{n_nationkey}) type=differential // { arity: 11 }
  1431. implementation
  1432. %1:nation[#0{n_nationkey}]KAef » %0:supplier[#3{s_nationkey}]KAef
  1433. ArrangeBy keys=[[#3{s_nationkey}]] // { arity: 7 }
  1434. ReadIndex on=supplier fk_supplier_nationkey=[differential join] // { arity: 7 }
  1435. ArrangeBy keys=[[#0{n_nationkey}]] // { arity: 4 }
  1436. ReadIndex on=nation pk_nation_nationkey=[differential join] // { arity: 4 }
  1437. cte l1 =
  1438. Project (#0{s_suppkey}..=#3{ps_availqty}) // { arity: 4 }
  1439. Join on=(#1{ps_partkey} = #4{p_partkey}) type=delta // { arity: 5 }
  1440. implementation
  1441. %0 » %1:partsupp[×] » %2[#0]UKA
  1442. %1:partsupp » %2[#0]UKA » %0[×]
  1443. %2 » %1:partsupp[#0{ps_partkey}]KA » %0[×]
  1444. ArrangeBy keys=[[]] // { arity: 1 }
  1445. Distinct project=[#0{s_suppkey}] // { arity: 1 }
  1446. Project (#0{s_suppkey}) // { arity: 1 }
  1447. Get l0 // { arity: 3 }
  1448. ArrangeBy keys=[[], [#0{ps_partkey}]] // { arity: 3 }
  1449. Project (#0{ps_partkey}..=#2{ps_availqty}) // { arity: 3 }
  1450. ReadIndex on=partsupp pk_partsupp_partkey_suppkey=[*** full scan ***] // { arity: 5 }
  1451. ArrangeBy keys=[[#0{p_partkey}]] // { arity: 1 }
  1452. Distinct project=[#0{p_partkey}] // { arity: 1 }
  1453. Project (#0{p_partkey}) // { arity: 1 }
  1454. Filter (#0{p_partkey}) IS NOT NULL AND like["forest%"](varchar_to_text(#1{p_name})) // { arity: 9 }
  1455. ReadIndex on=part pk_part_partkey=[*** full scan ***] // { arity: 9 }
  1456. Return // { arity: 2 }
  1457. Project (#1{s_name}, #2{s_address}) // { arity: 2 }
  1458. Join on=(#0{s_suppkey} = #3{s_suppkey}) type=differential // { arity: 4 }
  1459. implementation
  1460. %1[#0]UKA » %0:l0[#0]K
  1461. ArrangeBy keys=[[#0{s_suppkey}]] // { arity: 3 }
  1462. Get l0 // { arity: 3 }
  1463. ArrangeBy keys=[[#0{s_suppkey}]] // { arity: 1 }
  1464. Distinct project=[#0{s_suppkey}] // { arity: 1 }
  1465. Project (#0{s_suppkey}) // { arity: 1 }
  1466. Filter (integer_to_numeric(#2{ps_availqty}) > #5) // { arity: 6 }
  1467. Join on=(#0{s_suppkey} = #4{ps_suppkey} AND #1{ps_partkey} = #3{ps_partkey}) type=differential // { arity: 6 }
  1468. implementation
  1469. %1[#1, #0]UKK » %0:l1[#0{s_suppkey}, #1]KKf
  1470. ArrangeBy keys=[[#0{s_suppkey}, #1{ps_partkey}]] // { arity: 3 }
  1471. Project (#0{s_suppkey}, #1{ps_partkey}, #3{ps_availqty}) // { arity: 3 }
  1472. Filter (#0{s_suppkey} = #2{ps_suppkey}) // { arity: 4 }
  1473. Get l1 // { arity: 4 }
  1474. ArrangeBy keys=[[#1{ps_suppkey}, #0{ps_partkey}]] // { arity: 3 }
  1475. Project (#0{ps_partkey}, #1{ps_suppkey}, #3) // { arity: 3 }
  1476. Map ((0.5 * #2{sum_l_quantity})) // { arity: 4 }
  1477. Reduce group_by=[#0{ps_partkey}, #1{ps_suppkey}] aggregates=[sum(#2{l_quantity})] // { arity: 3 }
  1478. Project (#0{ps_partkey}, #1{ps_suppkey}, #6{l_quantity}) // { arity: 3 }
  1479. Filter (#12{l_shipdate} >= 1995-01-01) AND (date_to_timestamp(#12{l_shipdate}) < 1996-01-01 00:00:00) // { arity: 18 }
  1480. Join on=(#0{ps_partkey} = #3{l_partkey} AND #1{ps_suppkey} = #4{l_suppkey}) type=differential // { arity: 18 }
  1481. implementation
  1482. %0[#0{ps_partkey}, #1{ps_suppkey}]UKKA » %1:lineitem[#1{l_partkey}, #2{l_suppkey}]KKAiif
  1483. ArrangeBy keys=[[#0{ps_partkey}, #1{ps_suppkey}]] // { arity: 2 }
  1484. Distinct project=[#0{ps_partkey}, #1{ps_suppkey}] // { arity: 2 }
  1485. Project (#1{ps_partkey}, #2{ps_suppkey}) // { arity: 2 }
  1486. Get l1 // { arity: 4 }
  1487. ArrangeBy keys=[[#1{l_partkey}, #2{l_suppkey}]] // { arity: 16 }
  1488. ReadIndex on=lineitem fk_lineitem_partsuppkey=[differential join] // { arity: 16 }
  1489. Used Indexes:
  1490. - materialize.public.pk_nation_nationkey (differential join)
  1491. - materialize.public.pk_part_partkey (*** full scan ***)
  1492. - materialize.public.fk_supplier_nationkey (differential join)
  1493. - materialize.public.pk_partsupp_partkey_suppkey (*** full scan ***)
  1494. - materialize.public.fk_lineitem_partsuppkey (differential join)
  1495. Target cluster: quickstart
  1496. EOF
  1497. query T multiline
  1498. -- Query 21
  1499. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  1500. SELECT
  1501. s_name,
  1502. count(*) AS numwait
  1503. FROM
  1504. supplier,
  1505. lineitem l1,
  1506. orders,
  1507. nation
  1508. WHERE
  1509. s_suppkey = l1.l_suppkey
  1510. AND o_orderkey = l1.l_orderkey
  1511. AND o_orderstatus = 'F'
  1512. AND l1.l_receiptdate > l1.l_commitdate
  1513. AND EXISTS (
  1514. SELECT
  1515. *
  1516. FROM
  1517. lineitem l2
  1518. WHERE
  1519. l2.l_orderkey = l1.l_orderkey
  1520. AND l2.l_suppkey <> l1.l_suppkey
  1521. )
  1522. AND not EXISTS (
  1523. SELECT
  1524. *
  1525. FROM
  1526. lineitem l3
  1527. WHERE
  1528. l3.l_orderkey = l1.l_orderkey
  1529. AND l3.l_suppkey <> l1.l_suppkey
  1530. AND l3.l_receiptdate > l3.l_commitdate
  1531. )
  1532. AND s_nationkey = n_nationkey
  1533. AND n_name = 'SAUDI ARABIA'
  1534. GROUP BY
  1535. s_name
  1536. ORDER BY
  1537. numwait DESC,
  1538. s_name;
  1539. ----
  1540. Explained Query:
  1541. Finish order_by=[#1{count} desc nulls_first, #0{s_name} asc nulls_last] output=[#0, #1]
  1542. With
  1543. cte l0 =
  1544. Project (#0{s_suppkey}, #1{s_name}, #7{l_orderkey}) // { arity: 3 }
  1545. Filter (#25{o_orderstatus} = "F") AND (#33{n_name} = "SAUDI ARABIA") AND (#19{l_receiptdate} > #18{l_commitdate}) // { arity: 36 }
  1546. Join on=(#0{s_suppkey} = #9{l_suppkey} AND #3{s_nationkey} = #32{n_nationkey} AND #7{l_orderkey} = #23{o_orderkey}) type=delta // { arity: 36 }
  1547. implementation
  1548. %0:supplier » %3:nation[#0{n_nationkey}]KAef » %1:lineitem[#2{l_suppkey}]KAf » %2:orders[#0{o_orderkey}]KAef
  1549. %1:lineitem » %2:orders[#0{o_orderkey}]KAef » %0:supplier[#0{s_suppkey}]KA » %3:nation[#0{n_nationkey}]KAef
  1550. %2:orders » %1:lineitem[#0{l_orderkey}]KAf » %0:supplier[#0{s_suppkey}]KA » %3:nation[#0{n_nationkey}]KAef
  1551. %3:nation » %0:supplier[#3{s_nationkey}]KA » %1:lineitem[#2{l_suppkey}]KAf » %2:orders[#0{o_orderkey}]KAef
  1552. ArrangeBy keys=[[#0{s_suppkey}], [#3{s_nationkey}]] // { arity: 7 }
  1553. ReadIndex on=supplier pk_supplier_suppkey=[delta join 1st input (full scan)] fk_supplier_nationkey=[delta join lookup] // { arity: 7 }
  1554. ArrangeBy keys=[[#0{l_orderkey}], [#2{l_suppkey}]] // { arity: 16 }
  1555. ReadIndex on=lineitem fk_lineitem_orderkey=[delta join lookup] fk_lineitem_suppkey=[delta join lookup] // { arity: 16 }
  1556. ArrangeBy keys=[[#0{o_orderkey}]] // { arity: 9 }
  1557. ReadIndex on=orders pk_orders_orderkey=[delta join lookup] // { arity: 9 }
  1558. ArrangeBy keys=[[#0{n_nationkey}]] // { arity: 4 }
  1559. ReadIndex on=nation pk_nation_nationkey=[delta join lookup] // { arity: 4 }
  1560. cte l1 =
  1561. ArrangeBy keys=[[#0{l_orderkey}]] // { arity: 16 }
  1562. ReadIndex on=lineitem fk_lineitem_orderkey=[differential join] // { arity: 16 }
  1563. cte l2 =
  1564. Project (#0{s_suppkey}..=#2{l_orderkey}) // { arity: 3 }
  1565. Join on=(#0{s_suppkey} = #4{s_suppkey} AND #2{l_orderkey} = #3{l_orderkey}) type=differential // { arity: 5 }
  1566. implementation
  1567. %1[#1, #0]UKK » %0:l0[#0, #2]KK
  1568. ArrangeBy keys=[[#0{s_suppkey}, #2{l_orderkey}]] // { arity: 3 }
  1569. Get l0 // { arity: 3 }
  1570. ArrangeBy keys=[[#1{s_suppkey}, #0{l_orderkey}]] // { arity: 2 }
  1571. Distinct project=[#0{l_orderkey}, #1{s_suppkey}] // { arity: 2 }
  1572. Project (#0{l_orderkey}, #1{s_suppkey}) // { arity: 2 }
  1573. Filter (#1{s_suppkey} != #4{l_suppkey}) // { arity: 18 }
  1574. Join on=(#0{l_orderkey} = #2{l_orderkey}) type=differential // { arity: 18 }
  1575. implementation
  1576. %1:l1[#0{l_orderkey}]KA » %0[#0{l_orderkey}]K
  1577. ArrangeBy keys=[[#0{l_orderkey}]] // { arity: 2 }
  1578. Distinct project=[#1{l_orderkey}, #0{s_suppkey}] // { arity: 2 }
  1579. Project (#0{s_suppkey}, #2{l_orderkey}) // { arity: 2 }
  1580. Get l0 // { arity: 3 }
  1581. Get l1 // { arity: 16 }
  1582. cte l3 =
  1583. Distinct project=[#1{l_orderkey}, #0{s_suppkey}] // { arity: 2 }
  1584. Project (#0{s_suppkey}, #2{l_orderkey}) // { arity: 2 }
  1585. Get l2 // { arity: 3 }
  1586. Return // { arity: 2 }
  1587. Reduce group_by=[#0{s_name}] aggregates=[count(*)] // { arity: 2 }
  1588. Project (#1{s_name}) // { arity: 1 }
  1589. Join on=(#0{s_suppkey} = #4{s_suppkey} AND #2{l_orderkey} = #3{l_orderkey}) type=differential // { arity: 5 }
  1590. implementation
  1591. %0:l2[#2, #0]KK » %1[#0, #1]KK
  1592. ArrangeBy keys=[[#2{l_orderkey}, #0{s_suppkey}]] // { arity: 3 }
  1593. Get l2 // { arity: 3 }
  1594. ArrangeBy keys=[[#0{l_orderkey}, #1{s_suppkey}]] // { arity: 2 }
  1595. Union // { arity: 2 }
  1596. Negate // { arity: 2 }
  1597. Distinct project=[#0{l_orderkey}, #1{s_suppkey}] // { arity: 2 }
  1598. Project (#0{l_orderkey}, #1{s_suppkey}) // { arity: 2 }
  1599. Filter (#1{s_suppkey} != #4{l_suppkey}) AND (#14{l_receiptdate} > #13{l_commitdate}) // { arity: 18 }
  1600. Join on=(#0{l_orderkey} = #2{l_orderkey}) type=differential // { arity: 18 }
  1601. implementation
  1602. %1:l1[#0{l_orderkey}]KAf » %0:l3[#0{l_orderkey}]Kf
  1603. ArrangeBy keys=[[#0{l_orderkey}]] // { arity: 2 }
  1604. Get l3 // { arity: 2 }
  1605. Get l1 // { arity: 16 }
  1606. Get l3 // { arity: 2 }
  1607. Used Indexes:
  1608. - materialize.public.pk_nation_nationkey (delta join lookup)
  1609. - materialize.public.pk_supplier_suppkey (delta join 1st input (full scan))
  1610. - materialize.public.fk_supplier_nationkey (delta join lookup)
  1611. - materialize.public.pk_orders_orderkey (delta join lookup)
  1612. - materialize.public.fk_lineitem_orderkey (differential join, delta join lookup)
  1613. - materialize.public.fk_lineitem_suppkey (delta join lookup)
  1614. Target cluster: quickstart
  1615. EOF
  1616. query T multiline
  1617. -- Query 22
  1618. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  1619. SELECT
  1620. cntrycode,
  1621. count(*) AS numcust,
  1622. sum(c_acctbal) AS totacctbal
  1623. FROM
  1624. (
  1625. SELECT
  1626. substring(c_phone, 1, 2) AS cntrycode, c_acctbal
  1627. FROM
  1628. customer
  1629. WHERE
  1630. substring(c_phone, 1, 2)
  1631. IN ('13', '31', '23', '29', '30', '18', '17')
  1632. AND c_acctbal
  1633. > (
  1634. SELECT
  1635. avg(c_acctbal)
  1636. FROM
  1637. customer
  1638. WHERE
  1639. c_acctbal > 0.00
  1640. AND substring(c_phone, 1, 2)
  1641. IN (
  1642. '13',
  1643. '31',
  1644. '23',
  1645. '29',
  1646. '30',
  1647. '18',
  1648. '17'
  1649. )
  1650. )
  1651. AND NOT
  1652. EXISTS(
  1653. SELECT
  1654. *
  1655. FROM
  1656. orders
  1657. WHERE
  1658. o_custkey = c_custkey
  1659. )
  1660. )
  1661. AS custsale
  1662. GROUP BY
  1663. cntrycode
  1664. ORDER BY
  1665. cntrycode;
  1666. ----
  1667. Explained Query:
  1668. Finish order_by=[#0 asc nulls_last] output=[#0..=#2]
  1669. With
  1670. cte l0 =
  1671. Project (#0{c_custkey}, #4{c_phone}, #5{c_acctbal}, #8) // { arity: 4 }
  1672. Map (substr(char_to_text(#4{c_phone}), 1, 2)) // { arity: 9 }
  1673. ReadIndex on=customer pk_customer_custkey=[*** full scan ***] // { arity: 8 }
  1674. cte l1 =
  1675. Project (#0{c_custkey}..=#2{c_acctbal}) // { arity: 3 }
  1676. Filter (#2{c_acctbal} > (#3{sum_c_acctbal} / bigint_to_numeric(case when (#4{count} = 0) then null else #4{count} end))) // { arity: 5 }
  1677. CrossJoin type=differential // { arity: 5 }
  1678. implementation
  1679. %1[×]UA » %0:l0[×]ef
  1680. ArrangeBy keys=[[]] // { arity: 3 }
  1681. Project (#0{c_custkey}..=#2{c_acctbal}) // { arity: 3 }
  1682. Filter ((#3 = "13") OR (#3 = "17") OR (#3 = "18") OR (#3 = "23") OR (#3 = "29") OR (#3 = "30") OR (#3 = "31")) // { arity: 4 }
  1683. Get l0 // { arity: 4 }
  1684. ArrangeBy keys=[[]] // { arity: 2 }
  1685. Reduce aggregates=[sum(#0{c_acctbal}), count(*)] // { arity: 2 }
  1686. Project (#2{c_acctbal}) // { arity: 1 }
  1687. Filter (#2{c_acctbal} > 0) AND ((#3 = "13") OR (#3 = "17") OR (#3 = "18") OR (#3 = "23") OR (#3 = "29") OR (#3 = "30") OR (#3 = "31")) // { arity: 4 }
  1688. Get l0 // { arity: 4 }
  1689. cte l2 =
  1690. Distinct project=[#0{c_custkey}] // { arity: 1 }
  1691. Project (#0{c_custkey}) // { arity: 1 }
  1692. Get l1 // { arity: 3 }
  1693. Return // { arity: 3 }
  1694. Reduce group_by=[substr(char_to_text(#0{c_phone}), 1, 2)] aggregates=[count(*), sum(#1{c_acctbal})] // { arity: 3 }
  1695. Project (#1{c_phone}, #2{c_acctbal}) // { arity: 2 }
  1696. Join on=(#0{c_custkey} = #3{c_custkey}) type=differential // { arity: 4 }
  1697. implementation
  1698. %0:l1[#0]K » %1[#0]K
  1699. ArrangeBy keys=[[#0{c_custkey}]] // { arity: 3 }
  1700. Get l1 // { arity: 3 }
  1701. ArrangeBy keys=[[#0{c_custkey}]] // { arity: 1 }
  1702. Union // { arity: 1 }
  1703. Negate // { arity: 1 }
  1704. Project (#0{c_custkey}) // { arity: 1 }
  1705. Join on=(#0{c_custkey} = #1{o_custkey}) type=differential // { arity: 2 }
  1706. implementation
  1707. %0:l2[#0]UKA » %1[#0]UKA
  1708. ArrangeBy keys=[[#0{c_custkey}]] // { arity: 1 }
  1709. Get l2 // { arity: 1 }
  1710. ArrangeBy keys=[[#0{o_custkey}]] // { arity: 1 }
  1711. Distinct project=[#0{o_custkey}] // { arity: 1 }
  1712. Project (#1{o_custkey}) // { arity: 1 }
  1713. ReadIndex on=orders pk_orders_orderkey=[*** full scan ***] // { arity: 9 }
  1714. Get l2 // { arity: 1 }
  1715. Used Indexes:
  1716. - materialize.public.pk_customer_custkey (*** full scan ***)
  1717. - materialize.public.pk_orders_orderkey (*** full scan ***)
  1718. Target cluster: quickstart
  1719. EOF
  1720. ################################################################################
  1721. # end of optimized plans - below here is a sampling of other plan info
  1722. ################################################################################
  1723. query T multiline
  1724. -- Query 20
  1725. EXPLAIN RAW PLAN FOR SELECT
  1726. s_name,
  1727. s_address
  1728. FROM
  1729. supplier,
  1730. nation
  1731. WHERE
  1732. s_suppkey IN (
  1733. SELECT
  1734. ps_suppkey
  1735. FROM
  1736. partsupp
  1737. WHERE
  1738. ps_partkey IN (
  1739. SELECT
  1740. p_partkey
  1741. FROM
  1742. part
  1743. WHERE
  1744. p_name like 'forest%'
  1745. )
  1746. AND ps_availqty > (
  1747. SELECT
  1748. 0.5 * sum(l_quantity)
  1749. FROM
  1750. lineitem
  1751. WHERE
  1752. l_partkey = ps_partkey
  1753. AND l_suppkey = ps_suppkey
  1754. AND l_shipdate >= DATE '1995-01-01'
  1755. AND l_shipdate < DATE '1995-01-01' + INTERVAL '1' year
  1756. )
  1757. )
  1758. AND s_nationkey = n_nationkey
  1759. AND n_name = 'CANADA'
  1760. ORDER BY
  1761. s_name;
  1762. ----
  1763. Finish order_by=[#0 asc nulls_last] output=[#0, #1]
  1764. Project (#1, #2)
  1765. With
  1766. cte [l3 as subquery-3] =
  1767. Reduce aggregates=[any((#^0{s_suppkey} = #0{right_col0_0}))]
  1768. Project (#1)
  1769. With
  1770. cte [l2 as subquery-2] =
  1771. Project (#1)
  1772. Map ((0.5 * #0{?column?}))
  1773. Reduce aggregates=[sum(#4{l_quantity})]
  1774. Filter ((((#1{l_partkey} = #^0{ps_partkey}) AND (#2{l_suppkey} = #^1{ps_suppkey})) AND (#10{l_shipdate} >= text_to_date("1995-01-01"))) AND (date_to_timestamp(#10{l_shipdate}) < (text_to_date("1995-01-01") + 1 year)))
  1775. Get materialize.public.lineitem
  1776. cte [l1 as subquery-1] =
  1777. Reduce aggregates=[any((#^0{ps_partkey} = #0{right_col0_2}))]
  1778. Project (#0)
  1779. Filter (varchar_to_text(#1{p_name}) like "forest%")
  1780. Get materialize.public.part
  1781. Return
  1782. Filter (select(Get l1) AND (integer_to_numeric(#2{ps_availqty}) > select(Get l2)))
  1783. Get materialize.public.partsupp
  1784. Return
  1785. Filter ((select(Get l3) AND (#3{s_nationkey} = #7{n_nationkey})) AND (#8{n_name} = text_to_char[len=unbounded]("CANADA")))
  1786. CrossJoin
  1787. Get materialize.public.supplier
  1788. Get materialize.public.nation
  1789. Target cluster: quickstart
  1790. EOF