plan_insights.slt 37 KB

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