raw_plan_as_json.slt 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  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. # Test requires stable object IDs
  10. reset-server
  11. statement ok
  12. CREATE TABLE t (
  13. a int,
  14. b int
  15. )
  16. statement ok
  17. CREATE VIEW ov AS SELECT * FROM t ORDER BY b asc, a desc LIMIT 5
  18. statement ok
  19. CREATE VIEW v AS
  20. SELECT * FROM t WHERE a IS NOT NULL
  21. statement ok
  22. CREATE DEFAULT INDEX ON v
  23. statement ok
  24. CREATE MATERIALIZED VIEW mv AS
  25. SELECT * FROM t WHERE a IS NOT NULL
  26. mode cockroach
  27. # Test basic linear chains.
  28. query T multiline
  29. EXPLAIN RAW PLAN AS JSON FOR
  30. SELECT a + 1, b, 4 FROM mv WHERE a > 0
  31. ----
  32. {
  33. "Project": {
  34. "input": {
  35. "Map": {
  36. "input": {
  37. "Filter": {
  38. "input": {
  39. "Get": {
  40. "id": {
  41. "Global": {
  42. "User": 5
  43. }
  44. },
  45. "typ": {
  46. "column_types": [
  47. {
  48. "scalar_type": "Int32",
  49. "nullable": false
  50. },
  51. {
  52. "scalar_type": "Int32",
  53. "nullable": true
  54. }
  55. ],
  56. "keys": []
  57. }
  58. }
  59. },
  60. "predicates": [
  61. {
  62. "CallBinary": {
  63. "func": "Gt",
  64. "expr1": {
  65. "Column": [
  66. {
  67. "level": 0,
  68. "column": 0
  69. },
  70. "a"
  71. ]
  72. },
  73. "expr2": {
  74. "Literal": [
  75. {
  76. "data": [
  77. 44
  78. ]
  79. },
  80. {
  81. "scalar_type": "Int32",
  82. "nullable": false
  83. },
  84. null
  85. ]
  86. },
  87. "name": null
  88. }
  89. }
  90. ]
  91. }
  92. },
  93. "scalars": [
  94. {
  95. "CallBinary": {
  96. "func": "AddInt32",
  97. "expr1": {
  98. "Column": [
  99. {
  100. "level": 0,
  101. "column": 0
  102. },
  103. "a"
  104. ]
  105. },
  106. "expr2": {
  107. "Literal": [
  108. {
  109. "data": [
  110. 45,
  111. 1
  112. ]
  113. },
  114. {
  115. "scalar_type": "Int32",
  116. "nullable": false
  117. },
  118. null
  119. ]
  120. },
  121. "name": null
  122. }
  123. },
  124. {
  125. "Literal": [
  126. {
  127. "data": [
  128. 45,
  129. 4
  130. ]
  131. },
  132. {
  133. "scalar_type": "Int32",
  134. "nullable": false
  135. },
  136. null
  137. ]
  138. }
  139. ]
  140. }
  141. },
  142. "outputs": [
  143. 2,
  144. 1,
  145. 3
  146. ]
  147. }
  148. }
  149. EOF
  150. # Test table functions (CallTable).
  151. query T multiline
  152. EXPLAIN RAW PLAN AS JSON FOR
  153. SELECT * FROM generate_series(1, 7)
  154. ----
  155. {
  156. "CallTable": {
  157. "func": "GenerateSeriesInt32",
  158. "exprs": [
  159. {
  160. "Literal": [
  161. {
  162. "data": [
  163. 45,
  164. 1
  165. ]
  166. },
  167. {
  168. "scalar_type": "Int32",
  169. "nullable": false
  170. },
  171. null
  172. ]
  173. },
  174. {
  175. "Literal": [
  176. {
  177. "data": [
  178. 45,
  179. 7
  180. ]
  181. },
  182. {
  183. "scalar_type": "Int32",
  184. "nullable": false
  185. },
  186. null
  187. ]
  188. },
  189. {
  190. "Literal": [
  191. {
  192. "data": [
  193. 45,
  194. 1
  195. ]
  196. },
  197. {
  198. "scalar_type": "Int32",
  199. "nullable": false
  200. },
  201. null
  202. ]
  203. }
  204. ]
  205. }
  206. }
  207. EOF
  208. # Test Threshold, Union, Distinct, Negate.
  209. query T multiline
  210. EXPLAIN RAW PLAN AS JSON FOR
  211. SELECT a FROM t EXCEPT SELECT b FROM mv
  212. ----
  213. {
  214. "Threshold": {
  215. "input": {
  216. "Union": {
  217. "base": {
  218. "Distinct": {
  219. "input": {
  220. "Project": {
  221. "input": {
  222. "Get": {
  223. "id": {
  224. "Global": {
  225. "User": 1
  226. }
  227. },
  228. "typ": {
  229. "column_types": [
  230. {
  231. "scalar_type": "Int32",
  232. "nullable": true
  233. },
  234. {
  235. "scalar_type": "Int32",
  236. "nullable": true
  237. }
  238. ],
  239. "keys": []
  240. }
  241. }
  242. },
  243. "outputs": [
  244. 0
  245. ]
  246. }
  247. }
  248. }
  249. },
  250. "inputs": [
  251. {
  252. "Negate": {
  253. "input": {
  254. "Distinct": {
  255. "input": {
  256. "Project": {
  257. "input": {
  258. "Get": {
  259. "id": {
  260. "Global": {
  261. "User": 5
  262. }
  263. },
  264. "typ": {
  265. "column_types": [
  266. {
  267. "scalar_type": "Int32",
  268. "nullable": false
  269. },
  270. {
  271. "scalar_type": "Int32",
  272. "nullable": true
  273. }
  274. ],
  275. "keys": []
  276. }
  277. }
  278. },
  279. "outputs": [
  280. 1
  281. ]
  282. }
  283. }
  284. }
  285. }
  286. }
  287. }
  288. ]
  289. }
  290. }
  291. }
  292. }
  293. EOF
  294. # Test Finish (TODO).
  295. query T multiline
  296. EXPLAIN RAW PLAN AS JSON FOR
  297. SELECT * FROM t ORDER BY b asc, a desc LIMIT 5
  298. ----
  299. {
  300. "Get": {
  301. "id": {
  302. "Global": {
  303. "User": 1
  304. }
  305. },
  306. "typ": {
  307. "column_types": [
  308. {
  309. "scalar_type": "Int32",
  310. "nullable": true
  311. },
  312. {
  313. "scalar_type": "Int32",
  314. "nullable": true
  315. }
  316. ],
  317. "keys": []
  318. }
  319. }
  320. }
  321. EOF
  322. # Test Reduce (global).
  323. query T multiline
  324. EXPLAIN RAW PLAN AS JSON FOR
  325. SELECT abs(min(a) - max(a)) FROM t
  326. ----
  327. {
  328. "Project": {
  329. "input": {
  330. "Map": {
  331. "input": {
  332. "Reduce": {
  333. "input": {
  334. "Get": {
  335. "id": {
  336. "Global": {
  337. "User": 1
  338. }
  339. },
  340. "typ": {
  341. "column_types": [
  342. {
  343. "scalar_type": "Int32",
  344. "nullable": true
  345. },
  346. {
  347. "scalar_type": "Int32",
  348. "nullable": true
  349. }
  350. ],
  351. "keys": []
  352. }
  353. }
  354. },
  355. "group_key": [],
  356. "aggregates": [
  357. {
  358. "func": "MinInt32",
  359. "expr": {
  360. "Column": [
  361. {
  362. "level": 0,
  363. "column": 0
  364. },
  365. "a"
  366. ]
  367. },
  368. "distinct": false
  369. },
  370. {
  371. "func": "MaxInt32",
  372. "expr": {
  373. "Column": [
  374. {
  375. "level": 0,
  376. "column": 0
  377. },
  378. "a"
  379. ]
  380. },
  381. "distinct": false
  382. }
  383. ],
  384. "expected_group_size": null
  385. }
  386. },
  387. "scalars": [
  388. {
  389. "CallUnary": {
  390. "func": {
  391. "AbsInt32": null
  392. },
  393. "expr": {
  394. "CallBinary": {
  395. "func": "SubInt32",
  396. "expr1": {
  397. "Column": [
  398. {
  399. "level": 0,
  400. "column": 0
  401. },
  402. "?column?"
  403. ]
  404. },
  405. "expr2": {
  406. "Column": [
  407. {
  408. "level": 0,
  409. "column": 1
  410. },
  411. "?column?"
  412. ]
  413. },
  414. "name": null
  415. }
  416. },
  417. "name": null
  418. }
  419. }
  420. ]
  421. }
  422. },
  423. "outputs": [
  424. 2
  425. ]
  426. }
  427. }
  428. EOF
  429. # Test Reduce (local).
  430. query T multiline
  431. EXPLAIN RAW PLAN AS JSON FOR
  432. SELECT abs(min(a) - max(a)) FROM t GROUP BY b
  433. ----
  434. {
  435. "Project": {
  436. "input": {
  437. "Map": {
  438. "input": {
  439. "Reduce": {
  440. "input": {
  441. "Map": {
  442. "input": {
  443. "Get": {
  444. "id": {
  445. "Global": {
  446. "User": 1
  447. }
  448. },
  449. "typ": {
  450. "column_types": [
  451. {
  452. "scalar_type": "Int32",
  453. "nullable": true
  454. },
  455. {
  456. "scalar_type": "Int32",
  457. "nullable": true
  458. }
  459. ],
  460. "keys": []
  461. }
  462. }
  463. },
  464. "scalars": [
  465. {
  466. "Column": [
  467. {
  468. "level": 0,
  469. "column": 1
  470. },
  471. "b"
  472. ]
  473. }
  474. ]
  475. }
  476. },
  477. "group_key": [
  478. 2
  479. ],
  480. "aggregates": [
  481. {
  482. "func": "MinInt32",
  483. "expr": {
  484. "Column": [
  485. {
  486. "level": 0,
  487. "column": 0
  488. },
  489. "a"
  490. ]
  491. },
  492. "distinct": false
  493. },
  494. {
  495. "func": "MaxInt32",
  496. "expr": {
  497. "Column": [
  498. {
  499. "level": 0,
  500. "column": 0
  501. },
  502. "a"
  503. ]
  504. },
  505. "distinct": false
  506. }
  507. ],
  508. "expected_group_size": null
  509. }
  510. },
  511. "scalars": [
  512. {
  513. "CallUnary": {
  514. "func": {
  515. "AbsInt32": null
  516. },
  517. "expr": {
  518. "CallBinary": {
  519. "func": "SubInt32",
  520. "expr1": {
  521. "Column": [
  522. {
  523. "level": 0,
  524. "column": 1
  525. },
  526. "?column?"
  527. ]
  528. },
  529. "expr2": {
  530. "Column": [
  531. {
  532. "level": 0,
  533. "column": 2
  534. },
  535. "?column?"
  536. ]
  537. },
  538. "name": null
  539. }
  540. },
  541. "name": null
  542. }
  543. }
  544. ]
  545. }
  546. },
  547. "outputs": [
  548. 3
  549. ]
  550. }
  551. }
  552. EOF
  553. # Test EXISTS subqueries.
  554. query T multiline
  555. EXPLAIN RAW PLAN WITH(raw syntax) AS JSON FOR
  556. SELECT * FROM t WHERE EXISTS(SELECT * FROM mv WHERE t.a < mv.a) AND EXISTS(SELECT * FROM mv WHERE t.b > mv.b)
  557. ----
  558. {
  559. "Let": {
  560. "name": "subquery-2",
  561. "id": 2,
  562. "value": {
  563. "Filter": {
  564. "input": {
  565. "Get": {
  566. "id": {
  567. "Global": {
  568. "User": 5
  569. }
  570. },
  571. "typ": {
  572. "column_types": [
  573. {
  574. "scalar_type": "Int32",
  575. "nullable": false
  576. },
  577. {
  578. "scalar_type": "Int32",
  579. "nullable": true
  580. }
  581. ],
  582. "keys": []
  583. }
  584. }
  585. },
  586. "predicates": [
  587. {
  588. "CallBinary": {
  589. "func": "Gt",
  590. "expr1": {
  591. "Column": [
  592. {
  593. "level": 1,
  594. "column": 1
  595. },
  596. "b"
  597. ]
  598. },
  599. "expr2": {
  600. "Column": [
  601. {
  602. "level": 0,
  603. "column": 1
  604. },
  605. "b"
  606. ]
  607. },
  608. "name": null
  609. }
  610. }
  611. ]
  612. }
  613. },
  614. "body": {
  615. "Let": {
  616. "name": "subquery-1",
  617. "id": 1,
  618. "value": {
  619. "Filter": {
  620. "input": {
  621. "Get": {
  622. "id": {
  623. "Global": {
  624. "User": 5
  625. }
  626. },
  627. "typ": {
  628. "column_types": [
  629. {
  630. "scalar_type": "Int32",
  631. "nullable": false
  632. },
  633. {
  634. "scalar_type": "Int32",
  635. "nullable": true
  636. }
  637. ],
  638. "keys": []
  639. }
  640. }
  641. },
  642. "predicates": [
  643. {
  644. "CallBinary": {
  645. "func": "Lt",
  646. "expr1": {
  647. "Column": [
  648. {
  649. "level": 1,
  650. "column": 0
  651. },
  652. "a"
  653. ]
  654. },
  655. "expr2": {
  656. "Column": [
  657. {
  658. "level": 0,
  659. "column": 0
  660. },
  661. "a"
  662. ]
  663. },
  664. "name": null
  665. }
  666. }
  667. ]
  668. }
  669. },
  670. "body": {
  671. "Filter": {
  672. "input": {
  673. "Get": {
  674. "id": {
  675. "Global": {
  676. "User": 1
  677. }
  678. },
  679. "typ": {
  680. "column_types": [
  681. {
  682. "scalar_type": "Int32",
  683. "nullable": true
  684. },
  685. {
  686. "scalar_type": "Int32",
  687. "nullable": true
  688. }
  689. ],
  690. "keys": []
  691. }
  692. }
  693. },
  694. "predicates": [
  695. {
  696. "CallVariadic": {
  697. "func": "And",
  698. "exprs": [
  699. {
  700. "Exists": [
  701. {
  702. "Get": {
  703. "id": {
  704. "Local": 1
  705. },
  706. "typ": {
  707. "column_types": [],
  708. "keys": []
  709. }
  710. }
  711. },
  712. null
  713. ]
  714. },
  715. {
  716. "Exists": [
  717. {
  718. "Get": {
  719. "id": {
  720. "Local": 2
  721. },
  722. "typ": {
  723. "column_types": [],
  724. "keys": []
  725. }
  726. }
  727. },
  728. null
  729. ]
  730. }
  731. ],
  732. "name": null
  733. }
  734. }
  735. ]
  736. }
  737. }
  738. }
  739. }
  740. }
  741. }
  742. EOF
  743. # Test SELECT subqueries.
  744. query T multiline
  745. EXPLAIN RAW PLAN WITH(raw syntax) AS JSON FOR
  746. SELECT (SELECT v.a FROM v WHERE v.b = t.b LIMIT 1), (SELECT mv.a FROM mv WHERE mv.b = t.b LIMIT 1) FROM t
  747. ----
  748. {
  749. "Project": {
  750. "input": {
  751. "Let": {
  752. "name": "subquery-2",
  753. "id": 2,
  754. "value": {
  755. "Project": {
  756. "input": {
  757. "TopK": {
  758. "input": {
  759. "Filter": {
  760. "input": {
  761. "Get": {
  762. "id": {
  763. "Global": {
  764. "User": 5
  765. }
  766. },
  767. "typ": {
  768. "column_types": [
  769. {
  770. "scalar_type": "Int32",
  771. "nullable": false
  772. },
  773. {
  774. "scalar_type": "Int32",
  775. "nullable": true
  776. }
  777. ],
  778. "keys": []
  779. }
  780. }
  781. },
  782. "predicates": [
  783. {
  784. "CallBinary": {
  785. "func": "Eq",
  786. "expr1": {
  787. "Column": [
  788. {
  789. "level": 0,
  790. "column": 1
  791. },
  792. "b"
  793. ]
  794. },
  795. "expr2": {
  796. "Column": [
  797. {
  798. "level": 1,
  799. "column": 1
  800. },
  801. "b"
  802. ]
  803. },
  804. "name": null
  805. }
  806. }
  807. ]
  808. }
  809. },
  810. "group_key": [],
  811. "order_key": [],
  812. "limit": {
  813. "Literal": [
  814. {
  815. "data": [
  816. 50,
  817. 1
  818. ]
  819. },
  820. {
  821. "scalar_type": "Int64",
  822. "nullable": false
  823. },
  824. null
  825. ]
  826. },
  827. "offset": {
  828. "Literal": [
  829. {
  830. "data": [
  831. 49
  832. ]
  833. },
  834. {
  835. "scalar_type": "Int64",
  836. "nullable": false
  837. },
  838. null
  839. ]
  840. },
  841. "expected_group_size": null
  842. }
  843. },
  844. "outputs": [
  845. 0
  846. ]
  847. }
  848. },
  849. "body": {
  850. "Let": {
  851. "name": "subquery-1",
  852. "id": 1,
  853. "value": {
  854. "Project": {
  855. "input": {
  856. "TopK": {
  857. "input": {
  858. "Filter": {
  859. "input": {
  860. "Get": {
  861. "id": {
  862. "Global": {
  863. "User": 3
  864. }
  865. },
  866. "typ": {
  867. "column_types": [
  868. {
  869. "scalar_type": "Int32",
  870. "nullable": false
  871. },
  872. {
  873. "scalar_type": "Int32",
  874. "nullable": true
  875. }
  876. ],
  877. "keys": []
  878. }
  879. }
  880. },
  881. "predicates": [
  882. {
  883. "CallBinary": {
  884. "func": "Eq",
  885. "expr1": {
  886. "Column": [
  887. {
  888. "level": 0,
  889. "column": 1
  890. },
  891. "b"
  892. ]
  893. },
  894. "expr2": {
  895. "Column": [
  896. {
  897. "level": 1,
  898. "column": 1
  899. },
  900. "b"
  901. ]
  902. },
  903. "name": null
  904. }
  905. }
  906. ]
  907. }
  908. },
  909. "group_key": [],
  910. "order_key": [],
  911. "limit": {
  912. "Literal": [
  913. {
  914. "data": [
  915. 50,
  916. 1
  917. ]
  918. },
  919. {
  920. "scalar_type": "Int64",
  921. "nullable": false
  922. },
  923. null
  924. ]
  925. },
  926. "offset": {
  927. "Literal": [
  928. {
  929. "data": [
  930. 49
  931. ]
  932. },
  933. {
  934. "scalar_type": "Int64",
  935. "nullable": false
  936. },
  937. null
  938. ]
  939. },
  940. "expected_group_size": null
  941. }
  942. },
  943. "outputs": [
  944. 0
  945. ]
  946. }
  947. },
  948. "body": {
  949. "Map": {
  950. "input": {
  951. "Get": {
  952. "id": {
  953. "Global": {
  954. "User": 1
  955. }
  956. },
  957. "typ": {
  958. "column_types": [
  959. {
  960. "scalar_type": "Int32",
  961. "nullable": true
  962. },
  963. {
  964. "scalar_type": "Int32",
  965. "nullable": true
  966. }
  967. ],
  968. "keys": []
  969. }
  970. }
  971. },
  972. "scalars": [
  973. {
  974. "Select": [
  975. {
  976. "Get": {
  977. "id": {
  978. "Local": 1
  979. },
  980. "typ": {
  981. "column_types": [],
  982. "keys": []
  983. }
  984. }
  985. },
  986. null
  987. ]
  988. },
  989. {
  990. "Select": [
  991. {
  992. "Get": {
  993. "id": {
  994. "Local": 2
  995. },
  996. "typ": {
  997. "column_types": [],
  998. "keys": []
  999. }
  1000. }
  1001. },
  1002. null
  1003. ]
  1004. }
  1005. ]
  1006. }
  1007. }
  1008. }
  1009. }
  1010. }
  1011. },
  1012. "outputs": [
  1013. 2,
  1014. 3
  1015. ]
  1016. }
  1017. }
  1018. EOF
  1019. # Test CrossJoin derived from a comma join without a predicate.
  1020. query T multiline
  1021. EXPLAIN RAW PLAN AS JSON FOR
  1022. SELECT t1.a, t2.a FROM t as t1, t as t2
  1023. ----
  1024. {
  1025. "Project": {
  1026. "input": {
  1027. "Join": {
  1028. "left": {
  1029. "Get": {
  1030. "id": {
  1031. "Global": {
  1032. "User": 1
  1033. }
  1034. },
  1035. "typ": {
  1036. "column_types": [
  1037. {
  1038. "scalar_type": "Int32",
  1039. "nullable": true
  1040. },
  1041. {
  1042. "scalar_type": "Int32",
  1043. "nullable": true
  1044. }
  1045. ],
  1046. "keys": []
  1047. }
  1048. }
  1049. },
  1050. "right": {
  1051. "Get": {
  1052. "id": {
  1053. "Global": {
  1054. "User": 1
  1055. }
  1056. },
  1057. "typ": {
  1058. "column_types": [
  1059. {
  1060. "scalar_type": "Int32",
  1061. "nullable": true
  1062. },
  1063. {
  1064. "scalar_type": "Int32",
  1065. "nullable": true
  1066. }
  1067. ],
  1068. "keys": []
  1069. }
  1070. }
  1071. },
  1072. "on": {
  1073. "Literal": [
  1074. {
  1075. "data": [
  1076. 2
  1077. ]
  1078. },
  1079. {
  1080. "scalar_type": "Bool",
  1081. "nullable": false
  1082. },
  1083. null
  1084. ]
  1085. },
  1086. "kind": "Inner"
  1087. }
  1088. },
  1089. "outputs": [
  1090. 0,
  1091. 2
  1092. ]
  1093. }
  1094. }
  1095. EOF
  1096. # Test InnerJoin (comma syntax).
  1097. query T multiline
  1098. EXPLAIN RAW PLAN AS JSON FOR
  1099. SELECT t1.a, t2.a
  1100. FROM
  1101. t as t1,
  1102. t as t2,
  1103. t as t3
  1104. WHERE t1.b = t2.b AND t2.b = t3.b
  1105. ----
  1106. {
  1107. "Project": {
  1108. "input": {
  1109. "Filter": {
  1110. "input": {
  1111. "Join": {
  1112. "left": {
  1113. "Join": {
  1114. "left": {
  1115. "Get": {
  1116. "id": {
  1117. "Global": {
  1118. "User": 1
  1119. }
  1120. },
  1121. "typ": {
  1122. "column_types": [
  1123. {
  1124. "scalar_type": "Int32",
  1125. "nullable": true
  1126. },
  1127. {
  1128. "scalar_type": "Int32",
  1129. "nullable": true
  1130. }
  1131. ],
  1132. "keys": []
  1133. }
  1134. }
  1135. },
  1136. "right": {
  1137. "Get": {
  1138. "id": {
  1139. "Global": {
  1140. "User": 1
  1141. }
  1142. },
  1143. "typ": {
  1144. "column_types": [
  1145. {
  1146. "scalar_type": "Int32",
  1147. "nullable": true
  1148. },
  1149. {
  1150. "scalar_type": "Int32",
  1151. "nullable": true
  1152. }
  1153. ],
  1154. "keys": []
  1155. }
  1156. }
  1157. },
  1158. "on": {
  1159. "Literal": [
  1160. {
  1161. "data": [
  1162. 2
  1163. ]
  1164. },
  1165. {
  1166. "scalar_type": "Bool",
  1167. "nullable": false
  1168. },
  1169. null
  1170. ]
  1171. },
  1172. "kind": "Inner"
  1173. }
  1174. },
  1175. "right": {
  1176. "Get": {
  1177. "id": {
  1178. "Global": {
  1179. "User": 1
  1180. }
  1181. },
  1182. "typ": {
  1183. "column_types": [
  1184. {
  1185. "scalar_type": "Int32",
  1186. "nullable": true
  1187. },
  1188. {
  1189. "scalar_type": "Int32",
  1190. "nullable": true
  1191. }
  1192. ],
  1193. "keys": []
  1194. }
  1195. }
  1196. },
  1197. "on": {
  1198. "Literal": [
  1199. {
  1200. "data": [
  1201. 2
  1202. ]
  1203. },
  1204. {
  1205. "scalar_type": "Bool",
  1206. "nullable": false
  1207. },
  1208. null
  1209. ]
  1210. },
  1211. "kind": "Inner"
  1212. }
  1213. },
  1214. "predicates": [
  1215. {
  1216. "CallVariadic": {
  1217. "func": "And",
  1218. "exprs": [
  1219. {
  1220. "CallBinary": {
  1221. "func": "Eq",
  1222. "expr1": {
  1223. "Column": [
  1224. {
  1225. "level": 0,
  1226. "column": 1
  1227. },
  1228. "b"
  1229. ]
  1230. },
  1231. "expr2": {
  1232. "Column": [
  1233. {
  1234. "level": 0,
  1235. "column": 3
  1236. },
  1237. "b"
  1238. ]
  1239. },
  1240. "name": null
  1241. }
  1242. },
  1243. {
  1244. "CallBinary": {
  1245. "func": "Eq",
  1246. "expr1": {
  1247. "Column": [
  1248. {
  1249. "level": 0,
  1250. "column": 3
  1251. },
  1252. "b"
  1253. ]
  1254. },
  1255. "expr2": {
  1256. "Column": [
  1257. {
  1258. "level": 0,
  1259. "column": 5
  1260. },
  1261. "b"
  1262. ]
  1263. },
  1264. "name": null
  1265. }
  1266. }
  1267. ],
  1268. "name": null
  1269. }
  1270. }
  1271. ]
  1272. }
  1273. },
  1274. "outputs": [
  1275. 0,
  1276. 2
  1277. ]
  1278. }
  1279. }
  1280. EOF
  1281. # Test multiple CTEs: directly nested 'Let' variants are rendered in a flattened way.
  1282. query T multiline
  1283. EXPLAIN RAW PLAN AS JSON FOR
  1284. WITH A AS (SELECT 1 AS a), B as (SELECT a as b FROM A WHERE a > 0) SELECT * FROM A, B;
  1285. ----
  1286. {
  1287. "Let": {
  1288. "name": "a",
  1289. "id": 0,
  1290. "value": {
  1291. "Map": {
  1292. "input": {
  1293. "Constant": {
  1294. "rows": [
  1295. {
  1296. "data": []
  1297. }
  1298. ],
  1299. "typ": {
  1300. "column_types": [],
  1301. "keys": []
  1302. }
  1303. }
  1304. },
  1305. "scalars": [
  1306. {
  1307. "Literal": [
  1308. {
  1309. "data": [
  1310. 45,
  1311. 1
  1312. ]
  1313. },
  1314. {
  1315. "scalar_type": "Int32",
  1316. "nullable": false
  1317. },
  1318. null
  1319. ]
  1320. }
  1321. ]
  1322. }
  1323. },
  1324. "body": {
  1325. "Let": {
  1326. "name": "b",
  1327. "id": 1,
  1328. "value": {
  1329. "Filter": {
  1330. "input": {
  1331. "Get": {
  1332. "id": {
  1333. "Local": 0
  1334. },
  1335. "typ": {
  1336. "column_types": [
  1337. {
  1338. "scalar_type": "Int32",
  1339. "nullable": false
  1340. }
  1341. ],
  1342. "keys": []
  1343. }
  1344. }
  1345. },
  1346. "predicates": [
  1347. {
  1348. "CallBinary": {
  1349. "func": "Gt",
  1350. "expr1": {
  1351. "Column": [
  1352. {
  1353. "level": 0,
  1354. "column": 0
  1355. },
  1356. "a"
  1357. ]
  1358. },
  1359. "expr2": {
  1360. "Literal": [
  1361. {
  1362. "data": [
  1363. 44
  1364. ]
  1365. },
  1366. {
  1367. "scalar_type": "Int32",
  1368. "nullable": false
  1369. },
  1370. null
  1371. ]
  1372. },
  1373. "name": null
  1374. }
  1375. }
  1376. ]
  1377. }
  1378. },
  1379. "body": {
  1380. "Join": {
  1381. "left": {
  1382. "Get": {
  1383. "id": {
  1384. "Local": 0
  1385. },
  1386. "typ": {
  1387. "column_types": [
  1388. {
  1389. "scalar_type": "Int32",
  1390. "nullable": false
  1391. }
  1392. ],
  1393. "keys": []
  1394. }
  1395. }
  1396. },
  1397. "right": {
  1398. "Get": {
  1399. "id": {
  1400. "Local": 1
  1401. },
  1402. "typ": {
  1403. "column_types": [
  1404. {
  1405. "scalar_type": "Int32",
  1406. "nullable": false
  1407. }
  1408. ],
  1409. "keys": []
  1410. }
  1411. }
  1412. },
  1413. "on": {
  1414. "Literal": [
  1415. {
  1416. "data": [
  1417. 2
  1418. ]
  1419. },
  1420. {
  1421. "scalar_type": "Bool",
  1422. "nullable": false
  1423. },
  1424. null
  1425. ]
  1426. },
  1427. "kind": "Inner"
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. }
  1434. EOF