Debian Codegraph @

contrib/citext/expected/create_index_acl.out

raw
1 -- Each DefineIndex() ACL check uses either the original userid or the table
2 -- owner userid; see its header comment. Here, confirm that DefineIndex()
3 -- uses its original userid where necessary. The test works by creating
4 -- indexes that refer to as many sorts of objects as possible, with the table
5 -- owner having as few applicable privileges as possible. (The privileges.sql
6 -- regress_sro_user tests look for the opposite defect; they confirm that
7 -- DefineIndex() uses the table owner userid where necessary.)
8 SET allow_in_place_tablespaces = true;
9 CREATE TABLESPACE regress_create_idx_tblspace LOCATION '';
10 RESET allow_in_place_tablespaces;
11 BEGIN;
12 CREATE ROLE regress_minimal;
13 CREATE SCHEMA s;
14 CREATE EXTENSION citext SCHEMA s;
15 -- Revoke all conceivably-relevant ACLs within the extension. The system
16 -- doesn't check all these ACLs, but this will provide some coverage if that
17 -- ever changes.
18 REVOKE ALL ON TYPE s.citext FROM PUBLIC;
19 REVOKE ALL ON FUNCTION s.citext_pattern_lt FROM PUBLIC;
20 REVOKE ALL ON FUNCTION s.citext_pattern_le FROM PUBLIC;
21 REVOKE ALL ON FUNCTION s.citext_eq FROM PUBLIC;
22 REVOKE ALL ON FUNCTION s.citext_pattern_ge FROM PUBLIC;
23 REVOKE ALL ON FUNCTION s.citext_pattern_gt FROM PUBLIC;
24 REVOKE ALL ON FUNCTION s.citext_pattern_cmp FROM PUBLIC;
25 -- Functions sufficient for making an index column that has the side effect of
26 -- changing search_path at expression planning time.
27 CREATE FUNCTION public.setter() RETURNS bool VOLATILE
28 LANGUAGE SQL AS $$SET search_path = s; SELECT true$$;
29 CREATE FUNCTION s.const() RETURNS bool IMMUTABLE
30 LANGUAGE SQL AS $$SELECT public.setter()$$;
31 CREATE FUNCTION s.index_this_expr(s.citext, bool) RETURNS s.citext IMMUTABLE
32 LANGUAGE SQL AS $$SELECT $1$$;
33 REVOKE ALL ON FUNCTION public.setter FROM PUBLIC;
34 REVOKE ALL ON FUNCTION s.const FROM PUBLIC;
35 REVOKE ALL ON FUNCTION s.index_this_expr FROM PUBLIC;
36 -- Even for an empty table, expression planning calls s.const & public.setter.
37 GRANT EXECUTE ON FUNCTION public.setter TO regress_minimal;
38 GRANT EXECUTE ON FUNCTION s.const TO regress_minimal;
39 -- Function for index predicate.
40 CREATE FUNCTION s.index_row_if(s.citext) RETURNS bool IMMUTABLE
41 LANGUAGE SQL AS $$SELECT $1 IS NOT NULL$$;
42 REVOKE ALL ON FUNCTION s.index_row_if FROM PUBLIC;
43 -- Even for an empty table, CREATE INDEX checks ii_Predicate permissions.
44 GRANT EXECUTE ON FUNCTION s.index_row_if TO regress_minimal;
45 -- Non-extension, non-function objects.
46 CREATE COLLATION s.coll (LOCALE="C");
47 CREATE TABLE s.x (y s.citext);
48 ALTER TABLE s.x OWNER TO regress_minimal;
49 -- Empty-table DefineIndex()
50 CREATE UNIQUE INDEX u0rows ON s.x USING btree
51 ((s.index_this_expr(y, s.const())) COLLATE s.coll s.citext_pattern_ops)
52 TABLESPACE regress_create_idx_tblspace
53 WHERE s.index_row_if(y);
54 ALTER TABLE s.x ADD CONSTRAINT e0rows EXCLUDE USING btree
55 ((s.index_this_expr(y, s.const())) COLLATE s.coll WITH s.=)
56 USING INDEX TABLESPACE regress_create_idx_tblspace
57 WHERE (s.index_row_if(y));
58 -- Make the table nonempty.
59 INSERT INTO s.x VALUES ('foo'), ('bar');
60 -- If the INSERT runs the planner on index expressions, a search_path change
61 -- survives. As of 2022-06, the INSERT reuses a cached plan. It does so even
62 -- under debug_discard_caches, since each index is new-in-transaction. If
63 -- future work changes a cache lifecycle, this RESET may become necessary.
64 RESET search_path;
65 -- For a nonempty table, owner needs permissions throughout ii_Expressions.
66 GRANT EXECUTE ON FUNCTION s.index_this_expr TO regress_minimal;
67 CREATE UNIQUE INDEX u2rows ON s.x USING btree
68 ((s.index_this_expr(y, s.const())) COLLATE s.coll s.citext_pattern_ops)
69 TABLESPACE regress_create_idx_tblspace
70 WHERE s.index_row_if(y);
71 ALTER TABLE s.x ADD CONSTRAINT e2rows EXCLUDE USING btree
72 ((s.index_this_expr(y, s.const())) COLLATE s.coll WITH s.=)
73 USING INDEX TABLESPACE regress_create_idx_tblspace
74 WHERE (s.index_row_if(y));
75 -- Shall not find s.coll via search_path, despite the s.const->public.setter
76 -- call having set search_path=s during expression planning. Suppress the
77 -- message itself, which depends on the database encoding.
78 \set VERBOSITY sqlstate
79 ALTER TABLE s.x ADD CONSTRAINT underqualified EXCLUDE USING btree
80 ((s.index_this_expr(y, s.const())) COLLATE coll WITH s.=)
81 USING INDEX TABLESPACE regress_create_idx_tblspace
82 WHERE (s.index_row_if(y));
83 ERROR: 42704
84 \set VERBOSITY default
85 ROLLBACK;
86 DROP TABLESPACE regress_create_idx_tblspace;