github-2746.slt 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. # Regression test for https://github.com/MaterializeInc/database-issues/issues/2746
  10. mode cockroach
  11. statement ok
  12. CREATE TABLE orders ( o_orderkey integer, o_custkey integer NOT NULL, o_orderstatus text NOT NULL, o_totalprice decimal(15, 2) NOT NULL, o_orderdate DATE NOT NULL, o_orderpriority text NOT NULL, o_clerk text NOT NULL, o_shippriority integer NOT NULL, o_comment text NOT NULL);
  13. statement ok
  14. CREATE TABLE lineitem ( l_orderkey integer NOT NULL, l_partkey integer NOT NULL, l_suppkey integer NOT NULL, l_linenumber integer NOT NULL, l_quantity decimal(15, 2) NOT NULL, l_extendedprice decimal(15, 2) NOT NULL, l_discount decimal(15, 2) NOT NULL, l_tax decimal(15, 2) NOT NULL, l_returnflag text NOT NULL, l_linestatus text NOT NULL, l_shipdate date NOT NULL, l_commitdate date NOT NULL, l_receiptdate date NOT NULL, l_shipinstruct text NOT NULL, l_shipmode text NOT NULL, l_comment text NOT NULL
  15. );
  16. statement ok
  17. INSERT INTO "lineitem" VALUES (581,7,1,1,41,37187,0.09,0.07,'N','O','1997-05-26','1997-04-06','1997-06-10','TAKE BACK RETURN','MAIL','even, bold excuses about the'),(581,10,1,2,14,12740.14,0.06,0.08,'N','O','1997-05-17','1997-04-14','1997-06-08','NONE','MAIL','furiously silent depths'),(581,11,1,3,49,44639.49,0.1,0.02,'N','O','1997-02-27','1997-04-24','1997-03-10','TAKE BACK RETURN','MAIL','furiously regular theodolites wake qu'),(581,8,1,4,30,27240,0.1,0.08,'N','O','1997-06-19','1997-05-21','1997-06-22','TAKE BACK RETURN','TRUCK','even deposits wa'),(582,6,1,1,7,6342,0.07,0,'N','O','1997-11-16','1997-11-29','1997-12-10','TAKE BACK RETURN','FOB','carefully final requests sleep slyly. even,'),(582,6,1,2,49,44394,0.05,0.03,'N','O','1997-12-17','1998-01-12','1997-12-31','COLLECT COD','REG AIR','carefully regular'),(582,15,1,3,42,38430.42,0.07,0,'N','O','1997-11-15','1997-12-21','1997-12-03','COLLECT COD','SHIP','pending, spe'),(582,17,1,4,36,33012.36,0.06,0.01,'N','O','1997-12-09','1997-11-27','1997-12-26','TAKE BACK RETURN','SHIP','slyly final foxes nag permanen');
  18. statement ok
  19. INSERT INTO "orders" VALUES (547,10,'O',87538.95,'1996-06-22','3-MEDIUM','Clerk#000000976',0,'bold instructions print fluffily carefully id'),(548,13,'F',91796.96,'1994-09-21','1-URGENT','Clerk#000000435',0,'quickly regular accounts daz'),(549,11,'F',129199.61,'1992-07-13','1-URGENT','Clerk#000000196',0,'carefully regular foxes integrate ironic, fina'),(550,4,'O',27927.38,'1995-08-02','1-URGENT','Clerk#000000204',0,'carefully even asymptotes sleep furiously sp'),(551,10,'O',40845.41,'1995-05-30','1-URGENT','Clerk#000000179',0,'unusual, final accounts use above the special excuses. final depo'),(576,4,'O',17143.74,'1997-05-13','3-MEDIUM','Clerk#000000955',0,'pending theodolites about the carefu'),(577,7,'F',33465.32,'1994-12-19','5-LOW','Clerk#000000154',0,'blithely unusual packages sl'),(578,10,'O',60466.97,'1997-01-10','5-LOW','Clerk#000000281',0,'blithely pending asymptotes wake quickly across the carefully final'),(579,7,'O',116780.04,'1998-03-11','2-HIGH','Clerk#000000862',0,'slyly even requests cajole slyly. sil'),(580,7,'O',77490.74,'1997-07-05','2-HIGH','Clerk#000000314',0,'final ideas must have to are carefully quickly furious requests'),(581,7,'O',116599.09,'1997-02-23','4-NOT SPECIFIED','Clerk#000000239',0,'carefully regular dolphins cajole ruthlessl'),(582,5,'O',116419.79,'1997-10-21','1-URGENT','Clerk#000000378',0,'quietly ironic pinto beans wake carefully. ironic accounts across the dol');
  20. query I
  21. SELECT
  22. 1
  23. FROM
  24. lineitem JOIN orders ON true
  25. WHERE
  26. l_orderkey
  27. = ANY (
  28. SELECT
  29. o_orderkey
  30. FROM
  31. lineitem RIGHT JOIN orders ON true
  32. WHERE
  33. l_receiptdate IN ('1997-07-06')
  34. OR l_commitdate = o_orderdate - ' 7 DAY '
  35. );
  36. ----
  37. query T multiline
  38. EXPLAIN PHYSICAL PLAN AS VERBOSE TEXT FOR SELECT
  39. 1
  40. FROM
  41. lineitem JOIN orders ON true
  42. WHERE
  43. l_orderkey
  44. = ANY (
  45. SELECT
  46. o_orderkey
  47. FROM
  48. lineitem RIGHT JOIN orders ON true
  49. WHERE
  50. l_receiptdate IN ('1997-07-06')
  51. OR l_commitdate = o_orderdate - ' 7 DAY '
  52. );
  53. ----
  54. Explained Query:
  55. With
  56. cte l0 =
  57. Join::Linear
  58. linear_stage[0]
  59. lookup={ relation=1, key=[] }
  60. stream={ key=[], thinning=(#0) }
  61. source={ relation=0, key=[] }
  62. ArrangeBy
  63. raw=true
  64. arrangements[0]={ key=[], permutation=id, thinning=(#0) }
  65. types=[integer]
  66. Get::Collection materialize.public.lineitem
  67. project=(#0)
  68. raw=true
  69. ArrangeBy
  70. raw=true
  71. arrangements[0]={ key=[], permutation=id, thinning=() }
  72. Get::Collection materialize.public.orders
  73. project=()
  74. raw=true
  75. Return
  76. Join::Linear
  77. final_closure
  78. project=(#0)
  79. map=(1)
  80. linear_stage[0]
  81. closure
  82. project=()
  83. lookup={ relation=0, key=[#0] }
  84. stream={ key=[#0], thinning=() }
  85. source={ relation=1, key=[#0] }
  86. ArrangeBy
  87. raw=true
  88. arrangements[0]={ key=[#0], permutation=id, thinning=() }
  89. types=[integer]
  90. Get::PassArrangements l0
  91. raw=true
  92. Reduce::Distinct
  93. val_plan
  94. project=()
  95. key_plan=id
  96. Join::Delta
  97. plan_path[0]
  98. delta_stage[1]
  99. closure
  100. project=(#0)
  101. filter=(((#2{l_receiptdate} = 1997-07-06) OR (date_to_timestamp(#1{l_commitdate}) = (#3{o_orderdate} - 7 days))))
  102. lookup={ relation=2, key=[#0] }
  103. stream={ key=[#2], thinning=(#0, #1) }
  104. delta_stage[0]
  105. lookup={ relation=1, key=[] }
  106. stream={ key=[], thinning=(#0, #1) }
  107. source={ relation=0, key=[] }
  108. plan_path[1]
  109. delta_stage[1]
  110. closure
  111. project=(#0)
  112. filter=(((#3{l_receiptdate} = 1997-07-06) OR (date_to_timestamp(#2{l_commitdate}) = (#1{o_orderdate} - 7 days))))
  113. lookup={ relation=0, key=[] }
  114. stream={ key=[], thinning=(#0, #1) }
  115. delta_stage[0]
  116. lookup={ relation=2, key=[#0] }
  117. stream={ key=[#0], thinning=() }
  118. source={ relation=1, key=[] }
  119. plan_path[2]
  120. delta_stage[1]
  121. closure
  122. project=(#0)
  123. filter=(((#3{l_receiptdate} = 1997-07-06) OR (date_to_timestamp(#2{l_commitdate}) = (#1{o_orderdate} - 7 days))))
  124. lookup={ relation=0, key=[] }
  125. stream={ key=[], thinning=(#0, #1) }
  126. delta_stage[0]
  127. lookup={ relation=1, key=[#0] }
  128. stream={ key=[#0], thinning=(#1) }
  129. source={ relation=2, key=[#0] }
  130. ArrangeBy
  131. raw=true
  132. arrangements[0]={ key=[], permutation=id, thinning=(#0, #1) }
  133. types=[date, date]
  134. Get::Collection materialize.public.lineitem
  135. project=(#1, #2)
  136. raw=true
  137. ArrangeBy
  138. input_key=[#0]
  139. raw=false
  140. arrangements[0]={ key=[], permutation=id, thinning=(#0) }
  141. types=[integer]
  142. Reduce::Distinct
  143. val_plan
  144. project=()
  145. key_plan=id
  146. Get::PassArrangements l0
  147. raw=true
  148. ArrangeBy
  149. raw=true
  150. arrangements[0]={ key=[#0], permutation=id, thinning=(#1) }
  151. types=[integer, date]
  152. Get::Collection materialize.public.orders
  153. filter=((#0) IS NOT NULL)
  154. raw=true
  155. Source materialize.public.orders
  156. project=(#0, #4)
  157. Source materialize.public.lineitem
  158. project=(#0, #11, #12)
  159. Target cluster: quickstart
  160. EOF
  161. query I
  162. SELECT
  163. CASE o_orderkey
  164. WHEN 1 THEN l_orderkey
  165. ELSE (
  166. SELECT
  167. l_orderkey
  168. WHERE
  169. l_shipdate = o_orderdate + ' 3 MONTH '
  170. OR o_orderdate = l_shipdate - ' 9 DAY '
  171. AND EXISTS(
  172. SELECT
  173. 1
  174. WHERE
  175. true
  176. AND l_orderkey
  177. = ANY (
  178. SELECT
  179. o_orderkey
  180. FROM
  181. lineitem RIGHT JOIN orders ON true
  182. WHERE
  183. l_receiptdate IN ('1997-07-06') OR l_commitdate = o_orderdate - ' 7 DAY '
  184. )
  185. )
  186. )
  187. END
  188. FROM
  189. lineitem JOIN orders ON true;
  190. ----
  191. NULL
  192. NULL
  193. NULL
  194. NULL
  195. NULL
  196. NULL
  197. NULL
  198. NULL
  199. NULL
  200. NULL
  201. NULL
  202. NULL
  203. NULL
  204. NULL
  205. NULL
  206. NULL
  207. NULL
  208. NULL
  209. NULL
  210. NULL
  211. NULL
  212. NULL
  213. NULL
  214. NULL
  215. NULL
  216. NULL
  217. NULL
  218. NULL
  219. NULL
  220. NULL
  221. NULL
  222. NULL
  223. NULL
  224. NULL
  225. NULL
  226. NULL
  227. NULL
  228. NULL
  229. NULL
  230. NULL
  231. NULL
  232. NULL
  233. NULL
  234. NULL
  235. NULL
  236. NULL
  237. NULL
  238. NULL
  239. NULL
  240. NULL
  241. NULL
  242. NULL
  243. NULL
  244. NULL
  245. NULL
  246. NULL
  247. NULL
  248. NULL
  249. NULL
  250. NULL
  251. NULL
  252. NULL
  253. NULL
  254. NULL
  255. NULL
  256. NULL
  257. NULL
  258. NULL
  259. NULL
  260. NULL
  261. NULL
  262. NULL
  263. NULL
  264. NULL
  265. NULL
  266. NULL
  267. NULL
  268. NULL
  269. NULL
  270. NULL
  271. NULL
  272. NULL
  273. NULL
  274. NULL
  275. NULL
  276. NULL
  277. NULL
  278. NULL
  279. NULL
  280. NULL
  281. NULL
  282. NULL
  283. NULL
  284. NULL
  285. NULL
  286. NULL