tpch_create_materialized_view.slt 85 KB

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