diff --git a/src/backend/distributed/deparser/citus_ruleutils.c b/src/backend/distributed/deparser/citus_ruleutils.c index 12bdafeb2..91343af8f 100644 --- a/src/backend/distributed/deparser/citus_ruleutils.c +++ b/src/backend/distributed/deparser/citus_ruleutils.c @@ -1275,6 +1275,8 @@ simple_quote_literal(StringInfo buf, const char *val) * * CURRENT_USER - resolved to the user name of the current role being used * SESSION_USER - resolved to the user name of the user that opened the session + * CURRENT_ROLE - same as CURRENT_USER, resolved to the user name of the current role being used + * Postgres treats CURRENT_ROLE is equivalent to CURRENT_USER, and we follow the same approach. * * withQuoteIdentifier is used, because if the results will be used in a query the quotes are needed but if not there * should not be extra quotes. @@ -1290,7 +1292,9 @@ RoleSpecString(RoleSpec *spec, bool withQuoteIdentifier) quote_identifier(spec->rolename) : spec->rolename; } - + #if PG_VERSION_NUM >= PG_VERSION_14 + case ROLESPEC_CURRENT_ROLE: + #endif case ROLESPEC_CURRENT_USER: { return withQuoteIdentifier ? diff --git a/src/test/regress/expected/pg14.out b/src/test/regress/expected/pg14.out index 16fb3e8f9..a8b74c209 100644 --- a/src/test/regress/expected/pg14.out +++ b/src/test/regress/expected/pg14.out @@ -320,5 +320,62 @@ NOTICE: dropping metadata on the node (localhost,57638) (1 row) +-- ALTER STATISTICS .. OWNER TO CURRENT_ROLE +CREATE TABLE st1 (a int, b int); +CREATE STATISTICS role_s1 ON a, b FROM st1; +SELECT create_distributed_table('st1','a'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +ALTER STATISTICS role_s1 OWNER TO CURRENT_ROLE; +SET citus.enable_ddl_propagation TO off; -- for enterprise +CREATE ROLE role_1 WITH LOGIN SUPERUSER; +NOTICE: not propagating CREATE ROLE/USER commands to worker nodes +HINT: Connect to worker nodes directly to manually create all necessary users and roles. +SET citus.enable_ddl_propagation TO on; +SELECT run_command_on_workers($$CREATE ROLE role_1 WITH LOGIN SUPERUSER;$$); + run_command_on_workers +--------------------------------------------------------------------- + (localhost,57637,t,"CREATE ROLE") + (localhost,57638,t,"CREATE ROLE") +(2 rows) + +ALTER STATISTICS role_s1 OWNER TO CURRENT_ROLE; +SELECT run_command_on_workers($$SELECT rolname FROM pg_roles WHERE oid IN (SELECT stxowner FROM pg_statistic_ext WHERE stxname LIKE 'role\_s1%');$$); + run_command_on_workers +--------------------------------------------------------------------- + (localhost,57637,t,postgres) + (localhost,57638,t,postgres) +(2 rows) + +SET ROLE role_1; +ALTER STATISTICS role_s1 OWNER TO CURRENT_ROLE; +SELECT run_command_on_workers($$SELECT rolname FROM pg_roles WHERE oid IN (SELECT stxowner FROM pg_statistic_ext WHERE stxname LIKE 'role\_s1%');$$); + run_command_on_workers +--------------------------------------------------------------------- + (localhost,57637,t,role_1) + (localhost,57638,t,role_1) +(2 rows) + +SET ROLE postgres; +ALTER STATISTICS role_s1 OWNER TO CURRENT_USER; +SELECT run_command_on_workers($$SELECT rolname FROM pg_roles WHERE oid IN (SELECT stxowner FROM pg_statistic_ext WHERE stxname LIKE 'role\_s1%');$$); + run_command_on_workers +--------------------------------------------------------------------- + (localhost,57637,t,postgres) + (localhost,57638,t,postgres) +(2 rows) + +SET ROLE to NONE; +ALTER STATISTICS role_s1 OWNER TO CURRENT_ROLE; +SELECT run_command_on_workers($$SELECT rolname FROM pg_roles WHERE oid IN (SELECT stxowner FROM pg_statistic_ext WHERE stxname LIKE 'role\_s1%');$$); + run_command_on_workers +--------------------------------------------------------------------- + (localhost,57637,t,postgres) + (localhost,57638,t,postgres) +(2 rows) + set client_min_messages to error; drop schema pg14 cascade; diff --git a/src/test/regress/sql/pg14.sql b/src/test/regress/sql/pg14.sql index ce36c6922..f93167766 100644 --- a/src/test/regress/sql/pg14.sql +++ b/src/test/regress/sql/pg14.sql @@ -123,5 +123,25 @@ RESET client_min_messages; SELECT stop_metadata_sync_to_node('localhost', :worker_1_port); SELECT stop_metadata_sync_to_node('localhost', :worker_2_port); +-- ALTER STATISTICS .. OWNER TO CURRENT_ROLE +CREATE TABLE st1 (a int, b int); +CREATE STATISTICS role_s1 ON a, b FROM st1; +SELECT create_distributed_table('st1','a'); +ALTER STATISTICS role_s1 OWNER TO CURRENT_ROLE; +SET citus.enable_ddl_propagation TO off; -- for enterprise +CREATE ROLE role_1 WITH LOGIN SUPERUSER; +SET citus.enable_ddl_propagation TO on; +SELECT run_command_on_workers($$CREATE ROLE role_1 WITH LOGIN SUPERUSER;$$); +ALTER STATISTICS role_s1 OWNER TO CURRENT_ROLE; +SELECT run_command_on_workers($$SELECT rolname FROM pg_roles WHERE oid IN (SELECT stxowner FROM pg_statistic_ext WHERE stxname LIKE 'role\_s1%');$$); +SET ROLE role_1; +ALTER STATISTICS role_s1 OWNER TO CURRENT_ROLE; +SELECT run_command_on_workers($$SELECT rolname FROM pg_roles WHERE oid IN (SELECT stxowner FROM pg_statistic_ext WHERE stxname LIKE 'role\_s1%');$$); +SET ROLE postgres; +ALTER STATISTICS role_s1 OWNER TO CURRENT_USER; +SELECT run_command_on_workers($$SELECT rolname FROM pg_roles WHERE oid IN (SELECT stxowner FROM pg_statistic_ext WHERE stxname LIKE 'role\_s1%');$$); +SET ROLE to NONE; +ALTER STATISTICS role_s1 OWNER TO CURRENT_ROLE; +SELECT run_command_on_workers($$SELECT rolname FROM pg_roles WHERE oid IN (SELECT stxowner FROM pg_statistic_ext WHERE stxname LIKE 'role\_s1%');$$); set client_min_messages to error; drop schema pg14 cascade;