src/backend/utils/init/miscinit.c
/*
 * Change Role ID while running (SET ROLE)
 *
 * If roleid is InvalidOid, we are doing SET ROLE NONE: revert to the
 * session user authorization.	In this case the is_superuser argument
 * is ignored.
 *
 * When roleid is not InvalidOid, the caller must have checked whether
 * the session user has permission to become that role.  (We cannot check
 * here because this routine must be able to execute in a failed transaction
 * to restore a prior value of the ROLE GUC variable.)
 */
Change Role ID while running (SET ROLE)
If roleid is InvalidOid, we are doing SET ROLE NONE: revert to the
session user authorization.  In this case the is_superuser argument
is ignored.

When roleid is not InvalidOid, the caller must have checked whether
the session user has permission to become that role.  (We cannot check
here because this routine must be able to execute in a failed transaction
to restore a prior value of the ROLE GUC variable.)
Change Role ID while running ( SET ROLE ) If roleid is InvalidOid we are doing SET ROLE NONE : revert to the session user authorization . In this case the is_superuser argument is ignored . When roleid is not InvalidOid the caller must have checked whether the session user has permission to become that role . ( We cannot check here because this routine must be able to execute in a failed transaction to restore a prior value of the ROLE GUC variable . )
void
SetCurrentRoleId(Oid roleid, bool is_superuser)
{
	if (!OidIsValid(roleid))
	{
		if (!OidIsValid(SessionUserId))
			return;
		roleid = SessionUserId;
		is_superuser = SessionUserIsSuperuser;
		SetRoleIsActive = false;
	}
	else
		SetRoleIsActive = true;
	SetOuterUserId(roleid);
	if ((Gp_role == GP_ROLE_DISPATCH || Gp_role == GP_ROLE_EXECUTE) && IsResQueueEnabled())
	{
		SetResQueueId();
	}
	SetConfigOption("is_superuser",
					is_superuser ? "on" : "off",
					PGC_INTERNAL, PGC_S_OVERRIDE);
}
void SetCurrentRoleId ( Oid roleid , bool is_superuser ) { if ( ! OidIsValid ( roleid ) ) { if ( ! OidIsValid ( SessionUserId ) ) return ; roleid = SessionUserId ; is_superuser = SessionUserIsSuperuser ; SetRoleIsActive = false ; } else SetRoleIsActive = true ; SetOuterUserId ( roleid ) ; if ( ( Gp_role == GP_ROLE_DISPATCH || Gp_role == GP_ROLE_EXECUTE ) && IsResQueueEnabled ( ) ) { SetResQueueId ( ) ; } SetConfigOption ( " " , is_superuser ? " " : " " , PGC_INTERNAL , PGC_S_OVERRIDE ) ; }
Change Role ID while running (SET ROLE)
 If roleid is InvalidOid, we are doing SET ROLE NONE: revert to the
 session user authorization.
Change Role ID while running ( SET ROLE ) If roleid is InvalidOid we are doing SET ROLE NONE : revert to the session user authorization .
/*
	 * Get correct info if it's SET ROLE NONE
	 *
	 * If SessionUserId hasn't been set yet, just do nothing --- the eventual
	 * SetSessionUserId call will fix everything.  This is needed since we
	 * will get called during GUC initialization.
	 */ /* If resource scheduling enabled, set the cached queue for the new role.*/