vars.slt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  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. query T
  13. SHOW extra_float_digits
  14. ----
  15. 3
  16. statement ok
  17. SET extra_float_digits=2
  18. ----
  19. query T
  20. SHOW extra_float_digits
  21. ----
  22. 2
  23. simple
  24. SET extra_float_digits=1;
  25. SHOW extra_float_digits;
  26. ----
  27. COMPLETE 0
  28. 1
  29. COMPLETE 1
  30. query T
  31. SHOW extra_float_digits
  32. ----
  33. 1
  34. simple
  35. SET extra_float_digits=0;
  36. SHOW extra_float_digits;
  37. ROLLBACK;
  38. ----
  39. COMPLETE 0
  40. 0
  41. COMPLETE 1
  42. COMPLETE 0
  43. query T
  44. SHOW extra_float_digits
  45. ----
  46. 1
  47. simple
  48. SET LOCAL extra_float_digits=-1;
  49. SHOW extra_float_digits;
  50. ----
  51. COMPLETE 0
  52. -1
  53. COMPLETE 1
  54. query T
  55. SHOW extra_float_digits
  56. ----
  57. 1
  58. simple
  59. SET LOCAL extra_float_digits=-2;
  60. SHOW extra_float_digits;
  61. ROLLBACK
  62. ----
  63. COMPLETE 0
  64. -2
  65. COMPLETE 1
  66. COMPLETE 0
  67. query T
  68. SHOW extra_float_digits
  69. ----
  70. 1
  71. # Test resetting a variable.
  72. statement ok
  73. SET extra_float_digits=42
  74. statement ok
  75. SET extra_float_digits=DEFAULT
  76. query T
  77. SHOW extra_float_digits
  78. ----
  79. 3
  80. statement ok
  81. SET extra_float_digits=42
  82. simple
  83. SET LOCAL extra_float_digits=DEFAULT;
  84. SHOW extra_float_digits;
  85. ----
  86. COMPLETE 0
  87. 3
  88. COMPLETE 1
  89. query T
  90. SHOW extra_float_digits
  91. ----
  92. 42
  93. statement ok
  94. RESET extra_float_digits
  95. query T
  96. SHOW extra_float_digits
  97. ----
  98. 3
  99. # Test that resetting a read-only variable succeeds.
  100. statement ok
  101. SET server_version=DEFAULT
  102. statement ok
  103. RESET server_version
  104. # Test that resetting an unknown variable fails.
  105. statement error unrecognized configuration parameter
  106. SET does_not_exist = DEFAULT
  107. statement error unrecognized configuration parameter
  108. RESET does_not_exist
  109. # Test transaction isolation
  110. query T
  111. SHOW transaction_isolation
  112. ----
  113. strict serializable
  114. statement ok
  115. SET transaction_isolation = serializable
  116. query T
  117. SHOW transaction_isolation
  118. ----
  119. serializable
  120. statement ok
  121. SET transaction_isolation = 'read committed'
  122. query T
  123. SHOW transaction_isolation
  124. ----
  125. serializable
  126. statement error invalid value for parameter "transaction_isolation": "snapshot isolation"
  127. SET transaction_isolation = 'snapshot isolation'
  128. statement ok
  129. SET transaction_isolation = 'strict serializable'
  130. query T
  131. SHOW transaction_isolation
  132. ----
  133. strict serializable
  134. statement ok
  135. SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE
  136. query T
  137. SHOW transaction_isolation
  138. ----
  139. serializable
  140. statement ok
  141. SET TRANSACTION ISOLATION LEVEL STRICT SERIALIZABLE
  142. query T
  143. SHOW transaction_isolation
  144. ----
  145. serializable
  146. statement ok
  147. BEGIN;
  148. statement ok
  149. SET TRANSACTION ISOLATION LEVEL STRICT SERIALIZABLE
  150. query T
  151. SHOW transaction_isolation
  152. ----
  153. strict serializable
  154. statement ok
  155. COMMIT
  156. query T
  157. SHOW transaction_isolation
  158. ----
  159. serializable
  160. ## Last isolation level write wins
  161. statement ok
  162. SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE, ISOLATION LEVEL STRICT SERIALIZABLE
  163. query T
  164. SHOW transaction_isolation
  165. ----
  166. strict serializable
  167. statement error Expected transaction mode, found EOF
  168. SET TRANSACTION
  169. statement error SET TRANSACTION <access-mode> are not supported
  170. SET TRANSACTION READ ONLY
  171. # Test that a failed transaction will not commit var changes.
  172. statement ok
  173. CREATE TABLE t (i INT);
  174. simple conn=1
  175. SET extra_float_digits=-3;
  176. COMMIT;
  177. BEGIN;
  178. SET extra_float_digits=-4;
  179. INSERT INTO t VALUES (1);
  180. ----
  181. COMPLETE 0
  182. COMPLETE 0
  183. COMPLETE 0
  184. COMPLETE 0
  185. COMPLETE 1
  186. simple conn=2
  187. DROP TABLE t;
  188. ----
  189. COMPLETE 0
  190. simple conn=1
  191. COMMIT;
  192. ----
  193. db error: ERROR: unknown catalog item 'u1'
  194. simple conn=1
  195. SHOW extra_float_digits
  196. ----
  197. -3
  198. COMPLETE 1
  199. # Test the user= syntax for sqllogictest itself.
  200. simple conn=mz_system,user=mz_system
  201. ALTER SYSTEM SET max_tables = 100
  202. ----
  203. COMPLETE 0
  204. statement error parameter "idle_in_transaction_session_timeout" requires a "duration" value
  205. SET idle_in_transaction_session_timeout TO '-10ms'
  206. statement error unrecognized configuration parameter
  207. SELECT current_setting('unknown')
  208. statement error does not exist
  209. SELECT current_setting(true)
  210. query T
  211. SELECT current_setting('unknown', true)
  212. ----
  213. NULL
  214. query T
  215. SELECT current_setting('unknown', 'true')
  216. ----
  217. NULL
  218. statement error does not exist
  219. SELECT current_setting('datestyle', 3)
  220. statement error unrecognized configuration parameter
  221. SELECT current_setting('unknown', false)
  222. query T
  223. SELECT current_setting('dateSTYLE')
  224. ----
  225. ISO, MDY
  226. statement ok
  227. SET cluster_replica = 'r1'
  228. query T
  229. SELECT current_setting('cluster') || '.' || current_setting('cluster_replica')
  230. ----
  231. quickstart.r1
  232. query T
  233. SELECT current_setting('max_tables')
  234. ----
  235. 100
  236. # Test multi-valued variable planning.
  237. simple
  238. set datestyle = iso,mdy;
  239. show datestyle;
  240. set datestyle = iso, mdy;
  241. show datestyle;
  242. set datestyle = "iso,mdy";
  243. show datestyle;
  244. set datestyle = "iso, mdy";
  245. show datestyle;
  246. set datestyle = 'iso,mdy';
  247. show datestyle;
  248. set datestyle = 'iso, mdy';
  249. show datestyle;
  250. set datestyle = '"iso", "mdy", "iso", "mdy"', "mdy", "iso", "ISO", "IsO", "mDy";
  251. show datestyle;
  252. ----
  253. COMPLETE 0
  254. ISO, MDY
  255. COMPLETE 1
  256. COMPLETE 0
  257. ISO, MDY
  258. COMPLETE 1
  259. COMPLETE 0
  260. ISO, MDY
  261. COMPLETE 1
  262. COMPLETE 0
  263. ISO, MDY
  264. COMPLETE 1
  265. COMPLETE 0
  266. ISO, MDY
  267. COMPLETE 1
  268. COMPLETE 0
  269. ISO, MDY
  270. COMPLETE 1
  271. COMPLETE 0
  272. ISO, MDY
  273. COMPLETE 1
  274. statement error parameter "database" cannot have value "one","two": expects a single value
  275. set database = one, two
  276. # Test invalid values for float vars
  277. # TODO(jkosh44) the error messages here are bad, but the best we can do right now. A user will
  278. # never see this anyway since it's only exposed to admins.
  279. simple conn=mz_system,user=mz_system
  280. ALTER SYSTEM SET max_credit_consumption_rate = '-100.5'
  281. ----
  282. db error: ERROR: parameter "max_credit_consumption_rate" cannot have value "-100.5": only supports non-negative, non-NaN numeric values
  283. simple conn=mz_system,user=mz_system
  284. ALTER SYSTEM SET max_credit_consumption_rate = NaN
  285. ----
  286. db error: ERROR: parameter "max_credit_consumption_rate" cannot have value "NaN": only supports non-negative, non-NaN numeric values
  287. statement ok
  288. SET SCHEMA 'non-resolvable-name'
  289. statement ok
  290. SET SCHEMA TO 'non-resolvable-name'
  291. statement ok
  292. SET SCHEMA = 'non-resolvable-name'
  293. query T
  294. SHOW SCHEMA
  295. ----
  296. NULL
  297. statement ok
  298. SET SCHEMA TO 'public'
  299. query T
  300. SHOW SCHEMA
  301. ----
  302. public
  303. statement error Expected end of statement, found comma
  304. SET SCHEMA TO public, private, playground
  305. statement ok
  306. CREATE SCHEMA s
  307. statement ok
  308. SET SCHEMA TO s
  309. query T
  310. SHOW SCHEMA
  311. ----
  312. s
  313. statement ok
  314. RESET SCHEMA
  315. query T
  316. SHOW SCHEMA
  317. ----
  318. public
  319. statement ok
  320. SET SCHEMA TO s
  321. query T
  322. SHOW SCHEMA
  323. ----
  324. s
  325. statement ok
  326. SET SCHEMA TO DEFAULT
  327. query T
  328. SHOW SCHEMA
  329. ----
  330. public
  331. query error db error: ERROR: SHOW variable in subqueries not yet supported
  332. SELECT * FROM (show client_encoding)
  333. # Need to disable the result stash, so that we actually exceed max result size
  334. simple conn=mz_system,user=mz_system
  335. ALTER SYSTEM SET enable_compute_peek_response_stash = false
  336. ----
  337. COMPLETE 0
  338. statement ok
  339. SET max_query_result_size = 100
  340. query T
  341. SELECT generate_series(1, 2)
  342. ----
  343. 1
  344. 2
  345. query error db error: ERROR: result exceeds max size of 100 B
  346. SELECT generate_series(1, 51)
  347. # Regression for database-issues#6866
  348. # Ensure duplicate rows don't overcount bytes in the presence of LIMIT.
  349. query T
  350. SELECT x FROM (VALUES ('{"row": 1}')) AS a (x), generate_series(1, 50000) LIMIT 1
  351. ----
  352. {"row": 1}
  353. # Ensure that a large ordering key but small projection does not count against the result size limit.
  354. query I
  355. select 1 from (select array_agg(generate_series) x from generate_series(1, 1000000)) order by x limit 1
  356. ----
  357. 1
  358. statement ok
  359. RESET max_query_result_size
  360. simple conn=mz_system,user=mz_system
  361. ALTER SYSTEM RESET enable_compute_peek_response_stash
  362. ----
  363. COMPLETE 0
  364. statement ok
  365. CREATE ROLE parker;
  366. statement ok
  367. ALTER ROLE parker SET cluster TO foo;
  368. statement error invalid value for parameter "transaction_isolation": "garbage"
  369. ALTER ROLE parker SET transaction_isolation TO 'garbage';
  370. query T
  371. SHOW cluster;
  372. ----
  373. quickstart
  374. query TTT
  375. SELECT r.name, rp.parameter_name, rp.parameter_value
  376. FROM mz_role_parameters rp
  377. LEFT JOIN mz_roles r ON rp.role_id = r.id;
  378. ----
  379. parker cluster foo
  380. simple conn=parker_1,user=parker
  381. SHOW cluster;
  382. ----
  383. foo
  384. COMPLETE 1
  385. simple conn=parker_1,user=parker
  386. ALTER ROLE parker RESET cluster;
  387. ----
  388. COMPLETE 0
  389. query TTT
  390. SELECT r.name, rp.parameter_name, rp.parameter_value
  391. FROM mz_role_parameters rp
  392. LEFT JOIN mz_roles r ON rp.role_id = r.id;
  393. ----
  394. # Altering the Role defaults does not take effect until you restart your session, this matches
  395. # Postgres.
  396. simple conn=parker_1,user=parker
  397. SHOW cluster;
  398. ----
  399. foo
  400. COMPLETE 1
  401. # A new connection gets us a new session.
  402. simple conn=parker_2,user=parker
  403. SHOW cluster;
  404. ----
  405. quickstart
  406. COMPLETE 1
  407. # Roles can alter their own variables.
  408. simple conn=parker_2,user=parker
  409. ALTER ROLE parker SET cluster TO bar;
  410. ----
  411. COMPLETE 0
  412. query TTT
  413. SELECT r.name, rp.parameter_name, rp.parameter_value
  414. FROM mz_role_parameters rp
  415. LEFT JOIN mz_roles r ON rp.role_id = r.id;
  416. ----
  417. parker cluster bar
  418. simple conn=parker_3,user=parker
  419. SHOW cluster;
  420. ----
  421. bar
  422. COMPLETE 1
  423. simple conn=parker_3,user=parker
  424. SET cluster TO session_var;
  425. ----
  426. COMPLETE 0
  427. simple conn=parker_3,user=parker
  428. SHOW cluster;
  429. ----
  430. session_var
  431. COMPLETE 1
  432. simple conn=parker_3,user=parker
  433. RESET cluster;
  434. ----
  435. COMPLETE 0
  436. simple conn=parker_3,user=parker
  437. BEGIN;
  438. ----
  439. COMPLETE 0
  440. simple conn=parker_3,user=parker
  441. SHOW cluster;
  442. ----
  443. bar
  444. COMPLETE 1
  445. simple conn=parker_3,user=parker
  446. SET cluster TO in_transaction;
  447. ----
  448. COMPLETE 0
  449. simple conn=parker_3,user=parker
  450. SHOW cluster;
  451. ----
  452. in_transaction
  453. COMPLETE 1
  454. simple conn=parker_3,user=parker
  455. COMMIT;
  456. ----
  457. COMPLETE 0
  458. simple conn=parker_3,user=parker
  459. SHOW cluster;
  460. ----
  461. in_transaction
  462. COMPLETE 1
  463. simple conn=parker_3,user=parker
  464. RESET cluster;
  465. ----
  466. COMPLETE 0
  467. simple conn=parker_3,user=parker
  468. SHOW cluster;
  469. ----
  470. bar
  471. COMPLETE 1
  472. simple conn=parker_3,user=parker
  473. BEGIN;
  474. ----
  475. COMPLETE 0
  476. simple conn=parker_3,user=parker
  477. SET LOCAL cluster TO local_transaction;
  478. ----
  479. COMPLETE 0
  480. simple conn=parker_3,user=parker
  481. SHOW cluster;
  482. ----
  483. local_transaction
  484. COMPLETE 1
  485. simple conn=parker_3,user=parker
  486. ROLLBACK;
  487. ----
  488. COMPLETE 0
  489. simple conn=parker_3,user=parker
  490. SHOW cluster;
  491. ----
  492. bar
  493. COMPLETE 1
  494. simple conn=parker_3,user=parker
  495. SHOW search_path;
  496. ----
  497. public
  498. COMPLETE 1
  499. simple conn=parker_3,user=parker
  500. ALTER ROLE parker SET search_path TO foo, bar, baz;
  501. ----
  502. COMPLETE 0
  503. query TTT
  504. SELECT r.name, rp.parameter_name, rp.parameter_value
  505. FROM mz_role_parameters rp
  506. LEFT JOIN mz_roles r ON rp.role_id = r.id;
  507. ----
  508. parker cluster bar
  509. parker search_path foo,␠bar,␠baz
  510. simple conn=parker_4,user=parker
  511. SHOW search_path;
  512. ----
  513. foo, bar, baz
  514. COMPLETE 1
  515. simple conn=parker_3,user=parker
  516. ALTER ROLE parker SET search_path TO DEFAULT;
  517. ----
  518. COMPLETE 0
  519. simple conn=parker_5,user=parker
  520. SHOW search_path;
  521. ----
  522. public
  523. COMPLETE 1
  524. query TTT
  525. SELECT r.name, rp.parameter_name, rp.parameter_value
  526. FROM mz_role_parameters rp
  527. LEFT JOIN mz_roles r ON rp.role_id = r.id;
  528. ----
  529. parker cluster bar
  530. statement ok
  531. CREATE ROLE joe;
  532. # You can set variable values for yourself, but you need CREATEROLE privileges to set them for
  533. # other roles.
  534. simple conn=parker_3,user=parker
  535. ALTER ROLE joe SET cluster TO wont_work;
  536. ----
  537. db error: ERROR: permission denied for SYSTEM
  538. DETAIL: The 'parker' role needs CREATEROLE privileges on SYSTEM
  539. statement ok
  540. ALTER ROLE joe SET cluster TO will_work
  541. simple conn=joe,user=joe
  542. SHOW cluster;
  543. ----
  544. will_work
  545. COMPLETE 1
  546. query TTT rowsort
  547. SELECT r.name, rp.parameter_name, rp.parameter_value
  548. FROM mz_role_parameters rp
  549. LEFT JOIN mz_roles r ON rp.role_id = r.id;
  550. ----
  551. parker cluster bar
  552. joe cluster will_work
  553. # Should not be able to set a system variable.
  554. simple conn=parker_3,user=parker
  555. ALTER ROLE parker SET metrics_retention TO 10;
  556. ----
  557. db error: ERROR: unrecognized configuration parameter "metrics_retention"
  558. # Should not be able to set a variable that does not exist.
  559. simple conn=parker_3,user=parker
  560. ALTER ROLE parker SET i_am_a_fake_variable TO 10;
  561. ----
  562. db error: ERROR: unrecognized configuration parameter "i_am_a_fake_variable"
  563. # mz_system cannot set a system variable.
  564. simple conn=mz_system,user=mz_system
  565. ALTER ROLE parker SET metrics_retention TO 10;
  566. ----
  567. db error: ERROR: unrecognized configuration parameter "metrics_retention"
  568. # Role defaults should override a change to the system default.
  569. simple conn=mz_system,user=mz_system
  570. ALTER SYSTEM SET cluster TO new_system_default
  571. ----
  572. COMPLETE 0
  573. simple conn=joe_1,user=joe
  574. SHOW cluster;
  575. ----
  576. will_work
  577. COMPLETE 1
  578. # Reset the role default, so new sessions should get the system default.
  579. simple conn=joe_1,user=joe
  580. ALTER ROLE joe RESET cluster;
  581. ----
  582. COMPLETE 0
  583. query TTT
  584. SELECT r.name, rp.parameter_name, rp.parameter_value
  585. FROM mz_role_parameters rp
  586. LEFT JOIN mz_roles r ON rp.role_id = r.id;
  587. ----
  588. parker cluster bar
  589. simple conn=joe_2,user=joe
  590. SHOW cluster;
  591. ----
  592. new_system_default
  593. COMPLETE 1
  594. simple conn=joe_2,user=joe
  595. BEGIN;
  596. ----
  597. COMPLETE 0
  598. simple conn=joe_2,user=joe
  599. SET LOCAL cluster TO 'txn_specific_cluster';
  600. ----
  601. COMPLETE 0
  602. simple conn=joe_2,user=joe
  603. SHOW cluster;
  604. ----
  605. txn_specific_cluster
  606. COMPLETE 1
  607. simple conn=joe_2,user=joe
  608. COMMIT;
  609. ----
  610. COMPLETE 0
  611. simple conn=joe_2,user=joe
  612. SHOW cluster;
  613. ----
  614. new_system_default
  615. COMPLETE 1
  616. simple conn=joe_2,user=joe
  617. BEGIN;
  618. ----
  619. COMPLETE 0
  620. simple conn=joe_2,user=joe
  621. SET cluster TO 'foo_bar';
  622. ----
  623. COMPLETE 0
  624. simple conn=joe_2,user=joe
  625. SHOW cluster;
  626. ----
  627. foo_bar
  628. COMPLETE 1
  629. simple conn=joe_2,user=joe
  630. ROLLBACK;
  631. ----
  632. COMPLETE 0
  633. simple conn=joe_2,user=joe
  634. SHOW cluster;
  635. ----
  636. new_system_default
  637. COMPLETE 1
  638. # Not all session variables can be overriden.
  639. simple conn=mz_system,user=mz_system
  640. ALTER SYSTEM SET server_version TO this_wont_work
  641. ----
  642. db error: ERROR: unrecognized configuration parameter "server_version"
  643. simple conn=mz_system,user=mz_system
  644. ALTER SYSTEM SET emit_trace_id_notice TO true
  645. ----
  646. db error: ERROR: unrecognized configuration parameter "emit_trace_id_notice"