comment.slt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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. # Start from a pristine server
  11. reset-server
  12. statement ok
  13. CREATE TABLE a ( x int8, y text, z jsonb );
  14. query T
  15. SELECT obj_description((SELECT oid FROM mz_tables WHERE name = 'a'), 'pg_class')
  16. ----
  17. NULL
  18. query TTT
  19. SHOW OBJECTS
  20. ----
  21. a table (empty)
  22. statement ok
  23. COMMENT ON TABLE a IS 'foo_table';
  24. query TTT
  25. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  26. ----
  27. table NULL foo_table
  28. query IT
  29. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  30. ----
  31. 0 foo_table
  32. query TTT
  33. SHOW OBJECTS
  34. ----
  35. a table foo_table
  36. query TT
  37. SELECT obj_description((SELECT oid FROM mz_tables WHERE name = 'a'), 'pg_class'),
  38. obj_description((SELECT oid FROM mz_tables WHERE name = 'a'), 'notexist')
  39. ----
  40. foo_table NULL
  41. statement ok
  42. COMMENT ON COLUMN a.y IS 'load_bearing';
  43. query TTT rowsort
  44. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  45. ----
  46. table NULL foo_table
  47. table 2 load_bearing
  48. query IT
  49. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  50. ----
  51. 0 foo_table
  52. 2 load_bearing
  53. query T
  54. SELECT col_description((SELECT oid FROM mz_tables WHERE name = 'a'), 2)
  55. ----
  56. load_bearing
  57. query T
  58. SELECT col_description((SELECT oid FROM mz_tables WHERE name = 'a'), 1)
  59. ----
  60. NULL
  61. query TT
  62. SHOW TABLES;
  63. ----
  64. a foo_table
  65. query TT rowsort
  66. SELECT name, comment FROM (SHOW COLUMNS FROM a);
  67. ----
  68. x (empty)
  69. z (empty)
  70. y load_bearing
  71. statement ok
  72. CREATE TABLE b ( ts timestamptz );
  73. statement ok
  74. COMMENT ON COLUMN b.ts IS 'utc_timestamp';
  75. query TTT rowsort
  76. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  77. ----
  78. table NULL foo_table
  79. table 2 load_bearing
  80. table 1 utc_timestamp
  81. query IT rowsort
  82. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  83. ----
  84. 0 foo_table
  85. 2 load_bearing
  86. 1 utc_timestamp
  87. statement ok
  88. COMMENT ON TABLE b IS 'foo_table';
  89. query TT
  90. SHOW TABLES;
  91. ----
  92. a foo_table
  93. b foo_table
  94. statement ok
  95. DROP TABLE a;
  96. query TTT rowsort
  97. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  98. ----
  99. table NULL foo_table
  100. table 1 utc_timestamp
  101. query IT
  102. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  103. ----
  104. 0 foo_table
  105. 1 utc_timestamp
  106. statement ok
  107. COMMENT ON TABLE b IS NULL
  108. query TT
  109. SHOW TABLES;
  110. ----
  111. b (empty)
  112. statement ok
  113. COMMENT ON COLUMN b.ts IS NULL
  114. query TTT
  115. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  116. ----
  117. query IT
  118. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  119. ----
  120. statement error unknown catalog item 'c'
  121. COMMENT ON TABLE c IS 'does_not_exist';
  122. statement error column "b.does_not_exist" does not exist
  123. COMMENT ON COLUMN b.does_not_exist IS 'foo';
  124. statement ok
  125. CREATE INDEX b_idx ON b (ts);
  126. statement ok
  127. COMMENT ON INDEX b_idx IS 'speed_up';
  128. query TT
  129. SELECT name, comment FROM (SHOW INDEXES);
  130. ----
  131. b_idx speed_up
  132. statement ok
  133. CREATE VIEW c (col_1, col_2) AS VALUES ('a', 'b');
  134. statement ok
  135. COMMENT ON VIEW c IS 'this_is_a_view';
  136. query TTT
  137. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  138. ----
  139. index NULL speed_up
  140. view NULL this_is_a_view
  141. query IT
  142. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  143. ----
  144. 0 speed_up
  145. 0 this_is_a_view
  146. query T
  147. SELECT obj_description((SELECT oid FROM mz_indexes WHERE name = 'b_idx'), 'pg_class')
  148. ----
  149. speed_up
  150. statement ok
  151. DROP TABLE b CASCADE;
  152. statement ok
  153. COMMENT ON COLUMN c.col_1 IS 'this_works';
  154. query TT
  155. SELECT name, comment FROM (SHOW VIEWS);
  156. ----
  157. c this_is_a_view
  158. query TT rowsort
  159. SELECT name, comment FROM (SHOW COLUMNS FROM c);
  160. ----
  161. col_2 (empty)
  162. col_1 this_works
  163. query TTT
  164. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  165. ----
  166. view 1 this_works
  167. view NULL this_is_a_view
  168. query IT rowsort
  169. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  170. ----
  171. 1 this_works
  172. 0 this_is_a_view
  173. statement ok
  174. CREATE MATERIALIZED VIEW mv ( x ) AS SELECT 1
  175. statement ok
  176. COMMENT ON COLUMN mv.x IS 'comment_mat_view_col';
  177. statement ok
  178. COMMENT ON MATERIALIZED VIEW mv IS 'mat_foo';
  179. query TT
  180. SELECT name, comment FROM (SHOW MATERIALIZED VIEWS);
  181. ----
  182. mv mat_foo
  183. query TT
  184. SELECT name, comment FROM (SHOW COLUMNS FROM mv);
  185. ----
  186. x comment_mat_view_col
  187. query TTT rowsort
  188. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  189. ----
  190. view 1 this_works
  191. view NULL this_is_a_view
  192. materialized-view NULL mat_foo
  193. materialized-view 1 comment_mat_view_col
  194. query IT rowsort
  195. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  196. ----
  197. 0 mat_foo
  198. 1 this_works
  199. 0 this_is_a_view
  200. 1 comment_mat_view_col
  201. query TTT rowsort
  202. SHOW OBJECTS
  203. ----
  204. c view this_is_a_view
  205. mv materialized-view mat_foo
  206. query T
  207. SELECT obj_description((SELECT oid FROM mz_views WHERE name = 'c'), 'pg_class')
  208. ----
  209. this_is_a_view
  210. query T
  211. SELECT col_description((SELECT oid FROM mz_views WHERE name = 'c'), 1)
  212. ----
  213. this_works
  214. query TTTT
  215. SELECT obj_description((SELECT oid FROM mz_views WHERE name = 'c'), 'pg_class'),
  216. col_description((SELECT oid FROM mz_views WHERE name = 'c'), 1),
  217. obj_description(
  218. (SELECT oid FROM mz_materialized_views WHERE name = 'mv'), 'pg_class'),
  219. col_description((SELECT oid FROM mz_materialized_views WHERE name = 'mv'), 1)
  220. ----
  221. this_is_a_view this_works mat_foo comment_mat_view_col
  222. statement ok
  223. DROP VIEW c;
  224. statement ok
  225. DROP MATERIALIZED VIEW mv;
  226. query TTT
  227. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  228. ----
  229. query IT
  230. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  231. ----
  232. statement ok
  233. CREATE CLUSTER comment_cluster REPLICAS (r1 (SIZE '1'), r2 (SIZE '1'));
  234. statement ok
  235. COMMENT ON CLUSTER comment_cluster IS 'careful_now';
  236. query TT rowsort
  237. SELECT name, comment FROM (SHOW CLUSTERS);
  238. ----
  239. mz_probe (empty)
  240. mz_system (empty)
  241. mz_support (empty)
  242. quickstart (empty)
  243. mz_analytics (empty)
  244. mz_catalog_server (empty)
  245. comment_cluster careful_now
  246. statement ok
  247. COMMENT ON CLUSTER REPLICA comment_cluster.r2 IS 'second_replicator';
  248. query TTT
  249. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  250. ----
  251. cluster NULL careful_now
  252. cluster-replica NULL second_replicator
  253. query IT
  254. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  255. ----
  256. statement ok
  257. DROP CLUSTER REPLICA comment_cluster.r2;
  258. statement ok
  259. CREATE SOURCE my_webhook IN CLUSTER comment_cluster FROM WEBHOOK BODY FORMAT TEXT;
  260. statement ok
  261. COMMENT ON SOURCE my_webhook IS 'all_the_data';
  262. statement ok
  263. COMMENT ON COLUMN my_webhook.body IS 'json_blob';
  264. query TTT rowsort
  265. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  266. ----
  267. source 1 json_blob
  268. source NULL all_the_data
  269. cluster NULL careful_now
  270. query TT
  271. SELECT obj_description((SELECT oid FROM mz_sources WHERE name = 'my_webhook'), 'pg_class'),
  272. col_description((SELECT oid FROM mz_sources WHERE name = 'my_webhook'), 1)
  273. ----
  274. all_the_data json_blob
  275. query IT rowsort
  276. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  277. ----
  278. 1 json_blob
  279. 0 all_the_data
  280. query TT
  281. SELECT name, comment FROM (SHOW SOURCES);
  282. ----
  283. my_webhook all_the_data
  284. query TTT
  285. SHOW OBJECTS
  286. ----
  287. my_webhook source all_the_data
  288. statement ok
  289. CREATE TYPE int4_list AS LIST (ELEMENT TYPE = int4);
  290. statement ok
  291. COMMENT ON TYPE int4_list IS 'supercool_list';
  292. statement ok
  293. CREATE TYPE custom_type AS (x integer, y int4_list);
  294. statement ok
  295. CREATE TYPE custom_map_type AS MAP (KEY TYPE = text, VALUE TYPE = custom_type)
  296. statement ok
  297. COMMENT ON TYPE custom_map_type IS 'custom_map_type_comment';
  298. statement error cannot be depended upon
  299. COMMENT ON COLUMN custom_map_type.key IS 'comment_on_key';
  300. query TT rowsort
  301. SHOW TYPES;
  302. ----
  303. custom_map_type custom_map_type_comment
  304. custom_type (empty)
  305. int4_list supercool_list
  306. statement ok
  307. CREATE TYPE custom_list_type AS LIST (ELEMENT TYPE = custom_type)
  308. statement ok
  309. COMMENT ON TYPE custom_list_type IS 'custom_list_type_comment';
  310. statement error cannot be depended upon
  311. COMMENT ON COLUMN custom_list_type.element IS 'comment_on_element';
  312. statement error cannot be depended upon
  313. COMMENT ON COLUMN custom_map_type.key IS 'comment_on_key';
  314. statement ok
  315. COMMENT ON TYPE custom_type IS 'custom_type_comment';
  316. query TTT rowsort
  317. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  318. ----
  319. source 1 json_blob
  320. type NULL supercool_list
  321. source NULL all_the_data
  322. cluster NULL careful_now
  323. type NULL custom_type_comment
  324. type NULL custom_map_type_comment
  325. type NULL custom_list_type_comment
  326. query TTT
  327. SHOW OBJECTS
  328. ----
  329. custom_list_type type custom_list_type_comment
  330. custom_map_type type custom_map_type_comment
  331. custom_type type custom_type_comment
  332. int4_list type supercool_list
  333. my_webhook source all_the_data
  334. statement ok
  335. DROP TYPE custom_map_type;
  336. statement ok
  337. DROP TYPE custom_list_type;
  338. statement ok
  339. COMMENT ON COLUMN custom_type.x IS 'custom_type_x_comment';
  340. statement ok
  341. COMMENT ON COLUMN custom_type.y IS 'custom_type_y_comment';
  342. query TTT rowsort
  343. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  344. ----
  345. source 1 json_blob
  346. type NULL supercool_list
  347. source NULL all_the_data
  348. cluster NULL careful_now
  349. type NULL custom_type_comment
  350. type 1 custom_type_x_comment
  351. type 2 custom_type_y_comment
  352. query IT rowsort
  353. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  354. ----
  355. 1 json_blob
  356. 0 all_the_data
  357. 0 supercool_list
  358. 0 custom_type_comment
  359. 1 custom_type_x_comment
  360. 2 custom_type_y_comment
  361. query TTT rowsort
  362. SHOW OBJECTS
  363. ----
  364. custom_type type custom_type_comment
  365. int4_list type supercool_list
  366. my_webhook source all_the_data
  367. query TT
  368. SELECT obj_description((SELECT oid FROM mz_types WHERE name = 'custom_type'), 'pg_type'),
  369. col_description((SELECT oid FROM mz_types WHERE name = 'custom_type'), 1)
  370. ----
  371. custom_type_comment NULL
  372. statement ok
  373. DROP CLUSTER comment_cluster CASCADE;
  374. statement ok
  375. CREATE SECRET my_secret AS 'foobar';
  376. statement ok
  377. COMMENT ON SECRET my_secret IS 'supersecret';
  378. query TTT rowsort
  379. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  380. ----
  381. secret NULL supersecret
  382. type NULL supercool_list
  383. type NULL custom_type_comment
  384. type 1 custom_type_x_comment
  385. type 2 custom_type_y_comment
  386. query IT rowsort
  387. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  388. ----
  389. 0 supercool_list
  390. 0 custom_type_comment
  391. 1 custom_type_x_comment
  392. 2 custom_type_y_comment
  393. query T
  394. SELECT obj_description((SELECT oid FROM mz_secrets WHERE name = 'my_secret'), 'pg_class')
  395. ----
  396. NULL
  397. statement ok
  398. CREATE DATABASE comment_on_db;
  399. statement ok
  400. CREATE SCHEMA comment_on_schema;
  401. statement ok
  402. COMMENT ON DATABASE comment_on_db IS 'this_is_my_db';
  403. statement ok
  404. COMMENT ON SCHEMA comment_on_schema IS 'this_is_my_schema';
  405. query TTT
  406. SHOW OBJECTS
  407. ----
  408. custom_type type custom_type_comment
  409. int4_list type supercool_list
  410. my_secret secret supersecret
  411. statement ok
  412. DROP SECRET my_secret;
  413. statement ok
  414. DROP TYPE custom_type;
  415. statement ok
  416. DROP TYPE int4_list;
  417. query TTT
  418. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  419. ----
  420. database NULL this_is_my_db
  421. schema NULL this_is_my_schema
  422. query IT
  423. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  424. ----
  425. 0 this_is_my_schema
  426. query TT
  427. SELECT obj_description(
  428. (SELECT oid FROM mz_databases WHERE name = 'comment_on_db'), 'pg_class'),
  429. obj_description(
  430. (SELECT oid FROM mz_schemas WHERE name = 'comment_on_schema'), 'pg_namespace')
  431. ----
  432. NULL this_is_my_schema
  433. statement ok
  434. DROP DATABASE comment_on_db;
  435. statement ok
  436. DROP SCHEMA comment_on_schema;
  437. # Test RBAC.
  438. statement ok
  439. CREATE ROLE student;
  440. statement ok
  441. COMMENT ON ROLE student IS 'limited_role';
  442. query TTT
  443. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  444. ----
  445. role NULL limited_role
  446. query IT
  447. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  448. ----
  449. statement ok
  450. CREATE TABLE foo ( x int8 );
  451. simple conn=student,user=student
  452. COMMENT ON TABLE foo IS 'comment_from_student';
  453. ----
  454. db error: ERROR: must be owner of TABLE materialize.public.foo
  455. statement ok
  456. CREATE ROLE teacher;
  457. simple conn=mz_system,user=mz_system
  458. GRANT CREATEROLE ON SYSTEM TO student;
  459. ----
  460. COMPLETE 0
  461. simple conn=student,user=student
  462. COMMENT ON ROLE teacher IS 'foo';
  463. ----
  464. COMPLETE 0
  465. query TTT rowsort
  466. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  467. ----
  468. role NULL foo
  469. role NULL limited_role
  470. query IT
  471. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  472. ----
  473. simple conn=mz_system,user=mz_system
  474. REVOKE CREATEROLE ON SYSTEM FROM student;
  475. ----
  476. COMPLETE 0
  477. # To comment on a Role you must have the CREATEROLE privilege.
  478. simple conn=student,user=student
  479. COMMENT ON ROLE teacher IS 'updated_teacher_comment';
  480. ----
  481. db error: ERROR: permission denied for SYSTEM
  482. DETAIL: The 'student' role needs CREATEROLE privileges on SYSTEM
  483. statement ok
  484. DROP ROLE student;
  485. statement ok
  486. DROP ROLE teacher;
  487. query TTT
  488. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  489. ----
  490. query IT
  491. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  492. ----
  493. statement error must be owner of DATABASE materialize
  494. COMMENT ON DATABASE materialize IS 'main_db';
  495. statement error must be owner of SCHEMA materialize.public
  496. COMMENT ON SCHEMA public IS 'everyone_has_access';
  497. simple conn=mz_system,user=mz_system
  498. COMMENT ON DATABASE materialize IS 'main_db';
  499. ----
  500. COMPLETE 0
  501. query TTT
  502. SELECT object_type, object_sub_id, comment FROM mz_internal.mz_comments WHERE id NOT LIKE 's%';
  503. ----
  504. database NULL main_db
  505. query IT
  506. SELECT objsubid, description FROM pg_description WHERE objoid >= 20000;
  507. ----