Debian Codegraph @

contrib/citext/sql/create_index_acl.sql

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