optimized_plan_as_text.slt 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808
  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. simple conn=mz_system,user=mz_system
  10. ALTER SYSTEM SET unsafe_enable_table_keys = true
  11. ----
  12. COMPLETE 0
  13. statement ok
  14. CREATE TABLE t (
  15. a int,
  16. b int
  17. );
  18. statement ok
  19. CREATE TABLE u (
  20. c int,
  21. d int
  22. );
  23. statement ok
  24. CREATE TABLE v (
  25. e int,
  26. f int
  27. );
  28. statement ok
  29. CREATE INDEX t_a_idx ON t(a);
  30. statement ok
  31. CREATE VIEW ov AS SELECT * FROM t ORDER BY b asc, a desc LIMIT 5;
  32. statement ok
  33. CREATE VIEW iv AS
  34. SELECT * FROM t WHERE a IS NOT NULL;
  35. statement ok
  36. CREATE INDEX iv_a_idx ON iv(a);
  37. statement ok
  38. CREATE INDEX iv_b_idx ON iv(b);
  39. # This is an identical index to the above (on the same object, on the same key)
  40. statement ok
  41. CREATE INDEX iv_b_idx_2 ON iv(b);
  42. statement ok
  43. CREATE MATERIALIZED VIEW mv AS
  44. SELECT * FROM t WHERE a IS NOT NULL;
  45. statement ok
  46. CREATE MATERIALIZED VIEW non_empty_mv AS
  47. SELECT 1 as x, 2 as y;
  48. statement ok
  49. CREATE INDEX non_empty_mv_idx ON non_empty_mv(y + 7);
  50. statement ok
  51. CREATE MATERIALIZED VIEW empty_mv AS
  52. SELECT;
  53. statement ok
  54. CREATE INDEX empty_mv_idx ON empty_mv();
  55. mode cockroach
  56. # Test target cluster selection for mz_system tables without transactions.
  57. query T multiline
  58. EXPLAIN OPTIMIZED PLAN WITH(no fast path, humanized expressions) AS VERBOSE TEXT FOR
  59. SELECT * FROM mz_views;
  60. ----
  61. Explained Query:
  62. ReadIndex on=mz_views mz_views_ind=[*** full scan ***]
  63. Used Indexes:
  64. - mz_catalog.mz_views_ind (*** full scan ***)
  65. Target cluster: mz_catalog_server
  66. EOF
  67. # Test target cluster selection for mz_system tables inside a transaction.
  68. statement ok
  69. BEGIN
  70. statement ok
  71. SELECT * FROM t;
  72. query T multiline
  73. EXPLAIN OPTIMIZED PLAN WITH(no fast path, humanized expressions) AS VERBOSE TEXT FOR
  74. SELECT * FROM mz_views;
  75. ----
  76. Explained Query:
  77. ReadStorage mz_catalog.mz_views
  78. Source mz_catalog.mz_views
  79. Target cluster: quickstart
  80. EOF
  81. statement ok
  82. ROLLBACK
  83. # Test constant error.
  84. query T multiline
  85. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  86. SELECT 1 / 0
  87. ----
  88. Explained Query (fast path):
  89. Error "division by zero"
  90. Target cluster: quickstart
  91. EOF
  92. # Test constant with two elements.
  93. query T multiline
  94. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  95. (SELECT 1, 2) UNION ALL (SELECT 1, 2) UNION ALL (SELECT 3, 4)
  96. ----
  97. Explained Query (fast path):
  98. Constant
  99. - ((1, 2) x 2)
  100. - (3, 4)
  101. Target cluster: mz_catalog_server
  102. EOF
  103. # Test catalog queries (index found based on cluster auto-routing).
  104. query T multiline
  105. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR SELECT * FROM mz_internal.mz_source_status_history
  106. ----
  107. Explained Query (fast path):
  108. Project (#1{occurred_at}, #0{source_id}, #2{status}..=#5{replica_id})
  109. ReadIndex on=mz_internal.mz_source_status_history mz_source_status_history_ind=[*** full scan ***]
  110. Used Indexes:
  111. - mz_internal.mz_source_status_history_ind (*** full scan ***)
  112. Target cluster: mz_catalog_server
  113. EOF
  114. # Test fast path rendering on a non-trivial index.
  115. query T multiline
  116. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  117. SELECT * FROM non_empty_mv where y + 7 = 9
  118. ----
  119. Explained Query (fast path):
  120. Project (#1{x}, #2{y})
  121. ReadIndex on=materialize.public.non_empty_mv non_empty_mv_idx=[lookup value=(9)]
  122. Used Indexes:
  123. - materialize.public.non_empty_mv_idx (lookup)
  124. Target cluster: quickstart
  125. EOF
  126. # Test fast path rendering on an empty index on an empty relation.
  127. query T multiline
  128. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  129. SELECT * FROM empty_mv
  130. ----
  131. Explained Query (fast path):
  132. ReadIndex on=materialize.public.empty_mv empty_mv_idx=[*** full scan ***]
  133. Used Indexes:
  134. - materialize.public.empty_mv_idx (*** full scan ***)
  135. Target cluster: quickstart
  136. EOF
  137. # Test basic linear chains (fast path).
  138. query T multiline
  139. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  140. SELECT 1, a + b as c FROM iv WHERE b = 5 and a < 0 and a + b > 0
  141. ----
  142. Explained Query (fast path):
  143. Project (#4, #3)
  144. Filter (#1{a} < 0) AND ((#1{a} + #0{b}) > 0)
  145. Map ((#1{a} + 5), 1)
  146. ReadIndex on=materialize.public.iv iv_b_idx_2=[lookup value=(5)]
  147. Used Indexes:
  148. - materialize.public.iv_b_idx_2 (lookup)
  149. Target cluster: quickstart
  150. EOF
  151. # Test basic linear chains (slow path).
  152. query T multiline
  153. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  154. SELECT 1, a + b as c FROM mv WHERE a > 0 and b < 0 and a + b > 0
  155. ----
  156. Explained Query:
  157. Project (#3, #2)
  158. Filter (#1{b} < 0) AND (#0{a} > 0) AND (#2 > 0)
  159. Map ((#0{a} + #1{b}), 1)
  160. ReadStorage materialize.public.mv
  161. Source materialize.public.mv
  162. filter=((#0{a} > 0) AND (#1{b} < 0) AND ((#0{a} + #1{b}) > 0))
  163. Target cluster: quickstart
  164. EOF
  165. # Test table functions in the select clause (FlatMap).
  166. query T multiline
  167. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  168. SELECT generate_series(a, b) from t
  169. ----
  170. Explained Query:
  171. Project (#2)
  172. FlatMap generate_series(#0{a}, #1{b}, 1)
  173. ReadIndex on=t t_a_idx=[*** full scan ***]
  174. Used Indexes:
  175. - materialize.public.t_a_idx (*** full scan ***)
  176. Target cluster: quickstart
  177. EOF
  178. # Test Threshold, Union, Distinct, Negate.
  179. query T multiline
  180. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  181. SELECT a FROM t EXCEPT SELECT b FROM mv
  182. ----
  183. Explained Query:
  184. Threshold
  185. Union
  186. Distinct project=[#0{a}]
  187. Project (#0{a})
  188. ReadIndex on=t t_a_idx=[*** full scan ***]
  189. Negate
  190. Distinct project=[#0{b}]
  191. Project (#1{b})
  192. ReadStorage materialize.public.mv
  193. Source materialize.public.mv
  194. Used Indexes:
  195. - materialize.public.t_a_idx (*** full scan ***)
  196. Target cluster: quickstart
  197. EOF
  198. # Test Threshold, Union, Distinct, Negate.
  199. query T multiline
  200. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  201. SELECT a FROM t EXCEPT ALL SELECT b FROM mv
  202. ----
  203. Explained Query:
  204. Threshold
  205. Union
  206. Project (#0{a})
  207. ReadIndex on=t t_a_idx=[*** full scan ***]
  208. Negate
  209. Project (#1{b})
  210. ReadStorage materialize.public.mv
  211. Source materialize.public.mv
  212. Used Indexes:
  213. - materialize.public.t_a_idx (*** full scan ***)
  214. Target cluster: quickstart
  215. EOF
  216. # Test TopK.
  217. query T multiline
  218. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  219. SELECT * FROM ov
  220. ----
  221. Explained Query:
  222. TopK order_by=[#1{b} asc nulls_last, #0{a} desc nulls_first] limit=5
  223. ReadIndex on=t t_a_idx=[*** full scan ***]
  224. Used Indexes:
  225. - materialize.public.t_a_idx (*** full scan ***)
  226. Target cluster: quickstart
  227. EOF
  228. # Test Finish.
  229. query T multiline
  230. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  231. SELECT * FROM t ORDER BY b asc, a desc LIMIT 5
  232. ----
  233. Explained Query (fast path):
  234. Finish order_by=[#1 asc nulls_last, #0 desc nulls_first] limit=5 output=[#0, #1]
  235. ReadIndex on=materialize.public.t t_a_idx=[*** full scan ***]
  236. Used Indexes:
  237. - materialize.public.t_a_idx (*** full scan ***)
  238. Target cluster: quickstart
  239. EOF
  240. # Test Reduce (global).
  241. query T multiline
  242. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  243. SELECT abs(min(a) - max(a)) FROM t
  244. ----
  245. Explained Query:
  246. With
  247. cte l0 =
  248. Reduce aggregates=[min(#0{a}), max(#0{a})]
  249. Project (#0{a})
  250. ReadIndex on=t t_a_idx=[*** full scan ***]
  251. Return
  252. Project (#2)
  253. Map (abs((#0{min_a} - #1{max_a})))
  254. Union
  255. Get l0
  256. Map (null, null)
  257. Union
  258. Negate
  259. Project ()
  260. Get l0
  261. Constant
  262. - ()
  263. Used Indexes:
  264. - materialize.public.t_a_idx (*** full scan ***)
  265. Target cluster: quickstart
  266. EOF
  267. # Test Reduce (local).
  268. query T multiline
  269. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  270. SELECT abs(min(a) - max(a)) FROM t GROUP BY b
  271. ----
  272. Explained Query:
  273. Project (#3)
  274. Map (abs((#1{min_a} - #2{max_a})))
  275. Reduce group_by=[#1{b}] aggregates=[min(#0{a}), max(#0{a})]
  276. ReadIndex on=t t_a_idx=[*** full scan ***]
  277. Used Indexes:
  278. - materialize.public.t_a_idx (*** full scan ***)
  279. Target cluster: quickstart
  280. EOF
  281. # Test EXISTS subqueries.
  282. query T multiline
  283. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  284. SELECT * FROM t WHERE EXISTS(SELECT * FROM mv WHERE t.a < mv.a) AND EXISTS(SELECT * FROM mv WHERE t.b > mv.b)
  285. ----
  286. Explained Query:
  287. With
  288. cte l0 =
  289. Project (#0{a}, #1{b})
  290. Join on=(#0{a} = #2{a}) type=differential
  291. ArrangeBy keys=[[#0{a}]]
  292. ReadIndex on=t t_a_idx=[differential join]
  293. ArrangeBy keys=[[#0{a}]]
  294. Distinct project=[#0{a}]
  295. Project (#0{a})
  296. Filter (#0{a} < #1{a})
  297. CrossJoin type=differential
  298. ArrangeBy keys=[[]]
  299. Distinct project=[#0{a}]
  300. Project (#0{a})
  301. ReadIndex on=t t_a_idx=[*** full scan ***]
  302. ArrangeBy keys=[[]]
  303. Project (#0{a})
  304. ReadStorage materialize.public.mv
  305. Return
  306. Project (#0{a}, #1{b})
  307. Join on=(#1{b} = #2{b}) type=differential
  308. ArrangeBy keys=[[#1{b}]]
  309. Get l0
  310. ArrangeBy keys=[[#0{b}]]
  311. Distinct project=[#0{b}]
  312. Project (#0{b})
  313. Filter (#0{b} > #1{b})
  314. CrossJoin type=differential
  315. ArrangeBy keys=[[]]
  316. Distinct project=[#0{b}]
  317. Project (#1{b})
  318. Get l0
  319. ArrangeBy keys=[[]]
  320. Project (#1{b})
  321. ReadStorage materialize.public.mv
  322. Source materialize.public.mv
  323. Used Indexes:
  324. - materialize.public.t_a_idx (*** full scan ***, differential join)
  325. Target cluster: quickstart
  326. EOF
  327. # Test SELECT subqueries.
  328. query T multiline
  329. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  330. SELECT (SELECT iv.a FROM iv WHERE iv.b = t.b LIMIT 1), (SELECT mv.a FROM mv WHERE mv.b = t.b LIMIT 1) FROM t
  331. ----
  332. Explained Query:
  333. With
  334. cte l0 =
  335. Project (#1{b})
  336. ReadIndex on=t t_a_idx=[*** full scan ***]
  337. cte l1 =
  338. Distinct project=[#0{b}]
  339. Get l0
  340. cte l2 =
  341. ArrangeBy keys=[[#0{b}]]
  342. Get l1
  343. cte l3 =
  344. TopK group_by=[#0{b}] limit=1
  345. Project (#0{b}, #1{a})
  346. Filter (#0{b}) IS NOT NULL
  347. Join on=(#0{b} = #2{b}) type=differential
  348. Get l2
  349. ArrangeBy keys=[[#1{b}]]
  350. ReadIndex on=iv iv_b_idx=[differential join]
  351. cte l4 =
  352. TopK group_by=[#0{b}] limit=1
  353. Project (#0{b}, #1{a})
  354. Join on=(#0{b} = #2{b}) type=differential
  355. Get l2
  356. ArrangeBy keys=[[#1{b}]]
  357. Filter (#1{b}) IS NOT NULL
  358. ReadStorage materialize.public.mv
  359. Return
  360. Project (#2{a}, #4{a})
  361. Join on=(#0{b} = #1{b} = #3{b}) type=delta
  362. ArrangeBy keys=[[#0{b}]]
  363. Get l0
  364. ArrangeBy keys=[[#0{b}]]
  365. Union
  366. Get l3
  367. Map (null)
  368. Union
  369. Negate
  370. Project (#0{b})
  371. Get l3
  372. Get l1
  373. ArrangeBy keys=[[#0{b}]]
  374. Union
  375. Get l4
  376. Map (null)
  377. Union
  378. Negate
  379. Project (#0{b})
  380. Get l4
  381. Get l1
  382. Source materialize.public.mv
  383. filter=((#1{b}) IS NOT NULL)
  384. Used Indexes:
  385. - materialize.public.t_a_idx (*** full scan ***)
  386. - materialize.public.iv_b_idx (differential join)
  387. Target cluster: quickstart
  388. EOF
  389. # Test outer joins (ON syntax).
  390. query T multiline
  391. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  392. SELECT t1.a, t2.a
  393. FROM t as t1
  394. LEFT JOIN t as t2 ON t1.b = t2.b
  395. RIGHT JOIN t as t3 ON t2.b = t3.b
  396. ----
  397. Explained Query:
  398. With
  399. cte l0 =
  400. Filter (#1{b}) IS NOT NULL
  401. ReadIndex on=t t_a_idx=[*** full scan ***]
  402. cte l1 =
  403. ArrangeBy keys=[[#1{b}]]
  404. Get l0
  405. cte l2 =
  406. ArrangeBy keys=[[#0{b}]]
  407. Project (#1{b})
  408. Get l0
  409. cte l3 =
  410. Project (#0{a}..=#2{a})
  411. Join on=(#1{b} = #3{b} = #4{b}) type=delta
  412. Get l1
  413. Get l1
  414. Get l2
  415. Return
  416. Union
  417. Map (null, null)
  418. Union
  419. Negate
  420. Project ()
  421. Join on=(#0{b} = #1{b}) type=differential
  422. Get l2
  423. ArrangeBy keys=[[#0{b}]]
  424. Distinct project=[#0{b}]
  425. Project (#1{b})
  426. Get l3
  427. Project ()
  428. ReadIndex on=t t_a_idx=[*** full scan ***]
  429. Project (#0{a}, #2{a})
  430. Get l3
  431. Used Indexes:
  432. - materialize.public.t_a_idx (*** full scan ***)
  433. Target cluster: quickstart
  434. EOF
  435. # Test a single CTE.
  436. query T multiline
  437. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  438. WITH x AS (SELECT t.a * t.b as v from t) SELECT a.v + b.v FROM x as a, x as b
  439. ----
  440. Explained Query:
  441. With
  442. cte l0 =
  443. ArrangeBy keys=[[]]
  444. Project (#2)
  445. Map ((#0{a} * #1{b}))
  446. ReadIndex on=t t_a_idx=[*** full scan ***]
  447. Return
  448. Project (#2)
  449. Map ((#0{v} + #1{v}))
  450. CrossJoin type=differential
  451. Get l0
  452. Get l0
  453. Used Indexes:
  454. - materialize.public.t_a_idx (*** full scan ***)
  455. Target cluster: quickstart
  456. EOF
  457. # Test EXPLAIN INDEX for an indexed source
  458. query T multiline
  459. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  460. INDEX t_a_idx
  461. ----
  462. materialize.public.t_a_idx:
  463. ArrangeBy keys=[[#0{a}]]
  464. ReadStorage materialize.public.t
  465. Source materialize.public.t
  466. Target cluster: quickstart
  467. EOF
  468. # Test EXPLAIN INDEX for an indexed view (first index)
  469. query T multiline
  470. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  471. INDEX iv_a_idx;
  472. ----
  473. materialize.public.iv_a_idx:
  474. ArrangeBy keys=[[#0{a}]]
  475. ReadGlobalFromSameDataflow materialize.public.iv
  476. materialize.public.iv:
  477. Filter (#0{a}) IS NOT NULL
  478. ReadIndex on=t t_a_idx=[*** full scan ***]
  479. Used Indexes:
  480. - materialize.public.t_a_idx (*** full scan ***)
  481. Target cluster: quickstart
  482. EOF
  483. # Test EXPLAIN INDEX for an indexed view (based on a prior index)
  484. query T multiline
  485. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  486. INDEX iv_b_idx;
  487. ----
  488. materialize.public.iv_b_idx:
  489. ArrangeBy keys=[[#1{b}]]
  490. ReadIndex on=iv iv_a_idx=[*** full scan ***]
  491. Used Indexes:
  492. - materialize.public.iv_a_idx (*** full scan ***, index export)
  493. Target cluster: quickstart
  494. EOF
  495. # Test EXPLAIN INDEX for an indexed view where the index is exactly the same as a prior index.
  496. query T multiline
  497. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  498. INDEX iv_b_idx_2;
  499. ----
  500. materialize.public.iv_b_idx_2:
  501. ArrangeBy keys=[[#1{b}]]
  502. ReadIndex on=iv iv_b_idx=[plan root (no new arrangement)]
  503. Used Indexes:
  504. - materialize.public.iv_b_idx (plan root (no new arrangement), index export)
  505. Target cluster: quickstart
  506. Notices:
  507. - Notice: Index materialize.public.iv_b_idx_2 is identical to materialize.public.iv_b_idx, which is also defined on iv(b).
  508. Hint: Please drop all indexes except the first index created on iv(b) and recreate all dependent objects.
  509. EOF
  510. # Test multiple CTEs: a case where we cannot pull the let statement up through
  511. # the join because the local l0 is correlated against the lhs of the enclosing join.
  512. query T multiline
  513. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  514. SELECT
  515. *
  516. FROM
  517. (
  518. SELECT * FROM t
  519. ) as r1
  520. CROSS JOIN LATERAL (
  521. WITH r2 as (
  522. SELECT MAX(r1.a * t.a) AS m FROM t
  523. )
  524. SELECT * FROM r2 WHERE r2.m != r1.a
  525. ) as r3
  526. CROSS JOIN LATERAL (
  527. WITH r4 as (
  528. SELECT MAX(r1.a * t.a) AS m FROM t
  529. )
  530. SELECT * FROM r4 WHERE r4.m != r1.a OR (r4.m IS NOT NULL AND r1.a IS NULL)
  531. ) as r5;
  532. ----
  533. Explained Query:
  534. With
  535. cte l0 =
  536. Project (#0{a})
  537. ReadIndex on=t t_a_idx=[*** full scan ***]
  538. cte l1 =
  539. ArrangeBy keys=[[]]
  540. Get l0
  541. cte l2 =
  542. Project (#0{a}, #1{b}, #3{max})
  543. Filter (#0{a} != #3{max})
  544. Join on=(#0{a} = #2{a}) type=differential
  545. ArrangeBy keys=[[#0{a}]]
  546. ReadIndex on=t t_a_idx=[differential join]
  547. ArrangeBy keys=[[#0{a}]]
  548. Reduce group_by=[#0{a}] aggregates=[max((#0{a} * #1{a}))]
  549. CrossJoin type=differential
  550. ArrangeBy keys=[[]]
  551. Distinct project=[#0{a}]
  552. Get l0
  553. Get l1
  554. Return
  555. Project (#0{a}..=#2{max}, #4{max})
  556. Filter (#0{a} != #4{max})
  557. Join on=(#0{a} = #3{a}) type=differential
  558. ArrangeBy keys=[[#0{a}]]
  559. Get l2
  560. ArrangeBy keys=[[#0{a}]]
  561. Reduce group_by=[#0{a}] aggregates=[max((#0{a} * #1{a}))]
  562. CrossJoin type=differential
  563. ArrangeBy keys=[[]]
  564. Distinct project=[#0{a}]
  565. Project (#0{a})
  566. Get l2
  567. Get l1
  568. Used Indexes:
  569. - materialize.public.t_a_idx (*** full scan ***, differential join)
  570. Target cluster: quickstart
  571. EOF
  572. # Test cross join.
  573. query T multiline
  574. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  575. SELECT t1.a, t2.a FROM t as t1, t as t2
  576. ----
  577. Explained Query:
  578. With
  579. cte l0 =
  580. ArrangeBy keys=[[]]
  581. Project (#0{a})
  582. ReadIndex on=t t_a_idx=[*** full scan ***]
  583. Return
  584. CrossJoin type=differential
  585. Get l0
  586. Get l0
  587. Used Indexes:
  588. - materialize.public.t_a_idx (*** full scan ***)
  589. Target cluster: quickstart
  590. EOF
  591. # Test cyclic join.
  592. query T multiline
  593. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  594. SELECT t1.a, t2.a
  595. FROM
  596. t as t1,
  597. t as t2,
  598. t as t3
  599. WHERE t1.b = t2.b AND t2.b = t3.b
  600. ----
  601. Explained Query:
  602. With
  603. cte l0 =
  604. Filter (#1{b}) IS NOT NULL
  605. ReadIndex on=t t_a_idx=[*** full scan ***]
  606. cte l1 =
  607. ArrangeBy keys=[[#1{b}]]
  608. Get l0
  609. Return
  610. Project (#0{a}, #2{a})
  611. Join on=(#1{b} = #3{b} = #4{b}) type=delta
  612. Get l1
  613. Get l1
  614. ArrangeBy keys=[[#0{b}]]
  615. Project (#1{b})
  616. Get l0
  617. Used Indexes:
  618. - materialize.public.t_a_idx (*** full scan ***)
  619. Target cluster: quickstart
  620. EOF
  621. # Create indexes required for differential join tests
  622. statement ok
  623. CREATE INDEX u_c_idx ON U(c);
  624. statement ok
  625. CREATE INDEX u_d_idx ON U(d);
  626. statement ok
  627. CREATE INDEX v_e_idx ON V(e);
  628. # Temporarily switch off enable_eager_delta_joins
  629. simple conn=mz_system,user=mz_system
  630. ALTER SYSTEM SET enable_eager_delta_joins = false
  631. ----
  632. COMPLETE 0
  633. # Test a differential join.
  634. query T multiline
  635. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  636. SELECT a, b, c, d, e, f
  637. FROM t, u, v
  638. WHERE a = c and d = e and b = f
  639. ----
  640. Explained Query:
  641. Project (#0{a}, #1{b}, #0{a}, #3{d}, #3{d}, #1{b})
  642. Filter (#0{a}) IS NOT NULL
  643. Join on=(#0{a} = #2{c} AND #1{b} = #5{f} AND #3{d} = #4{e}) type=differential
  644. ArrangeBy keys=[[#0{a}]]
  645. ReadIndex on=t t_a_idx=[differential join]
  646. ArrangeBy keys=[[#0{c}]]
  647. ReadIndex on=u u_c_idx=[differential join]
  648. ArrangeBy keys=[[#0{e}, #1{f}]]
  649. Filter (#0{e}) IS NOT NULL AND (#1{f}) IS NOT NULL
  650. ReadIndex on=v v_e_idx=[*** full scan ***]
  651. Used Indexes:
  652. - materialize.public.t_a_idx (differential join)
  653. - materialize.public.u_c_idx (differential join)
  654. - materialize.public.v_e_idx (*** full scan ***)
  655. Target cluster: quickstart
  656. EOF
  657. # Test a differential join WITH(join implementations).
  658. query T multiline
  659. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, join implementations) AS VERBOSE TEXT FOR
  660. SELECT a, b, c, d, e, f
  661. FROM t, u, v
  662. WHERE a = c and d = e and b = f
  663. ----
  664. Explained Query:
  665. Project (#0{a}, #1{b}, #0{a}, #3{d}, #3{d}, #1{b})
  666. Filter (#0{a}) IS NOT NULL
  667. Join on=(#0{a} = #2{c} AND #1{b} = #5{f} AND #3{d} = #4{e}) type=differential
  668. implementation
  669. %0:t[#0{a}]KA » %1:u[#0{c}]KA » %2:v[#0{e}, #1{f}]KK
  670. ArrangeBy keys=[[#0{a}]]
  671. ReadIndex on=t t_a_idx=[differential join]
  672. ArrangeBy keys=[[#0{c}]]
  673. ReadIndex on=u u_c_idx=[differential join]
  674. ArrangeBy keys=[[#0{e}, #1{f}]]
  675. Filter (#0{e}) IS NOT NULL AND (#1{f}) IS NOT NULL
  676. ReadIndex on=v v_e_idx=[*** full scan ***]
  677. Used Indexes:
  678. - materialize.public.t_a_idx (differential join)
  679. - materialize.public.u_c_idx (differential join)
  680. - materialize.public.v_e_idx (*** full scan ***)
  681. Target cluster: quickstart
  682. EOF
  683. simple conn=mz_system,user=mz_system
  684. ALTER SYSTEM SET enable_eager_delta_joins = true
  685. ----
  686. COMPLETE 0
  687. # Create indexes required for delta join tests
  688. statement ok
  689. CREATE INDEX t_b_idx ON T(b);
  690. # Test a delta join without WITH(join implementations).
  691. query T multiline
  692. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  693. SELECT a, b, c, d, e, f
  694. FROM t, u, v
  695. WHERE b = c and d = e
  696. ----
  697. Explained Query:
  698. Project (#0{a}, #1{b}, #1{b}, #3{d}, #3{d}, #5{f})
  699. Filter (#1{b}) IS NOT NULL AND (#3{d}) IS NOT NULL
  700. Join on=(#1{b} = #2{c} AND #3{d} = #4{e}) type=delta
  701. ArrangeBy keys=[[#1{b}]]
  702. ReadIndex on=t t_b_idx=[delta join 1st input (full scan)]
  703. ArrangeBy keys=[[#0{c}], [#1{d}]]
  704. ReadIndex on=u u_c_idx=[delta join lookup] u_d_idx=[delta join lookup]
  705. ArrangeBy keys=[[#0{e}]]
  706. ReadIndex on=v v_e_idx=[delta join lookup]
  707. Used Indexes:
  708. - materialize.public.u_c_idx (delta join lookup)
  709. - materialize.public.u_d_idx (delta join lookup)
  710. - materialize.public.v_e_idx (delta join lookup)
  711. - materialize.public.t_b_idx (delta join 1st input (full scan))
  712. Target cluster: quickstart
  713. EOF
  714. # Test a delta join WITH(join implementations).
  715. query T multiline
  716. EXPLAIN OPTIMIZED PLAN WITH(join implementations, humanized expressions) AS VERBOSE TEXT FOR
  717. SELECT a, b, c, d, e, f
  718. FROM t, u, v
  719. WHERE b = c and d = e
  720. ----
  721. Explained Query:
  722. Project (#0{a}, #1{b}, #1{b}, #3{d}, #3{d}, #5{f})
  723. Filter (#1{b}) IS NOT NULL AND (#3{d}) IS NOT NULL
  724. Join on=(#1{b} = #2{c} AND #3{d} = #4{e}) type=delta
  725. implementation
  726. %0:t » %1:u[#0{c}]KA » %2:v[#0{e}]KA
  727. %1:u » %0:t[#1{b}]KA » %2:v[#0{e}]KA
  728. %2:v » %1:u[#1{d}]KA » %0:t[#1{b}]KA
  729. ArrangeBy keys=[[#1{b}]]
  730. ReadIndex on=t t_b_idx=[delta join 1st input (full scan)]
  731. ArrangeBy keys=[[#0{c}], [#1{d}]]
  732. ReadIndex on=u u_c_idx=[delta join lookup] u_d_idx=[delta join lookup]
  733. ArrangeBy keys=[[#0{e}]]
  734. ReadIndex on=v v_e_idx=[delta join lookup]
  735. Used Indexes:
  736. - materialize.public.u_c_idx (delta join lookup)
  737. - materialize.public.u_d_idx (delta join lookup)
  738. - materialize.public.v_e_idx (delta join lookup)
  739. - materialize.public.t_b_idx (delta join 1st input (full scan))
  740. Target cluster: quickstart
  741. EOF
  742. # Test a delta join where the first input has both a full scan and a lookup.
  743. query T multiline
  744. EXPLAIN OPTIMIZED PLAN WITH(join implementations, humanized expressions) AS VERBOSE TEXT FOR
  745. SELECT a, b, c, d, e, f
  746. FROM t, u, v
  747. WHERE a = c and b = e
  748. ----
  749. Explained Query:
  750. Project (#0{a}, #1{b}, #0{a}, #3{d}, #1{b}, #5{f})
  751. Filter (#0{a}) IS NOT NULL AND (#1{b}) IS NOT NULL
  752. Join on=(#0{a} = #2{c} AND #1{b} = #4{e}) type=delta
  753. implementation
  754. %0:t » %1:u[#0{c}]KA » %2:v[#0{e}]KA
  755. %1:u » %0:t[#0{a}]KA » %2:v[#0{e}]KA
  756. %2:v » %0:t[#1{b}]KA » %1:u[#0{c}]KA
  757. ArrangeBy keys=[[#0{a}], [#1{b}]]
  758. ReadIndex on=t t_a_idx=[delta join 1st input (full scan)] t_b_idx=[delta join lookup]
  759. ArrangeBy keys=[[#0{c}]]
  760. ReadIndex on=u u_c_idx=[delta join lookup]
  761. ArrangeBy keys=[[#0{e}]]
  762. ReadIndex on=v v_e_idx=[delta join lookup]
  763. Used Indexes:
  764. - materialize.public.t_a_idx (delta join 1st input (full scan))
  765. - materialize.public.u_c_idx (delta join lookup)
  766. - materialize.public.v_e_idx (delta join lookup)
  767. - materialize.public.t_b_idx (delta join lookup)
  768. Target cluster: quickstart
  769. EOF
  770. # Test an IndexedFilter join.
  771. query T multiline
  772. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  773. SELECT a, max(b)
  774. FROM t
  775. WHERE a = 0
  776. GROUP BY a
  777. ----
  778. Explained Query:
  779. Project (#1, #0{max_b})
  780. Map (0)
  781. Reduce aggregates=[max(#0{b})]
  782. Project (#1{b})
  783. ReadIndex on=materialize.public.t t_a_idx=[lookup value=(0)]
  784. Used Indexes:
  785. - materialize.public.t_a_idx (lookup)
  786. Target cluster: quickstart
  787. EOF
  788. # Create index for IndexedFilter test
  789. statement ok
  790. CREATE INDEX t_a_b_idx ON T(a,b)
  791. # Test an IndexedFilter join WITH(join implementations).
  792. query T multiline
  793. EXPLAIN OPTIMIZED PLAN WITH(join implementations, humanized expressions) AS VERBOSE TEXT FOR
  794. SELECT a, max(b)
  795. FROM t
  796. WHERE (a = 0 AND b = 1) OR (a = 3 AND b = 4) OR (a = 7 AND b = 8)
  797. GROUP BY a
  798. ----
  799. Explained Query:
  800. Reduce group_by=[#0{a}] aggregates=[max(#1{b})]
  801. Project (#0{a}, #1{b})
  802. ReadIndex on=materialize.public.t t_a_b_idx=[lookup values=[(0, 1); (3, 4); (7, 8)]]
  803. Used Indexes:
  804. - materialize.public.t_a_b_idx (lookup)
  805. Target cluster: quickstart
  806. EOF
  807. # Test an IndexedFilter join on fast path WITH(join implementations).
  808. query T multiline
  809. EXPLAIN OPTIMIZED PLAN WITH(join implementations, humanized expressions) AS VERBOSE TEXT FOR
  810. SELECT *
  811. FROM t
  812. WHERE (a = 0 AND b = 1) OR (a = 3 AND b = 4) OR (a = 7 AND b = 8)
  813. ----
  814. Explained Query (fast path):
  815. Project (#0{a}, #1{b})
  816. ReadIndex on=materialize.public.t t_a_b_idx=[lookup values=[(0, 1); (3, 4); (7, 8)]]
  817. Used Indexes:
  818. - materialize.public.t_a_b_idx (lookup)
  819. Target cluster: quickstart
  820. EOF
  821. # Test materialize#17348.
  822. statement ok
  823. CREATE TABLE r(f0 INT, f1 INT, f2 INT, f3 INT, f4 INT, f5 INT, f6 INT, f7 INT, f8 INT, f9 INT, f10 INT, f11 INT, f12 INT, f13 INT, f14 INT, f15 INT, f16 INT);
  824. query T multiline
  825. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR SELECT *
  826. FROM r AS r0, r AS r1
  827. WHERE
  828. r0.f0=r1.f0 AND
  829. r0.f2=r1.f2 AND
  830. r0.f3=r1.f3 AND
  831. r0.f4=r1.f4 AND
  832. r0.f6=r1.f6 AND
  833. r0.f8=r1.f8 AND
  834. r0.f9=r1.f9 AND
  835. r0.f11=r1.f11 AND
  836. r0.f12=r1.f12 AND
  837. r0.f13=r1.f13 AND
  838. r0.f15=r1.f15 AND
  839. r0.f16=r1.f16;
  840. ----
  841. Explained Query:
  842. With
  843. cte l0 =
  844. ArrangeBy keys=[[#0{f0}, #2{f2}..=#4{f4}, #6{f6}, #8{f8}, #9{f9}, #11{f11}..=#13{f13}, #15{f15}, #16{f16}]]
  845. Filter (#0{f0}) IS NOT NULL AND (#2{f2}) IS NOT NULL AND (#3{f3}) IS NOT NULL AND (#4{f4}) IS NOT NULL AND (#6{f6}) IS NOT NULL AND (#8{f8}) IS NOT NULL AND (#9{f9}) IS NOT NULL AND (#11{f11}) IS NOT NULL AND (#12{f12}) IS NOT NULL AND (#13{f13}) IS NOT NULL AND (#15{f15}) IS NOT NULL AND (#16{f16}) IS NOT NULL
  846. ReadStorage materialize.public.r
  847. Return
  848. Project (#0{f0}..=#16{f16}, #0{f0}, #18{f1}, #2{f2}..=#4{f4}, #22{f5}, #6{f6}, #24{f7}, #8{f8}, #9{f9}, #27{f10}, #11{f11}..=#13{f13}, #31{f14}, #15{f15}, #16{f16})
  849. Join on=(#0{f0} = #17{f0} AND #2{f2} = #19{f2} AND #3{f3} = #20{f3} AND #4{f4} = #21{f4} AND #6{f6} = #23{f6} AND #8{f8} = #25{f8} AND #9{f9} = #26{f9} AND #11{f11} = #28{f11} AND #12{f12} = #29{f12} AND #13{f13} = #30{f13} AND #15{f15} = #32{f15} AND #16{f16} = #33{f16}) type=differential
  850. Get l0
  851. Get l0
  852. Source materialize.public.r
  853. filter=((#0{f0}) IS NOT NULL AND (#2{f2}) IS NOT NULL AND (#3{f3}) IS NOT NULL AND (#4{f4}) IS NOT NULL AND (#6{f6}) IS NOT NULL AND (#8{f8}) IS NOT NULL AND (#9{f9}) IS NOT NULL AND (#11{f11}) IS NOT NULL AND (#12{f12}) IS NOT NULL AND (#13{f13}) IS NOT NULL AND (#15{f15}) IS NOT NULL AND (#16{f16}) IS NOT NULL)
  854. Target cluster: quickstart
  855. EOF
  856. ## linear chains is currently disabled for WMR.
  857. statement error not supported
  858. EXPLAIN OPTIMIZED PLAN WITH(linear chains) AS VERBOSE TEXT FOR
  859. WITH MUTUALLY RECURSIVE
  860. foo (a int, b int) AS (SELECT 1, 2 UNION SELECT a, 7 FROM bar),
  861. bar (a int) as (SELECT a FROM foo)
  862. SELECT * FROM bar;
  863. # Regression test for database-issues#5674: support mz_now() on select from indexed table
  864. # ---
  865. simple conn=mz_system,user=mz_system
  866. ALTER SYSTEM SET enable_rbac_checks TO false;
  867. ----
  868. COMPLETE 0
  869. statement ok
  870. DROP SCHEMA IF EXISTS public CASCADE;
  871. simple conn=mz_system,user=mz_system
  872. ALTER SYSTEM RESET enable_rbac_checks;
  873. ----
  874. COMPLETE 0
  875. statement ok
  876. CREATE SCHEMA public;
  877. statement ok
  878. CREATE TABLE t(a TIMESTAMP);
  879. statement ok
  880. CREATE DEFAULT INDEX ON t;
  881. # EXPLAIN output is time-dependent, so we don't want show the output here, just
  882. # assert that the query doesn't fail.
  883. statement ok
  884. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR SELECT * FROM t WHERE a < mz_now();
  885. # Regression test for materialize#19177
  886. # ---
  887. statement ok
  888. DROP SCHEMA IF EXISTS public CASCADE;
  889. statement ok
  890. CREATE SCHEMA public;
  891. statement ok
  892. CREATE TABLE t1(x text);
  893. statement ok
  894. CREATE TABLE t2(x text);
  895. statement ok
  896. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR SELECT * FROM t1, t2 WHERE t1.x || mz_internal.mz_session_id() = t2.x || mz_internal.mz_session_id();
  897. # Regression test for the join visitation part of materialize#19177
  898. statement ok
  899. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR SELECT * FROM t1, t2 WHERE t1.x || mz_now() = t2.x || mz_now();
  900. query T multiline
  901. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  902. SELECT lag(x, 3, 'default') IGNORE NULLS OVER (ORDER BY x || x)
  903. FROM t1;
  904. ----
  905. Explained Query:
  906. Project (#2)
  907. Map (record_get[0](#1))
  908. FlatMap unnest_list(#0{lag})
  909. Reduce aggregates=[lag[ignore_nulls=true, order_by=[#0{x} asc nulls_last]](row(row(row(#0{x}), row(#0{x}, 3, "default")), (#0{x} || #0{x})))]
  910. ReadStorage materialize.public.t1
  911. Source materialize.public.t1
  912. Target cluster: quickstart
  913. EOF
  914. query T multiline
  915. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  916. SELECT first_value(x) OVER (ORDER BY x || x ROWS BETWEEN 5 preceding AND CURRENT ROW)
  917. FROM t1;
  918. ----
  919. Explained Query:
  920. Project (#2)
  921. Map (record_get[0](#1))
  922. FlatMap unnest_list(#0{first_value})
  923. Reduce aggregates=[first_value[order_by=[#0{x} asc nulls_last] rows between 5 preceding and current row](row(row(row(#0{x}), #0{x}), (#0{x} || #0{x})))]
  924. ReadStorage materialize.public.t1
  925. Source materialize.public.t1
  926. Target cluster: quickstart
  927. EOF
  928. ## "Used indexes" tests
  929. statement ok
  930. CREATE TABLE t (
  931. a int,
  932. b int
  933. );
  934. statement ok
  935. CREATE TABLE u (
  936. c int,
  937. d int
  938. );
  939. # If two indexes exist on the same table, then "Used indexes" should print the one that we are actually going to use
  940. statement ok
  941. CREATE INDEX u_c ON u(c);
  942. statement ok
  943. CREATE INDEX u_d ON u(d);
  944. query T multiline
  945. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  946. SELECT *
  947. FROM t, u
  948. WHERE t.b = u.c;
  949. ----
  950. Explained Query:
  951. Project (#0{a}, #1{b}, #1{b}, #3{d})
  952. Join on=(#1{b} = #2{c}) type=differential
  953. ArrangeBy keys=[[#1{b}]]
  954. Filter (#1{b}) IS NOT NULL
  955. ReadStorage materialize.public.t
  956. ArrangeBy keys=[[#0{c}]]
  957. ReadIndex on=u u_c=[differential join]
  958. Source materialize.public.t
  959. filter=((#1{b}) IS NOT NULL)
  960. Used Indexes:
  961. - materialize.public.u_c (differential join)
  962. Target cluster: quickstart
  963. EOF
  964. query T multiline
  965. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  966. SELECT *
  967. FROM t, u
  968. WHERE t.b = u.d;
  969. ----
  970. Explained Query:
  971. Project (#0{a}..=#2{c}, #1{b})
  972. Join on=(#1{b} = #3{d}) type=differential
  973. ArrangeBy keys=[[#1{b}]]
  974. Filter (#1{b}) IS NOT NULL
  975. ReadStorage materialize.public.t
  976. ArrangeBy keys=[[#1{d}]]
  977. ReadIndex on=u u_d=[differential join]
  978. Source materialize.public.t
  979. filter=((#1{b}) IS NOT NULL)
  980. Used Indexes:
  981. - materialize.public.u_d (differential join)
  982. Target cluster: quickstart
  983. EOF
  984. statement ok
  985. DROP INDEX u_c;
  986. # Let's test the weird situation that two identical indexes exist.
  987. statement ok
  988. CREATE INDEX t_a_idx_1 ON t(a);
  989. statement ok
  990. CREATE INDEX t_a_idx_2 ON t(a);
  991. query T multiline
  992. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  993. SELECT *
  994. FROM t, u
  995. WHERE t.a = u.c
  996. ----
  997. Explained Query:
  998. Project (#0{a}, #1{b}, #0{a}, #3{d})
  999. Join on=(#0{a} = #2{c}) type=differential
  1000. ArrangeBy keys=[[#0{a}]]
  1001. ReadIndex on=t t_a_idx_1=[differential join]
  1002. ArrangeBy keys=[[#0{c}]]
  1003. Filter (#0{c}) IS NOT NULL
  1004. ReadIndex on=u u_d=[*** full scan ***]
  1005. Used Indexes:
  1006. - materialize.public.u_d (*** full scan ***)
  1007. - materialize.public.t_a_idx_1 (differential join)
  1008. Target cluster: quickstart
  1009. EOF
  1010. # An index is used two times by the same (self) join. We should show a 1st input and a non-1st input usage.
  1011. query T multiline
  1012. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  1013. SELECT *
  1014. FROM t AS t1, t AS t2, t AS t3
  1015. WHERE t1.a = t2.a AND t2.a = t3.a;
  1016. ----
  1017. Explained Query:
  1018. With
  1019. cte l0 =
  1020. ArrangeBy keys=[[#0{a}]]
  1021. ReadIndex on=t t_a_idx_1=[delta join lookup, delta join 1st input (full scan)]
  1022. Return
  1023. Project (#0{a}, #1{b}, #0{a}, #3{b}, #0{a}, #5{b})
  1024. Filter (#0{a}) IS NOT NULL
  1025. Join on=(#0{a} = #2{a} = #4{a}) type=delta
  1026. Get l0
  1027. Get l0
  1028. Get l0
  1029. Used Indexes:
  1030. - materialize.public.t_a_idx_1 (delta join lookup, delta join 1st input (full scan))
  1031. Target cluster: quickstart
  1032. EOF
  1033. # An index is used in both a join and a full scan.
  1034. query T multiline
  1035. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  1036. (SELECT t1.a + t2.a AS a, t1.b + t2.b AS b
  1037. FROM t AS t1, t AS t2
  1038. WHERE t1.a = t2.a)
  1039. UNION
  1040. (SELECT *
  1041. FROM t
  1042. WHERE b > 5)
  1043. ----
  1044. Explained Query:
  1045. With
  1046. cte l0 =
  1047. ArrangeBy keys=[[#0{a}]]
  1048. ReadIndex on=t t_a_idx_1=[differential join]
  1049. Return
  1050. Distinct project=[#0{a}, #1{b}]
  1051. Union
  1052. Project (#4, #5)
  1053. Filter (#0{a}) IS NOT NULL
  1054. Map ((#0{a} + #0{a}), (#1{b} + #3{b}))
  1055. Join on=(#0{a} = #2{a}) type=differential
  1056. Get l0
  1057. Get l0
  1058. Filter (#1{b} > 5)
  1059. ReadIndex on=t t_a_idx_1=[*** full scan ***]
  1060. Used Indexes:
  1061. - materialize.public.t_a_idx_1 (*** full scan ***, differential join)
  1062. Target cluster: quickstart
  1063. EOF
  1064. # An index exists that can't be used for the join because of having the wrong key.
  1065. query T multiline
  1066. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  1067. (SELECT t1.a + t2.a AS a, t1.b + t2.b AS b
  1068. FROM t AS t1, t AS t2
  1069. WHERE t1.b = t2.b)
  1070. UNION
  1071. (SELECT *
  1072. FROM t
  1073. WHERE b > 5)
  1074. ----
  1075. Explained Query:
  1076. With
  1077. cte l0 =
  1078. ArrangeBy keys=[[#1{b}]]
  1079. Filter (#1{b}) IS NOT NULL
  1080. ReadIndex on=t t_a_idx_1=[*** full scan ***]
  1081. Return
  1082. Distinct project=[#0{a}, #1{b}]
  1083. Union
  1084. Project (#4, #5)
  1085. Map ((#0{a} + #2{a}), (#1{b} + #1{b}))
  1086. Join on=(#1{b} = #3{b}) type=differential
  1087. Get l0
  1088. Get l0
  1089. Filter (#1{b} > 5)
  1090. ReadIndex on=t t_a_idx_1=[*** full scan ***]
  1091. Used Indexes:
  1092. - materialize.public.t_a_idx_1 (*** full scan ***)
  1093. Target cluster: quickstart
  1094. EOF
  1095. # Similar to the previous test, but exercises the full scan code inside the context loop of the Get case in
  1096. # `collect_index_reqs_inner`, where we don't have an index for the requested key.
  1097. statement ok
  1098. CREATE TABLE t_non_null (
  1099. a int NOT NULL,
  1100. b int NOT NULL
  1101. );
  1102. statement ok
  1103. CREATE INDEX t_non_null_a_idx ON t_non_null(a);
  1104. query T multiline
  1105. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  1106. (SELECT t1.a + t2.a AS a, t1.b + t2.b AS b
  1107. FROM t_non_null AS t1, t_non_null AS t2
  1108. WHERE t1.b = t2.b)
  1109. UNION
  1110. (SELECT *
  1111. FROM t_non_null
  1112. WHERE b > 5)
  1113. ----
  1114. Explained Query:
  1115. With
  1116. cte l0 =
  1117. ArrangeBy keys=[[#1{b}]]
  1118. ReadIndex on=t_non_null t_non_null_a_idx=[*** full scan ***]
  1119. Return
  1120. Distinct project=[#0{a}, #1{b}]
  1121. Union
  1122. Project (#4, #5)
  1123. Map ((#0{a} + #2{a}), (#1{b} + #1{b}))
  1124. Join on=(#1{b} = #3{b}) type=differential
  1125. Get l0
  1126. Get l0
  1127. Filter (#1{b} > 5)
  1128. ReadIndex on=t_non_null t_non_null_a_idx=[*** full scan ***]
  1129. Used Indexes:
  1130. - materialize.public.t_non_null_a_idx (*** full scan ***)
  1131. Target cluster: quickstart
  1132. EOF
  1133. # This has 1 more full scan than the previous test, because the join needs 2 different arrangements.
  1134. # (But we print only one full scan due to deduplication.)
  1135. query T multiline
  1136. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  1137. (SELECT t1.a + t2.a AS a, t1.b + t2.b AS b
  1138. FROM t_non_null AS t1, t_non_null AS t2
  1139. WHERE t1.b = t2.b + 1)
  1140. UNION
  1141. (SELECT *
  1142. FROM t_non_null
  1143. WHERE b > 5)
  1144. ----
  1145. Explained Query:
  1146. Distinct project=[#0{a}, #1{b}]
  1147. Union
  1148. Project (#4, #5)
  1149. Map ((#0{a} + #2{a}), (#1{b} + #3{b}))
  1150. Join on=(#1{b} = (#3{b} + 1)) type=differential
  1151. ArrangeBy keys=[[#1{b}]]
  1152. ReadIndex on=t_non_null t_non_null_a_idx=[*** full scan ***]
  1153. ArrangeBy keys=[[(#1{b} + 1)]]
  1154. ReadIndex on=t_non_null t_non_null_a_idx=[*** full scan ***]
  1155. Filter (#1{b} > 5)
  1156. ReadIndex on=t_non_null t_non_null_a_idx=[*** full scan ***]
  1157. Used Indexes:
  1158. - materialize.public.t_non_null_a_idx (*** full scan ***)
  1159. Target cluster: quickstart
  1160. EOF
  1161. # An index is used in both a lookup and a full scan.
  1162. query T multiline
  1163. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  1164. SELECT * FROM t
  1165. UNION
  1166. SELECT * FROM t WHERE a = 5;
  1167. ----
  1168. Explained Query:
  1169. Distinct project=[#0{a}, #1{b}]
  1170. Union
  1171. ReadIndex on=t t_a_idx_2=[*** full scan ***]
  1172. Project (#0{a}, #1{b})
  1173. ReadIndex on=materialize.public.t t_a_idx_2=[lookup value=(5)]
  1174. Used Indexes:
  1175. - materialize.public.t_a_idx_2 (*** full scan ***, lookup)
  1176. Target cluster: quickstart
  1177. EOF
  1178. # Several lookups using different indexes
  1179. statement ok
  1180. CREATE INDEX t_b_idx ON t(b);
  1181. query T multiline
  1182. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  1183. SELECT * FROM t
  1184. UNION ALL
  1185. SELECT * FROM t WHERE b = 7
  1186. UNION ALL
  1187. SELECT * FROM t WHERE a = 5
  1188. UNION ALL
  1189. SELECT * FROM u WHERE c = 3
  1190. UNION ALL
  1191. SELECT * FROM u WHERE d = 1;
  1192. ----
  1193. Explained Query:
  1194. Union
  1195. ReadIndex on=t t_b_idx=[*** full scan ***]
  1196. Project (#0{a}, #1{b})
  1197. ReadIndex on=materialize.public.t t_b_idx=[lookup value=(7)]
  1198. Project (#0{a}, #1{b})
  1199. ReadIndex on=materialize.public.t t_a_idx_2=[lookup value=(5)]
  1200. Filter (#0{c} = 3)
  1201. ReadIndex on=u u_d=[*** full scan ***]
  1202. Project (#0{c}, #1{d})
  1203. ReadIndex on=materialize.public.u u_d=[lookup value=(1)]
  1204. Used Indexes:
  1205. - materialize.public.u_d (*** full scan ***, lookup)
  1206. - materialize.public.t_a_idx_2 (lookup)
  1207. - materialize.public.t_b_idx (*** full scan ***, lookup)
  1208. Target cluster: quickstart
  1209. EOF
  1210. # Fast path with a LIMIT and no ORDER BY. This is not a full scan.
  1211. query T multiline
  1212. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  1213. SELECT a+b as x
  1214. FROM t
  1215. WHERE a < 7
  1216. LIMIT 3;
  1217. ----
  1218. Explained Query (fast path):
  1219. Finish limit=3 output=[#0]
  1220. Project (#2)
  1221. Filter (#0{a} < 7)
  1222. Map ((#0{a} + #1{b}))
  1223. ReadIndex on=materialize.public.t t_a_idx_1=[*** full scan ***]
  1224. Used Indexes:
  1225. - materialize.public.t_a_idx_1 (fast path limit)
  1226. Target cluster: quickstart
  1227. EOF
  1228. # Same query without a LIMIT, so full scan
  1229. query T multiline
  1230. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  1231. SELECT a+b as x
  1232. FROM t
  1233. WHERE a < 7;
  1234. ----
  1235. Explained Query (fast path):
  1236. Project (#2)
  1237. Filter (#0{a} < 7)
  1238. Map ((#0{a} + #1{b}))
  1239. ReadIndex on=materialize.public.t t_a_idx_1=[*** full scan ***]
  1240. Used Indexes:
  1241. - materialize.public.t_a_idx_1 (*** full scan ***)
  1242. Target cluster: quickstart
  1243. EOF
  1244. # Same query with a LIMIT + ORDER BY, so full scan
  1245. query T multiline
  1246. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  1247. SELECT a+b as x
  1248. FROM t
  1249. WHERE a < 7
  1250. ORDER BY x
  1251. LIMIT 3;
  1252. ----
  1253. Explained Query (fast path):
  1254. Finish order_by=[#0 asc nulls_last] limit=3 output=[#0]
  1255. Project (#2)
  1256. Filter (#0{a} < 7)
  1257. Map ((#0{a} + #1{b}))
  1258. ReadIndex on=materialize.public.t t_a_idx_1=[*** full scan ***]
  1259. Used Indexes:
  1260. - materialize.public.t_a_idx_1 (*** full scan ***)
  1261. Target cluster: quickstart
  1262. EOF
  1263. # We should choose an index whose key is a unique key (if exists)
  1264. statement ok
  1265. CREATE TABLE t4(
  1266. a int,
  1267. b int primary key,
  1268. c int
  1269. );
  1270. statement ok
  1271. CREATE INDEX t4_idx_a ON t4(a);
  1272. statement ok
  1273. CREATE INDEX t4_idx_b ON t4(b);
  1274. statement ok
  1275. CREATE INDEX t4_idx_c ON t4(c);
  1276. query T multiline
  1277. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
  1278. SELECT * FROM t4;
  1279. ----
  1280. Explained Query (fast path):
  1281. Project (#1{a}, #0{b}, #2{c})
  1282. ReadIndex on=materialize.public.t4 t4_idx_b=[*** full scan ***]
  1283. Used Indexes:
  1284. - materialize.public.t4_idx_b (*** full scan ***)
  1285. Target cluster: quickstart
  1286. EOF
  1287. # EXPLAIN should work even if there are no replicas.
  1288. statement ok
  1289. CREATE CLUSTER no_replicas (SIZE '1', REPLICATION FACTOR 0);
  1290. statement ok
  1291. SET CLUSTER = no_replicas;
  1292. query T multiline
  1293. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  1294. SELECT * FROM t4;
  1295. ----
  1296. Explained Query:
  1297. ReadStorage materialize.public.t4
  1298. Source materialize.public.t4
  1299. Target cluster: no_replicas
  1300. EOF
  1301. statement ok
  1302. CREATE TABLE t5(
  1303. x int,
  1304. y int NOT NULL,
  1305. z int
  1306. );
  1307. statement ok
  1308. CREATE TABLE t6(
  1309. a int NOT NULL,
  1310. b int
  1311. );
  1312. # WITH(EQUIVALENCES)
  1313. query T multiline
  1314. EXPLAIN OPTIMIZED PLAN WITH(EQUIVALENCES, humanized expressions) AS VERBOSE TEXT FOR
  1315. SELECT *
  1316. FROM t5, t6
  1317. WHERE x = a AND b IN (8,9);
  1318. ----
  1319. Explained Query:
  1320. Project (#0{x}..=#2{z}, #0{x}, #4{b}) // { equivs: "[[#0{x}, #3{x}], [false, (#0{x}) IS NULL, (#1{y}) IS NULL], [true, ((#4{b} = 8) OR (#4{b} = 9))]]" }
  1321. Join on=(#0{x} = #3{a}) type=differential // { equivs: "[[#0{x}, #3{a}], [false, (#0{x}) IS NULL, (#1{y}) IS NULL], [true, ((#4{b} = 8) OR (#4{b} = 9))]]" }
  1322. ArrangeBy keys=[[#0{x}]] // { equivs: "[[false, (#0{x}) IS NULL, (#1{y}) IS NULL]]" }
  1323. Filter (#0{x}) IS NOT NULL // { equivs: "[[false, (#0{x}) IS NULL, (#1{y}) IS NULL]]" }
  1324. ReadStorage materialize.public.t5 // { equivs: "[[false, (#1{y}) IS NULL]]" }
  1325. ArrangeBy keys=[[#0{a}]] // { equivs: "[[false, (#0{a}) IS NULL], [true, ((#1{b} = 8) OR (#1{b} = 9))]]" }
  1326. Filter ((#1{b} = 8) OR (#1{b} = 9)) // { equivs: "[[false, (#0{a}) IS NULL], [true, ((#1{b} = 8) OR (#1{b} = 9))]]" }
  1327. ReadStorage materialize.public.t6 // { equivs: "[[false, (#0{a}) IS NULL]]" }
  1328. Source materialize.public.t5
  1329. filter=((#0{x}) IS NOT NULL)
  1330. Source materialize.public.t6
  1331. filter=(((#1{b} = 8) OR (#1{b} = 9)))
  1332. Target cluster: no_replicas
  1333. EOF
  1334. query T multiline
  1335. EXPLAIN OPTIMIZED PLAN WITH(EQUIVALENCES, HUMANIZED EXPRESSIONS) AS VERBOSE TEXT FOR
  1336. SELECT *
  1337. FROM t5, t6
  1338. WHERE x = a AND b IN (8,9);
  1339. ----
  1340. Explained Query:
  1341. Project (#0{x}..=#2{z}, #0{x}, #4{b}) // { equivs: "[[#0{x}, #3{x}], [false, (#0{x}) IS NULL, (#1{y}) IS NULL], [true, ((#4{b} = 8) OR (#4{b} = 9))]]" }
  1342. Join on=(#0{x} = #3{a}) type=differential // { equivs: "[[#0{x}, #3{a}], [false, (#0{x}) IS NULL, (#1{y}) IS NULL], [true, ((#4{b} = 8) OR (#4{b} = 9))]]" }
  1343. ArrangeBy keys=[[#0{x}]] // { equivs: "[[false, (#0{x}) IS NULL, (#1{y}) IS NULL]]" }
  1344. Filter (#0{x}) IS NOT NULL // { equivs: "[[false, (#0{x}) IS NULL, (#1{y}) IS NULL]]" }
  1345. ReadStorage materialize.public.t5 // { equivs: "[[false, (#1{y}) IS NULL]]" }
  1346. ArrangeBy keys=[[#0{a}]] // { equivs: "[[false, (#0{a}) IS NULL], [true, ((#1{b} = 8) OR (#1{b} = 9))]]" }
  1347. Filter ((#1{b} = 8) OR (#1{b} = 9)) // { equivs: "[[false, (#0{a}) IS NULL], [true, ((#1{b} = 8) OR (#1{b} = 9))]]" }
  1348. ReadStorage materialize.public.t6 // { equivs: "[[false, (#0{a}) IS NULL]]" }
  1349. Source materialize.public.t5
  1350. filter=((#0{x}) IS NOT NULL)
  1351. Source materialize.public.t6
  1352. filter=(((#1{b} = 8) OR (#1{b} = 9)))
  1353. Target cluster: no_replicas
  1354. EOF
  1355. # `count(*)` is planned as `count(true)`. We take care in EXPLAIN to show `count(true)` as `count(*)` to avoid confusing
  1356. # users.
  1357. query T multiline
  1358. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  1359. SELECT count(*)
  1360. FROM t5;
  1361. ----
  1362. Explained Query:
  1363. With
  1364. cte l0 =
  1365. Reduce aggregates=[count(*)]
  1366. Project ()
  1367. ReadStorage materialize.public.t5
  1368. Return
  1369. Union
  1370. Get l0
  1371. Map (0)
  1372. Union
  1373. Negate
  1374. Project ()
  1375. Get l0
  1376. Constant
  1377. - ()
  1378. Source materialize.public.t5
  1379. Target cluster: no_replicas
  1380. EOF
  1381. query error DISTINCT \* not supported as function args
  1382. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  1383. SELECT count(distinct *)
  1384. FROM t5;
  1385. # `count(true)` is currently also printed as `count(*)` in EXPLAIN, which I'd say is fine.
  1386. query T multiline
  1387. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  1388. SELECT count(true)
  1389. FROM t5;
  1390. ----
  1391. Explained Query:
  1392. With
  1393. cte l0 =
  1394. Reduce aggregates=[count(*)]
  1395. Project ()
  1396. ReadStorage materialize.public.t5
  1397. Return
  1398. Union
  1399. Get l0
  1400. Map (0)
  1401. Union
  1402. Negate
  1403. Project ()
  1404. Get l0
  1405. Constant
  1406. - ()
  1407. Source materialize.public.t5
  1408. Target cluster: no_replicas
  1409. EOF
  1410. # But `count(DISTINCT true)` means an entirely different thing, so EXPLAIN shouldn't conflate it with `count(*)`.
  1411. query T multiline
  1412. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  1413. SELECT count(DISTINCT true)
  1414. FROM t5;
  1415. ----
  1416. Explained Query:
  1417. With
  1418. cte l0 =
  1419. Reduce aggregates=[count(distinct true)]
  1420. Project ()
  1421. ReadStorage materialize.public.t5
  1422. Return
  1423. Union
  1424. Get l0
  1425. Map (0)
  1426. Union
  1427. Negate
  1428. Project ()
  1429. Get l0
  1430. Constant
  1431. - ()
  1432. Source materialize.public.t5
  1433. Target cluster: no_replicas
  1434. EOF
  1435. # OFFSET clause in RowSetFinishing
  1436. query T multiline
  1437. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  1438. SELECT a+b
  1439. FROM t4
  1440. OFFSET 1;
  1441. ----
  1442. Explained Query:
  1443. Finish offset=1 output=[#0]
  1444. Project (#3)
  1445. Map ((#0{a} + #1{b}))
  1446. ReadStorage materialize.public.t4
  1447. Source materialize.public.t4
  1448. Target cluster: no_replicas
  1449. EOF
  1450. # OFFSET clause in TopK
  1451. query T multiline
  1452. EXPLAIN OPTIMIZED PLAN AS VERBOSE TEXT FOR
  1453. SELECT a+b, (SELECT a*b FROM t4 OFFSET 1)
  1454. FROM t4;
  1455. ----
  1456. Explained Query:
  1457. With
  1458. cte l0 =
  1459. TopK offset=1
  1460. Project (#3)
  1461. Map ((#0{a} * #1{b}))
  1462. ReadStorage materialize.public.t4
  1463. cte l1 =
  1464. Union
  1465. Get l0
  1466. Project (#1)
  1467. FlatMap guard_subquery_size(#0)
  1468. Reduce aggregates=[count(*)]
  1469. Project ()
  1470. Get l0
  1471. Return
  1472. Project (#3, #2)
  1473. Map ((#0{a} + #1{b}))
  1474. CrossJoin type=differential
  1475. ArrangeBy keys=[[]]
  1476. Project (#0, #1)
  1477. ReadStorage materialize.public.t4
  1478. ArrangeBy keys=[[]]
  1479. Union
  1480. Get l1
  1481. Map (null)
  1482. Union
  1483. Negate
  1484. Distinct project=[]
  1485. Project ()
  1486. Get l1
  1487. Constant
  1488. - ()
  1489. Source materialize.public.t4
  1490. Target cluster: no_replicas
  1491. EOF