not-null-propagation.slt 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  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. mode cockroach
  10. statement ok
  11. CREATE TABLE int_table (col_null INTEGER, col_not_null INTEGER NOT NULL);
  12. statement ok
  13. CREATE TABLE bool_table (col_null BOOLEAN, col_not_null BOOLEAN NOT NULL);
  14. statement ok
  15. CREATE TABLE str_table (col_null STRING, col_not_null STRING NOT NULL);
  16. statement ok
  17. CREATE TABLE ts_table (col_null TIMESTAMP, col_not_null TIMESTAMP NOT NULL);
  18. statement ok
  19. CREATE TABLE json_table (col_null JSONB, col_not_null JSONB NOT NULL);
  20. statement ok
  21. INSERT INTO json_table VALUES(null, '{}');
  22. #
  23. # Constants are NOT NULL
  24. #
  25. query T multiline
  26. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT 1;
  27. ----
  28. Explained Query:
  29. Constant // { types: "(integer)" }
  30. - (1)
  31. Target cluster: mz_catalog_server
  32. EOF
  33. # NULL literal is NULL-able
  34. query T multiline
  35. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT NULL;
  36. ----
  37. Explained Query:
  38. Constant // { types: "(text?)" }
  39. - (null)
  40. Target cluster: mz_catalog_server
  41. EOF
  42. #
  43. # VALUES
  44. #
  45. query T multiline
  46. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT * FROM (VALUES(1), (2));
  47. ----
  48. Explained Query:
  49. Constant // { types: "(integer)" }
  50. - (1)
  51. - (2)
  52. Target cluster: quickstart
  53. EOF
  54. query T multiline
  55. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT * FROM (VALUES(1), (NULL));
  56. ----
  57. Explained Query:
  58. Constant // { types: "(integer?)" }
  59. - (null)
  60. - (1)
  61. Target cluster: quickstart
  62. EOF
  63. #
  64. # CAST propagates NOT NULL property
  65. #
  66. query T multiline
  67. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT CAST(col_null AS BIGINT), CAST(col_not_null AS BIGINT) FROM int_table;
  68. ----
  69. Explained Query:
  70. Project (#2, #3) // { types: "(bigint?, bigint)" }
  71. Map (integer_to_bigint(#0{col_null}), integer_to_bigint(#1{col_not_null})) // { types: "(integer?, integer, bigint?, bigint)" }
  72. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  73. Source materialize.public.int_table
  74. Target cluster: quickstart
  75. EOF
  76. #
  77. # IS NULL and friends
  78. #
  79. query T multiline
  80. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_null IS NULL, col_null IS NOT NULL FROM int_table;
  81. ----
  82. Explained Query:
  83. Project (#2, #3) // { types: "(boolean, boolean)" }
  84. Map ((#0{col_null}) IS NULL, NOT(#2)) // { types: "(integer?, integer, boolean, boolean)" }
  85. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  86. Source materialize.public.int_table
  87. Target cluster: quickstart
  88. EOF
  89. query T multiline
  90. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_null IS TRUE, col_null IS NOT TRUE FROM bool_table;
  91. ----
  92. Explained Query:
  93. Project (#2, #3) // { types: "(boolean, boolean)" }
  94. Map ((#0{col_null}) IS TRUE, NOT(#2)) // { types: "(boolean?, boolean, boolean, boolean)" }
  95. ReadStorage materialize.public.bool_table // { types: "(boolean?, boolean)" }
  96. Source materialize.public.bool_table
  97. Target cluster: quickstart
  98. EOF
  99. query T multiline
  100. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_null IS UNKNOWN, col_null IS NOT UNKNOWN FROM bool_table;
  101. ----
  102. Explained Query:
  103. Project (#2, #3) // { types: "(boolean, boolean)" }
  104. Map ((#0{col_null}) IS NULL, NOT(#2)) // { types: "(boolean?, boolean, boolean, boolean)" }
  105. ReadStorage materialize.public.bool_table // { types: "(boolean?, boolean)" }
  106. Source materialize.public.bool_table
  107. Target cluster: quickstart
  108. EOF
  109. #
  110. # Try some other operators
  111. #
  112. query T multiline
  113. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_not_null + col_not_null , col_not_null + 1 , col_not_null % col_not_null , col_not_null % 2 FROM int_table;
  114. ----
  115. Explained Query:
  116. Project (#2..=#5) // { types: "(integer, integer, integer, integer)" }
  117. Map ((#1{col_not_null} + #1{col_not_null}), (#1{col_not_null} + 1), (#1{col_not_null} % #1{col_not_null}), (#1{col_not_null} % 2)) // { types: "(integer?, integer, integer, integer, integer, integer)" }
  118. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  119. Source materialize.public.int_table
  120. Target cluster: quickstart
  121. EOF
  122. #
  123. # GREATEST / LEAST / COALESCE are NOT NULL if at leat one of their arguments is NOT NULL
  124. #
  125. query T multiline
  126. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT GREATEST(col_not_null), GREATEST(col_not_null, col_not_null), GREATEST(col_not_null, col_null), GREATEST(col_null, col_null) FROM int_table;
  127. ----
  128. Explained Query:
  129. Project (#2..=#5) // { types: "(integer, integer, integer?, integer?)" }
  130. Map (greatest(#1{col_not_null}), greatest(#1{col_not_null}, #1{col_not_null}), greatest(#1{col_not_null}, #0{col_null}), greatest(#0{col_null}, #0{col_null})) // { types: "(integer?, integer, integer, integer, integer?, integer?)" }
  131. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  132. Source materialize.public.int_table
  133. Target cluster: quickstart
  134. EOF
  135. query T multiline
  136. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT LEAST(col_not_null), LEAST(col_not_null, col_not_null), LEAST(col_not_null, col_null), LEAST(col_null, col_null) FROM int_table;
  137. ----
  138. Explained Query:
  139. Project (#2..=#5) // { types: "(integer, integer, integer?, integer?)" }
  140. Map (least(#1{col_not_null}), least(#1{col_not_null}, #1{col_not_null}), least(#1{col_not_null}, #0{col_null}), least(#0{col_null}, #0{col_null})) // { types: "(integer?, integer, integer, integer, integer?, integer?)" }
  141. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  142. Source materialize.public.int_table
  143. Target cluster: quickstart
  144. EOF
  145. query T multiline
  146. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT COALESCE(col_not_null), COALESCE(col_not_null, col_not_null), COALESCE(col_not_null, col_null), COALESCE(col_null, col_null) FROM int_table;
  147. ----
  148. Explained Query:
  149. Project (#1{col_not_null}, #1{col_not_null}, #1{col_not_null}, #0{col_null}) // { types: "(integer, integer, integer, integer?)" }
  150. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  151. Source materialize.public.int_table
  152. Target cluster: quickstart
  153. EOF
  154. #
  155. # NULLIF is NOT NULL if first argument is NOT NULL, second argument is NULL, NULL-able otherwise
  156. #
  157. query T multiline
  158. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT NULLIF(col_not_null, 'a') , NULLIF(col_not_null, NULL), NULLIF(col_null, NULL) , NULLIF(col_null, col_not_null) FROM int_table;
  159. ----
  160. Explained Query:
  161. Project (#3, #1{col_not_null}, #0{col_null}, #2) // { types: "(integer?, integer, integer?, integer?)" }
  162. Map (case when (#0{col_null} = #1{col_not_null}) then null else #0{col_null} end, error("invalid input syntax for type integer: invalid digit found in string: \"a\"")) // { types: "(integer?, integer, integer?, integer?)" }
  163. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  164. Source materialize.public.int_table
  165. Target cluster: quickstart
  166. EOF
  167. #
  168. # Equality, logical operators
  169. #
  170. query T multiline
  171. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_not_null = 1 FROM int_table;
  172. ----
  173. Explained Query:
  174. Project (#2) // { types: "(boolean)" }
  175. Map ((#1{col_not_null} = 1)) // { types: "(integer?, integer, boolean)" }
  176. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  177. Source materialize.public.int_table
  178. Target cluster: quickstart
  179. EOF
  180. query T multiline
  181. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_not_null AND col_not_null , col_not_null OR col_not_null FROM bool_table;
  182. ----
  183. Explained Query:
  184. Project (#1{col_not_null}, #1{col_not_null}) // { types: "(boolean, boolean)" }
  185. ReadStorage materialize.public.bool_table // { types: "(boolean?, boolean)" }
  186. Source materialize.public.bool_table
  187. Target cluster: quickstart
  188. EOF
  189. query T multiline
  190. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_null AND col_not_null , col_null OR col_not_null FROM bool_table;
  191. ----
  192. Explained Query:
  193. Project (#2, #3) // { types: "(boolean?, boolean?)" }
  194. Map ((#0{col_null} AND #1{col_not_null}), (#0{col_null} OR #1{col_not_null})) // { types: "(boolean?, boolean, boolean?, boolean?)" }
  195. ReadStorage materialize.public.bool_table // { types: "(boolean?, boolean)" }
  196. Source materialize.public.bool_table
  197. Target cluster: quickstart
  198. EOF
  199. query T multiline
  200. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT NOT col_null , NOT col_not_null FROM bool_table;
  201. ----
  202. Explained Query:
  203. Project (#2, #3) // { types: "(boolean?, boolean)" }
  204. Map (NOT(#0{col_null}), NOT(#1{col_not_null})) // { types: "(boolean?, boolean, boolean?, boolean)" }
  205. ReadStorage materialize.public.bool_table // { types: "(boolean?, boolean)" }
  206. Source materialize.public.bool_table
  207. Target cluster: quickstart
  208. EOF
  209. #
  210. # Meth, that is, math
  211. #
  212. query T multiline
  213. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT ABS(col_not_null), LOG(col_not_null), ROUND(col_not_null), COS(col_not_null), col_not_null << col_not_null FROM int_table;
  214. ----
  215. Explained Query:
  216. Project (#2, #4..=#7) // { types: "(integer, double precision, double precision, double precision, integer)" }
  217. Map (abs(#1{col_not_null}), integer_to_double(#1{col_not_null}), log10f64(#3), roundf64(#3), cos(#3), (#1{col_not_null} << #1{col_not_null})) // { types: "(integer?, integer, integer, double precision, double precision, double precision, double precision, integer)" }
  218. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  219. Source materialize.public.int_table
  220. Target cluster: quickstart
  221. EOF
  222. #
  223. # MIN/MAX/AVG/.. can be NULL even on a NOT NULL column
  224. #
  225. query T multiline
  226. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT MIN(col_not_null), MAX(col_not_null), AVG(col_not_null), STDDEV(col_not_null), LIST_AGG(col_not_null) FROM int_table;
  227. ----
  228. Explained Query:
  229. With
  230. cte l0 =
  231. Reduce aggregates=[min(#0{col_not_null}), max(#0{col_not_null}), sum(#0{col_not_null}), count(*), sum((integer_to_numeric(#0{col_not_null}) * integer_to_numeric(#0{col_not_null}))), sum(integer_to_numeric(#0{col_not_null})), count(integer_to_numeric(#0{col_not_null})), list_agg[order_by=[]](row(list[#0{col_not_null}]))] // { types: "(integer, integer, bigint, bigint, numeric, numeric, bigint, integer list)" }
  232. Project (#1{col_not_null}) // { types: "(integer)" }
  233. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  234. Return // { types: "(integer?, integer?, numeric?, numeric?, integer list?)" }
  235. Project (#0{min_col_not_null}, #1{max_col_not_null}, #8, #9, #7{list_agg}) // { types: "(integer?, integer?, numeric?, numeric?, integer list?)" }
  236. Map ((bigint_to_numeric(#2{sum_col_not_null}) / bigint_to_numeric(case when (#3{count} = 0) then null else #3{count} end)), sqrtnumeric(case when ((#4{sum}) IS NULL OR (#5{sum}) IS NULL OR (case when (#6{count} = 0) then null else #6{count} end) IS NULL OR (case when (0 = (#6{count} - 1)) then null else (#6{count} - 1) end) IS NULL) then null else greatest(((#4{sum} - ((#5{sum} * #5{sum}) / bigint_to_numeric(case when (#6{count} = 0) then null else #6{count} end))) / bigint_to_numeric(case when (0 = (#6{count} - 1)) then null else (#6{count} - 1) end)), 0) end)) // { types: "(integer?, integer?, bigint?, bigint, numeric?, numeric?, bigint, integer list?, numeric?, numeric?)" }
  237. Union // { types: "(integer?, integer?, bigint?, bigint, numeric?, numeric?, bigint, integer list?)" }
  238. Get l0 // { types: "(integer, integer, bigint, bigint, numeric, numeric, bigint, integer list)" }
  239. Map (null, null, null, 0, null, null, 0, null) // { types: "(integer?, integer?, bigint?, bigint, numeric?, numeric?, bigint, integer list?)" }
  240. Union // { types: "()" }
  241. Negate // { types: "()" }
  242. Project () // { types: "()" }
  243. Get l0 // { types: "(integer, integer, bigint, bigint, numeric, numeric, bigint, integer list)" }
  244. Constant // { types: "()" }
  245. - ()
  246. Source materialize.public.int_table
  247. Target cluster: quickstart
  248. EOF
  249. #
  250. # COUNT preserves NOT NULL
  251. #
  252. query T multiline
  253. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT COUNT(col_not_null), COUNT(DISTINCT col_not_null) FROM int_table;
  254. ----
  255. Explained Query:
  256. With
  257. cte l0 =
  258. Reduce aggregates=[count(*), count(distinct #0{col_not_null})] // { types: "(bigint, bigint)" }
  259. Project (#1{col_not_null}) // { types: "(integer)" }
  260. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  261. Return // { types: "(bigint, bigint)" }
  262. Union // { types: "(bigint, bigint)" }
  263. Get l0 // { types: "(bigint, bigint)" }
  264. Map (0, 0) // { types: "(bigint, bigint)" }
  265. Union // { types: "()" }
  266. Negate // { types: "()" }
  267. Project () // { types: "()" }
  268. Get l0 // { types: "(bigint, bigint)" }
  269. Constant // { types: "()" }
  270. - ()
  271. Source materialize.public.int_table
  272. Target cluster: quickstart
  273. EOF
  274. #
  275. # LIKE
  276. #
  277. query T multiline
  278. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_not_null LIKE col_not_null, col_null LIKE col_not_null, col_not_null LIKE col_null FROM str_table;
  279. ----
  280. Explained Query:
  281. Project (#2..=#4) // { types: "(boolean, boolean?, boolean?)" }
  282. Map ((#1{col_not_null} like #1{col_not_null}), (#0{col_null} like #1{col_not_null}), (#1{col_not_null} like #0{col_null})) // { types: "(text?, text, boolean, boolean?, boolean?)" }
  283. ReadStorage materialize.public.str_table // { types: "(text?, text)" }
  284. Source materialize.public.str_table
  285. Target cluster: quickstart
  286. EOF
  287. # VARIADIC FUNCTIONS
  288. query T multiline
  289. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_not_null || col_not_null, substr(col_not_null, 3, 2), regexp_match(col_not_null, col_not_null), lpad(col_not_null, 3, col_not_null) FROM str_table;
  290. ----
  291. Explained Query:
  292. Project (#2..=#5) // { types: "(text, text, text[]?, text)" }
  293. Map ((#1{col_not_null} || #1{col_not_null}), substr(#1{col_not_null}, 3, 2), regexp_match(#1{col_not_null}, #1{col_not_null}), lpad(#1{col_not_null}, 3, #1{col_not_null})) // { types: "(text?, text, text, text, text[]?, text)" }
  294. ReadStorage materialize.public.str_table // { types: "(text?, text)" }
  295. Source materialize.public.str_table
  296. Target cluster: quickstart
  297. EOF
  298. # VARIADIC FUNCTIONS that introduce nulls
  299. query BBBBBBB
  300. SELECT COALESCE(NULLIF('a', 'a')) IS NULL, GREATEST(NULLIF('a', 'a')) IS NULL, LEAST(NULLIF('a', 'a')) IS NULL, MAKE_TIMESTAMP(2023, 1, 1, 0, 0, 11111) IS NULL, (ARRAY[1, 2])[3] IS NULL, (LIST[1, 2])[3] IS NULL, REGEXP_MATCH('a', 'b') IS NULL;
  301. ----
  302. true true true true true true true
  303. # BINARY FUNCTIONS that introduce nulls
  304. # MapGetValue and ListLengthMax not covered
  305. query BBBBBBBBB
  306. SELECT (col_not_null -> 'x')::int IS NULL, (col_not_null -> 'y')::text IS NULL, col_not_null #> '{z}' IS NULL, ('1'::JSONB) || ('2'::JSONB) IS NULL, ('1'::jsonb) - 1 IS NULL, ('1'::jsonb) - 'x' IS NULL, ARRAY_LENGTH(ARRAY[]::INT[], 1) IS NULL, ARRAY_LOWER(ARRAY[]::INT[], 1) IS NULL, ARRAY_UPPER(ARRAY[]::INT[], 1) IS NULL FROM json_table;
  307. ----
  308. true true true true true true true true true
  309. #
  310. # REGEXP returns NULL on no match, so can not be NOT NULL
  311. #
  312. query T multiline
  313. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT REGEXP_MATCH(col_not_null, 'aaa'), REGEXP_MATCH('aaa', col_not_null) FROM str_table;
  314. ----
  315. Explained Query:
  316. Project (#2, #3) // { types: "(text[]?, text[]?)" }
  317. Map (regexp_match["aaa", case_insensitive=false](#1{col_not_null}), regexp_match("aaa", #1{col_not_null})) // { types: "(text?, text, text[]?, text[]?)" }
  318. ReadStorage materialize.public.str_table // { types: "(text?, text)" }
  319. Source materialize.public.str_table
  320. Target cluster: quickstart
  321. EOF
  322. #
  323. # SPLIT_PART on the other hand returns an empty string, so can be NOT NULL
  324. #
  325. query T multiline
  326. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT SPLIT_PART(col_not_null, 'a', 100), SPLIT_PART('a', col_not_null, 100), SPLIT_PART('a', 'a', col_not_null::int) FROM str_table;
  327. ----
  328. Explained Query:
  329. Project (#2..=#4) // { types: "(text, text, text)" }
  330. Map (split_string(#1{col_not_null}, "a", 100), split_string("a", #1{col_not_null}, 100), split_string("a", "a", text_to_integer(#1{col_not_null}))) // { types: "(text?, text, text, text, text)" }
  331. ReadStorage materialize.public.str_table // { types: "(text?, text)" }
  332. Source materialize.public.str_table
  333. Target cluster: quickstart
  334. EOF
  335. #
  336. # IN , NOT IN
  337. #
  338. query T multiline
  339. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_not_null IN (1), 1 IN (col_not_null), 1 IN (1, col_null) , 1 IN (NULL), NULL IN (1), NULL IN (col_not_null) FROM int_table;
  340. ----
  341. Explained Query:
  342. Project (#2, #2..=#6) // { types: "(boolean, boolean, boolean, boolean?, boolean?, boolean?)" }
  343. Map ((#1{col_not_null} = 1), true, null, null, null) // { types: "(integer?, integer, boolean, boolean, boolean?, boolean?, boolean?)" }
  344. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  345. Source materialize.public.int_table
  346. Target cluster: quickstart
  347. EOF
  348. query T multiline
  349. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_not_null NOT IN (1), 1 not IN (col_not_null), 1 NOT IN (1, col_null) , 1 NOT IN (NULL), NULL NOT IN (1), NULL NOT IN (col_not_null) FROM int_table;
  350. ----
  351. Explained Query:
  352. Project (#2, #2..=#6) // { types: "(boolean, boolean, boolean, boolean?, boolean?, boolean?)" }
  353. Map ((#1{col_not_null} != 1), false, null, null, null) // { types: "(integer?, integer, boolean, boolean, boolean?, boolean?, boolean?)" }
  354. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  355. Source materialize.public.int_table
  356. Target cluster: quickstart
  357. EOF
  358. #
  359. # SOME, ANY, ALL
  360. #
  361. query T multiline
  362. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT 1 = SOME (VALUES(col_null)), 1 = SOME (VALUES(col_not_null)), col_null = SOME (VALUES(NULL::int)), col_not_null = SOME (VALUES(NULL::int)) , col_null = SOME (VALUES(col_not_null)) , col_not_null = SOME (VALUES(col_null)) FROM int_table;
  363. ----
  364. Explained Query:
  365. With
  366. cte l0 =
  367. Distinct project=[#0{col_null}, #1{col_not_null}] // { types: "(integer?, integer)" }
  368. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  369. Return // { types: "(boolean?, boolean, boolean?, boolean?, boolean?, boolean?)" }
  370. Project (#5, #4, #7, #8, #6, #6) // { types: "(boolean?, boolean, boolean?, boolean?, boolean?, boolean?)" }
  371. Map ((#0{col_null} = 1), (#0{col_null} = #1{col_not_null}), null, null) // { types: "(integer?, integer, integer?, integer, boolean, boolean?, boolean?, boolean?, boolean?)" }
  372. Join on=(#0{col_null} = #2{col_null} AND #1{col_not_null} = #3{col_not_null}) type=differential // { types: "(integer?, integer, integer?, integer, boolean)" }
  373. ArrangeBy keys=[[#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer)" }
  374. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  375. ArrangeBy keys=[[#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer, boolean)" }
  376. Union // { types: "(integer?, integer, boolean)" }
  377. Filter (#1{col_not_null} = 1) // { types: "(integer?, integer, boolean)" }
  378. Map (true) // { types: "(integer?, integer, boolean)" }
  379. Get l0 // { types: "(integer?, integer)" }
  380. Map (false) // { types: "(integer?, integer, boolean)" }
  381. Union // { types: "(integer?, integer)" }
  382. Negate // { types: "(integer?, integer)" }
  383. Filter (#1{col_not_null} = 1) // { types: "(integer?, integer)" }
  384. Get l0 // { types: "(integer?, integer)" }
  385. Get l0 // { types: "(integer?, integer)" }
  386. Source materialize.public.int_table
  387. Target cluster: quickstart
  388. EOF
  389. query T multiline
  390. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT 1 > ANY (VALUES(col_null)), 1 > ANY (VALUES(col_not_null)), col_null > ANY (VALUES(NULL::int)), col_not_null > ANY (VALUES(NULL::int)) , col_null > ANY (VALUES(col_not_null)) , col_not_null > ANY (VALUES(col_null)) FROM int_table;
  391. ----
  392. Explained Query:
  393. With
  394. cte l0 =
  395. Distinct project=[#0{col_null}, #1{col_not_null}] // { types: "(integer?, integer)" }
  396. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  397. Return // { types: "(boolean?, boolean, boolean?, boolean?, boolean?, boolean?)" }
  398. Project (#5, #4, #8, #9, #6, #7) // { types: "(boolean?, boolean, boolean?, boolean?, boolean?, boolean?)" }
  399. Map ((1 > #0{col_null}), (#0{col_null} > #1{col_not_null}), (#1{col_not_null} > #0{col_null}), null, null) // { types: "(integer?, integer, integer?, integer, boolean, boolean?, boolean?, boolean?, boolean?, boolean?)" }
  400. Join on=(#0{col_null} = #2{col_null} AND #1{col_not_null} = #3{col_not_null}) type=differential // { types: "(integer?, integer, integer?, integer, boolean)" }
  401. ArrangeBy keys=[[#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer)" }
  402. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  403. ArrangeBy keys=[[#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer, boolean)" }
  404. Union // { types: "(integer?, integer, boolean)" }
  405. Filter (1 > #1{col_not_null}) // { types: "(integer?, integer, boolean)" }
  406. Map (true) // { types: "(integer?, integer, boolean)" }
  407. Get l0 // { types: "(integer?, integer)" }
  408. Map (false) // { types: "(integer?, integer, boolean)" }
  409. Union // { types: "(integer?, integer)" }
  410. Negate // { types: "(integer?, integer)" }
  411. Filter (1 > #1{col_not_null}) // { types: "(integer?, integer)" }
  412. Get l0 // { types: "(integer?, integer)" }
  413. Get l0 // { types: "(integer?, integer)" }
  414. Source materialize.public.int_table
  415. Target cluster: quickstart
  416. EOF
  417. query T multiline
  418. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT 1 < ALL (VALUES(col_null)), 1 < ALL (VALUES(col_not_null)), col_null < ALL (VALUES(NULL::int)), col_not_null < ALL (VALUES(NULL::int)) , col_null < ALL (VALUES(col_not_null)) , col_not_null < ALL (VALUES(col_null)) FROM int_table;
  419. ----
  420. Explained Query:
  421. With
  422. cte l0 =
  423. Distinct project=[#0{col_null}, #1{col_not_null}] // { types: "(integer?, integer)" }
  424. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  425. Return // { types: "(boolean?, boolean, boolean?, boolean?, boolean?, boolean?)" }
  426. Project (#5, #8..=#10, #6, #7) // { types: "(boolean?, boolean, boolean?, boolean?, boolean?, boolean?)" }
  427. Map ((1 < #0{col_null}), (#0{col_null} < #1{col_not_null}), (#1{col_not_null} < #0{col_null}), NOT(#4), null, null) // { types: "(integer?, integer, integer?, integer, boolean, boolean?, boolean?, boolean?, boolean, boolean?, boolean?)" }
  428. Join on=(#0{col_null} = #2{col_null} AND #1{col_not_null} = #3{col_not_null}) type=differential // { types: "(integer?, integer, integer?, integer, boolean)" }
  429. ArrangeBy keys=[[#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer)" }
  430. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  431. ArrangeBy keys=[[#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer, boolean)" }
  432. Union // { types: "(integer?, integer, boolean)" }
  433. Filter (1 >= #1{col_not_null}) // { types: "(integer?, integer, boolean)" }
  434. Map (true) // { types: "(integer?, integer, boolean)" }
  435. Get l0 // { types: "(integer?, integer)" }
  436. Map (false) // { types: "(integer?, integer, boolean)" }
  437. Union // { types: "(integer?, integer)" }
  438. Negate // { types: "(integer?, integer)" }
  439. Filter (1 >= #1{col_not_null}) // { types: "(integer?, integer)" }
  440. Get l0 // { types: "(integer?, integer)" }
  441. Get l0 // { types: "(integer?, integer)" }
  442. Source materialize.public.int_table
  443. Target cluster: quickstart
  444. EOF
  445. query T multiline
  446. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT 1 = SOME(VALUES(1), (NULL::int)), 1 = ALL (VALUES(1), (NULL::int)) , 1 = ANY (VALUES(1), (NULL::int));
  447. ----
  448. Explained Query:
  449. Constant // { types: "(boolean, boolean?, boolean)" }
  450. - (true, null, true)
  451. Target cluster: quickstart
  452. EOF
  453. query T multiline
  454. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT 1 = SOME(VALUES(NULL::int), (1)), 1 = ALL (VALUES(NULL::int), (1)) , 1 = ANY (VALUES(NULL::int), (1));
  455. ----
  456. Explained Query:
  457. Constant // { types: "(boolean, boolean?, boolean)" }
  458. - (true, null, true)
  459. Target cluster: quickstart
  460. EOF
  461. query T multiline
  462. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT 1 = SOME(VALUES(col_not_null), (NULL::int)), 1 = ALL (VALUES(col_not_null), (NULL::int)) , 1 = ANY (VALUES(col_not_null), (NULL::int)) FROM int_table;
  463. ----
  464. Explained Query:
  465. With
  466. cte l0 =
  467. Project (#1{col_not_null}) // { types: "(integer)" }
  468. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  469. cte l1 =
  470. Distinct project=[#0{col_not_null}] // { types: "(integer)" }
  471. Get l0 // { types: "(integer)" }
  472. cte l2 =
  473. FlatMap wrap1(#0{col_not_null}, null) // { types: "(integer, integer?)" }
  474. Get l1 // { types: "(integer)" }
  475. cte l3 =
  476. Reduce group_by=[#0{col_not_null}] aggregates=[any((#1{right_col0_0} = 1))] // { types: "(integer, boolean?)" }
  477. Get l2 // { types: "(integer, integer?)" }
  478. cte l4 =
  479. Union // { types: "(integer, boolean?)" }
  480. Get l3 // { types: "(integer, boolean?)" }
  481. Map (false) // { types: "(integer, boolean)" }
  482. Union // { types: "(integer)" }
  483. Negate // { types: "(integer)" }
  484. Project (#0{col_not_null}) // { types: "(integer)" }
  485. Get l3 // { types: "(integer, boolean?)" }
  486. Get l1 // { types: "(integer)" }
  487. cte l5 =
  488. Reduce group_by=[#0{col_not_null}] aggregates=[all((#1{right_col0_2} = 1))] // { types: "(integer, boolean?)" }
  489. Get l2 // { types: "(integer, integer?)" }
  490. cte l6 =
  491. Union // { types: "(integer, boolean?)" }
  492. Get l5 // { types: "(integer, boolean?)" }
  493. Map (true) // { types: "(integer, boolean)" }
  494. Union // { types: "(integer)" }
  495. Negate // { types: "(integer)" }
  496. Project (#0{col_not_null}) // { types: "(integer)" }
  497. Get l5 // { types: "(integer, boolean?)" }
  498. Get l1 // { types: "(integer)" }
  499. Return // { types: "(boolean?, boolean?, boolean?)" }
  500. Project (#2{any}, #4{all}, #2{any}) // { types: "(boolean?, boolean?, boolean?)" }
  501. Join on=(#0{col_not_null} = #1{col_not_null} = #3{col_not_null}) type=delta // { types: "(integer, integer, boolean?, integer, boolean?)" }
  502. ArrangeBy keys=[[#0{col_not_null}]] // { types: "(integer)" }
  503. Get l0 // { types: "(integer)" }
  504. ArrangeBy keys=[[#0{col_not_null}]] // { types: "(integer, boolean?)" }
  505. Union // { types: "(integer, boolean?)" }
  506. Get l4 // { types: "(integer, boolean?)" }
  507. Map (null) // { types: "(integer, boolean?)" }
  508. Union // { types: "(integer)" }
  509. Negate // { types: "(integer)" }
  510. Project (#0{col_not_null}) // { types: "(integer)" }
  511. Get l4 // { types: "(integer, boolean?)" }
  512. Get l1 // { types: "(integer)" }
  513. ArrangeBy keys=[[#0{col_not_null}]] // { types: "(integer, boolean?)" }
  514. Union // { types: "(integer, boolean?)" }
  515. Get l6 // { types: "(integer, boolean?)" }
  516. Map (null) // { types: "(integer, boolean?)" }
  517. Union // { types: "(integer)" }
  518. Negate // { types: "(integer)" }
  519. Project (#0{col_not_null}) // { types: "(integer)" }
  520. Get l6 // { types: "(integer, boolean?)" }
  521. Get l1 // { types: "(integer)" }
  522. Source materialize.public.int_table
  523. Target cluster: quickstart
  524. EOF
  525. #
  526. # Scalar subqueries can return NULL on no rows returned by the subquery
  527. #
  528. query T multiline
  529. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT (SELECT col_not_null FROM int_table) FROM int_table;
  530. ----
  531. Explained Query:
  532. With
  533. cte l0 =
  534. Project () // { types: "()" }
  535. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  536. cte l1 =
  537. Union // { types: "(integer)" }
  538. Project (#1{col_not_null}) // { types: "(integer)" }
  539. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  540. Project (#1) // { types: "(integer)" }
  541. FlatMap guard_subquery_size(#0{count}) // { types: "(bigint, integer)" }
  542. Reduce aggregates=[count(*)] // { types: "(bigint)" }
  543. Get l0 // { types: "()" }
  544. Return // { types: "(integer?)" }
  545. CrossJoin type=differential // { types: "(integer?)" }
  546. ArrangeBy keys=[[]] // { types: "()" }
  547. Get l0 // { types: "()" }
  548. ArrangeBy keys=[[]] // { types: "(integer?)" }
  549. Union // { types: "(integer?)" }
  550. Get l1 // { types: "(integer)" }
  551. Map (null) // { types: "(integer?)" }
  552. Union // { types: "()" }
  553. Negate // { types: "()" }
  554. Distinct project=[] // { types: "()" }
  555. Project () // { types: "()" }
  556. Get l1 // { types: "(integer)" }
  557. Constant // { types: "()" }
  558. - ()
  559. Source materialize.public.int_table
  560. Target cluster: quickstart
  561. EOF
  562. #
  563. # IN/EXISTS
  564. #
  565. query T multiline
  566. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT 1 IN (SELECT col_not_null FROM int_table), 1 NOT IN (SELECT col_not_null FROM int_table) FROM int_table;
  567. ----
  568. Explained Query:
  569. With
  570. cte l0 =
  571. Distinct project=[] // { types: "()" }
  572. Project () // { types: "()" }
  573. Filter (#1{col_not_null} = 1) // { types: "(integer?, integer)" }
  574. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  575. cte l1 =
  576. ArrangeBy keys=[[]] // { types: "(boolean)" }
  577. Union // { types: "(boolean)" }
  578. Map (true) // { types: "(boolean)" }
  579. Get l0 // { types: "()" }
  580. Map (false) // { types: "(boolean)" }
  581. Union // { types: "()" }
  582. Negate // { types: "()" }
  583. Get l0 // { types: "()" }
  584. Constant // { types: "()" }
  585. - ()
  586. Return // { types: "(boolean, boolean)" }
  587. Project (#0, #2) // { types: "(boolean, boolean)" }
  588. Map (NOT(#1)) // { types: "(boolean, boolean, boolean)" }
  589. CrossJoin type=delta // { types: "(boolean, boolean)" }
  590. ArrangeBy keys=[[]] // { types: "()" }
  591. Project () // { types: "()" }
  592. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  593. Get l1 // { types: "(boolean)" }
  594. Get l1 // { types: "(boolean)" }
  595. Source materialize.public.int_table
  596. Target cluster: quickstart
  597. EOF
  598. query T multiline
  599. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT EXISTS (SELECT col_not_null FROM int_table), NOT EXISTS (SELECT col_not_null FROM int_table) FROM int_table;
  600. ----
  601. Explained Query:
  602. With
  603. cte l0 =
  604. Project () // { types: "()" }
  605. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  606. cte l1 =
  607. Distinct project=[] // { types: "()" }
  608. Get l0 // { types: "()" }
  609. Return // { types: "(boolean, boolean)" }
  610. Map (NOT(#0{"?column?"})) // { types: "(boolean, boolean)" }
  611. CrossJoin type=differential // { types: "(boolean)" }
  612. ArrangeBy keys=[[]] // { types: "()" }
  613. Get l0 // { types: "()" }
  614. ArrangeBy keys=[[]] // { types: "(boolean)" }
  615. Union // { types: "(boolean)" }
  616. Map (true) // { types: "(boolean)" }
  617. Get l1 // { types: "()" }
  618. Map (false) // { types: "(boolean)" }
  619. Union // { types: "()" }
  620. Negate // { types: "()" }
  621. Get l1 // { types: "()" }
  622. Constant // { types: "()" }
  623. - ()
  624. Source materialize.public.int_table
  625. Target cluster: quickstart
  626. EOF
  627. query T multiline
  628. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT 1 = SOME (SELECT col_not_null FROM int_table), col_not_null = SOME (SELECT 1), col_null = SOME ( SELECT col_not_null FROM int_table ) FROM int_table;
  629. ----
  630. Explained Query:
  631. With
  632. cte l0 =
  633. Distinct project=[] // { types: "()" }
  634. Project () // { types: "()" }
  635. Filter (#1{col_not_null} = 1) // { types: "(integer?, integer)" }
  636. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  637. cte l1 =
  638. Distinct project=[#0{col_null}, #1{col_not_null}] // { types: "(integer?, integer)" }
  639. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  640. cte l2 =
  641. Distinct project=[#0{col_null}] // { types: "(integer?)" }
  642. Project (#0{col_null}) // { types: "(integer?)" }
  643. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  644. cte l3 =
  645. Reduce group_by=[#0{col_null}] aggregates=[any((#0{col_null} = #1{col_not_null}))] // { types: "(integer?, boolean?)" }
  646. CrossJoin type=differential // { types: "(integer?, integer)" }
  647. ArrangeBy keys=[[]] // { types: "(integer?)" }
  648. Get l2 // { types: "(integer?)" }
  649. ArrangeBy keys=[[]] // { types: "(integer)" }
  650. Project (#1{col_not_null}) // { types: "(integer)" }
  651. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  652. cte l4 =
  653. Union // { types: "(integer?, boolean?)" }
  654. Get l3 // { types: "(integer?, boolean?)" }
  655. Map (false) // { types: "(integer?, boolean)" }
  656. Union // { types: "(integer?)" }
  657. Negate // { types: "(integer?)" }
  658. Project (#0{col_null}) // { types: "(integer?)" }
  659. Get l3 // { types: "(integer?, boolean?)" }
  660. Get l2 // { types: "(integer?)" }
  661. Return // { types: "(boolean, boolean, boolean?)" }
  662. Project (#2, #5, #7{any}) // { types: "(boolean, boolean, boolean?)" }
  663. Join on=(#0{col_null} = #3{col_null} = #6{col_null} AND #1{col_not_null} = #4{col_not_null}) type=delta // { types: "(integer?, integer, boolean, integer?, integer, boolean, integer?, boolean?)" }
  664. ArrangeBy keys=[[], [#0{col_null}], [#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer)" }
  665. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  666. ArrangeBy keys=[[]] // { types: "(boolean)" }
  667. Union // { types: "(boolean)" }
  668. Map (true) // { types: "(boolean)" }
  669. Get l0 // { types: "()" }
  670. Map (false) // { types: "(boolean)" }
  671. Union // { types: "()" }
  672. Negate // { types: "()" }
  673. Get l0 // { types: "()" }
  674. Constant // { types: "()" }
  675. - ()
  676. ArrangeBy keys=[[#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer, boolean)" }
  677. Union // { types: "(integer?, integer, boolean)" }
  678. Filter (#1{col_not_null} = 1) // { types: "(integer?, integer, boolean)" }
  679. Map (true) // { types: "(integer?, integer, boolean)" }
  680. Get l1 // { types: "(integer?, integer)" }
  681. Map (false) // { types: "(integer?, integer, boolean)" }
  682. Union // { types: "(integer?, integer)" }
  683. Negate // { types: "(integer?, integer)" }
  684. Filter (#1{col_not_null} = 1) // { types: "(integer?, integer)" }
  685. Get l1 // { types: "(integer?, integer)" }
  686. Get l1 // { types: "(integer?, integer)" }
  687. ArrangeBy keys=[[#0{col_null}]] // { types: "(integer?, boolean?)" }
  688. Union // { types: "(integer?, boolean?)" }
  689. Get l4 // { types: "(integer?, boolean?)" }
  690. Map (null) // { types: "(integer?, boolean?)" }
  691. Union // { types: "(integer?)" }
  692. Negate // { types: "(integer?)" }
  693. Project (#0{col_null}) // { types: "(integer?)" }
  694. Get l4 // { types: "(integer?, boolean?)" }
  695. Get l2 // { types: "(integer?)" }
  696. Source materialize.public.int_table
  697. Target cluster: quickstart
  698. EOF
  699. #
  700. # DATE / TIME functions
  701. #
  702. query T multiline
  703. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_null - INTERVAL '1 second' , col_not_null - INTERVAL '1 second' FROM ts_table;
  704. ----
  705. Explained Query:
  706. Project (#2, #3) // { types: "(timestamp without time zone?, timestamp without time zone)" }
  707. Map ((#0{col_null} - 00:00:01), (#1{col_not_null} - 00:00:01)) // { types: "(timestamp without time zone?, timestamp without time zone, timestamp without time zone?, timestamp without time zone)" }
  708. ReadStorage materialize.public.ts_table // { types: "(timestamp without time zone?, timestamp without time zone)" }
  709. Source materialize.public.ts_table
  710. Target cluster: quickstart
  711. EOF
  712. query T multiline
  713. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_null - col_not_null, col_not_null - col_null FROM ts_table;
  714. ----
  715. Explained Query:
  716. Project (#2, #3) // { types: "(interval?, interval?)" }
  717. Map ((#0{col_null} - #1{col_not_null}), (#1{col_not_null} - #0{col_null})) // { types: "(timestamp without time zone?, timestamp without time zone, interval?, interval?)" }
  718. ReadStorage materialize.public.ts_table // { types: "(timestamp without time zone?, timestamp without time zone)" }
  719. Source materialize.public.ts_table
  720. Target cluster: quickstart
  721. EOF
  722. #
  723. # INNER JOIN preserves
  724. #
  725. query T multiline
  726. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT a1.col_not_null, a2.col_not_null FROM int_table AS a1 INNER JOIN int_table AS a2 ON TRUE;
  727. ----
  728. Explained Query:
  729. With
  730. cte l0 =
  731. ArrangeBy keys=[[]] // { types: "(integer)" }
  732. Project (#1{col_not_null}) // { types: "(integer)" }
  733. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  734. Return // { types: "(integer, integer)" }
  735. CrossJoin type=differential // { types: "(integer, integer)" }
  736. Get l0 // { types: "(integer)" }
  737. Get l0 // { types: "(integer)" }
  738. Source materialize.public.int_table
  739. Target cluster: quickstart
  740. EOF
  741. #
  742. # OUTER JOIN does not for columns coming from the right side
  743. #
  744. query T multiline
  745. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT a1.col_not_null, a2.col_not_null FROM int_table AS a1 LEFT JOIN int_table AS a2 ON TRUE;
  746. ----
  747. Explained Query:
  748. With
  749. cte l0 =
  750. CrossJoin type=differential // { types: "(integer?, integer, integer)" }
  751. ArrangeBy keys=[[]] // { types: "(integer?, integer)" }
  752. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  753. ArrangeBy keys=[[]] // { types: "(integer)" }
  754. Project (#1{col_not_null}) // { types: "(integer)" }
  755. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  756. Return // { types: "(integer, integer?)" }
  757. Union // { types: "(integer, integer?)" }
  758. Project (#1{col_not_null}, #2{col_not_null}) // { types: "(integer, integer)" }
  759. Get l0 // { types: "(integer?, integer, integer)" }
  760. Project (#1{col_not_null}, #4) // { types: "(integer, integer?)" }
  761. Map (null) // { types: "(integer?, integer, integer?, integer, integer?)" }
  762. Join on=(#0{col_null} = #2{col_null} AND #1{col_not_null} = #3{col_not_null}) type=differential // { types: "(integer?, integer, integer?, integer)" }
  763. ArrangeBy keys=[[#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer)" }
  764. Union // { types: "(integer?, integer)" }
  765. Negate // { types: "(integer?, integer)" }
  766. Distinct project=[#0{col_null}, #1{col_not_null}] // { types: "(integer?, integer)" }
  767. Project (#0{col_null}, #1{col_not_null}) // { types: "(integer?, integer)" }
  768. Get l0 // { types: "(integer?, integer, integer)" }
  769. Distinct project=[#0{col_null}, #1{col_not_null}] // { types: "(integer?, integer)" }
  770. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  771. ArrangeBy keys=[[#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer)" }
  772. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  773. Source materialize.public.int_table
  774. Target cluster: quickstart
  775. EOF
  776. query T multiline
  777. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT a1.col_not_null, a2.col_not_null FROM int_table AS a1 FULL OUTER JOIN int_table AS a2 ON TRUE;
  778. ----
  779. Explained Query:
  780. With
  781. cte l0 =
  782. ArrangeBy keys=[[]] // { types: "(integer?, integer)" }
  783. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  784. cte l1 =
  785. CrossJoin type=differential // { types: "(integer?, integer, integer?, integer)" }
  786. Get l0 // { types: "(integer?, integer)" }
  787. Get l0 // { types: "(integer?, integer)" }
  788. cte l2 =
  789. Distinct project=[#0{col_null}, #1{col_not_null}] // { types: "(integer?, integer)" }
  790. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  791. cte l3 =
  792. ArrangeBy keys=[[#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer)" }
  793. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  794. Return // { types: "(integer?, integer?)" }
  795. Union // { types: "(integer?, integer?)" }
  796. Project (#1{col_not_null}, #3{col_not_null}) // { types: "(integer, integer)" }
  797. Get l1 // { types: "(integer?, integer, integer?, integer)" }
  798. Project (#1{col_not_null}, #4) // { types: "(integer, integer?)" }
  799. Map (null) // { types: "(integer?, integer, integer?, integer, integer?)" }
  800. Join on=(#0{col_null} = #2{col_null} AND #1{col_not_null} = #3{col_not_null}) type=differential // { types: "(integer?, integer, integer?, integer)" }
  801. ArrangeBy keys=[[#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer)" }
  802. Union // { types: "(integer?, integer)" }
  803. Negate // { types: "(integer?, integer)" }
  804. Distinct project=[#0{col_null}, #1{col_not_null}] // { types: "(integer?, integer)" }
  805. Project (#0{col_null}, #1{col_not_null}) // { types: "(integer?, integer)" }
  806. Get l1 // { types: "(integer?, integer, integer?, integer)" }
  807. Get l2 // { types: "(integer?, integer)" }
  808. Get l3 // { types: "(integer?, integer)" }
  809. Project (#4, #1{col_not_null}) // { types: "(integer?, integer)" }
  810. Map (null) // { types: "(integer?, integer, integer?, integer, integer?)" }
  811. Join on=(#0{col_null} = #2{col_null} AND #1{col_not_null} = #3{col_not_null}) type=differential // { types: "(integer?, integer, integer?, integer)" }
  812. ArrangeBy keys=[[#0{col_null}, #1{col_not_null}]] // { types: "(integer?, integer)" }
  813. Union // { types: "(integer?, integer)" }
  814. Negate // { types: "(integer?, integer)" }
  815. Distinct project=[#0{col_null}, #1{col_not_null}] // { types: "(integer?, integer)" }
  816. Project (#2{col_null}, #3{col_not_null}) // { types: "(integer?, integer)" }
  817. Get l1 // { types: "(integer?, integer, integer?, integer)" }
  818. Get l2 // { types: "(integer?, integer)" }
  819. Get l3 // { types: "(integer?, integer)" }
  820. Source materialize.public.int_table
  821. Target cluster: quickstart
  822. EOF
  823. #
  824. # UNION
  825. #
  826. query T multiline
  827. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_not_null FROM int_table UNION ALL SELECT col_not_null FROM int_table;
  828. ----
  829. Explained Query:
  830. With
  831. cte l0 =
  832. Project (#1{col_not_null}) // { types: "(integer)" }
  833. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  834. Return // { types: "(integer)" }
  835. Union // { types: "(integer)" }
  836. Get l0 // { types: "(integer)" }
  837. Get l0 // { types: "(integer)" }
  838. Source materialize.public.int_table
  839. Target cluster: quickstart
  840. EOF
  841. query T multiline
  842. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT col_not_null FROM int_table UNION ALL SELECT col_null FROM int_table;
  843. ----
  844. Explained Query:
  845. Union // { types: "(integer?)" }
  846. Project (#1{col_not_null}) // { types: "(integer)" }
  847. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  848. Project (#0{col_null}) // { types: "(integer?)" }
  849. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  850. Source materialize.public.int_table
  851. Target cluster: quickstart
  852. EOF
  853. #
  854. # DERIVED TABLES
  855. #
  856. query T multiline
  857. EXPLAIN OPTIMIZED PLAN WITH(types, no fast path, humanized expressions) AS VERBOSE TEXT FOR SELECT f1 + 1 FROM (SELECT col_not_null + 1 AS f1 FROM int_table);
  858. ----
  859. Explained Query:
  860. Project (#2) // { types: "(integer)" }
  861. Map (((#1{col_not_null} + 1) + 1)) // { types: "(integer?, integer, integer)" }
  862. ReadStorage materialize.public.int_table // { types: "(integer?, integer)" }
  863. Source materialize.public.int_table
  864. Target cluster: quickstart
  865. EOF