Skip to content

Commit

Permalink
Fix an issue where proconfig for functions was not reset with babelfi…
Browse files Browse the repository at this point in the history
…sh installed (babelfish-for-postgresql#2641) (babelfish-for-postgresql#2799)

If babelfish is installed the set_sql_dialect is installed. That means we were never resetting the proconfig values for triggers/functions.
One major symptom of this is mVU failure when there are some other extensions installed which change search path in proconfig.

Task: BABEL-4982

Signed-off-by: Tanzeel Khan <[email protected]>
  • Loading branch information
tanscorpio7 authored Jul 26, 2024
1 parent c17fd7f commit 845747c
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 0 deletions.
95 changes: 95 additions & 0 deletions test/JDBC/expected/BABEL_4982.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
-- psql
CREATE SCHEMA s1
GO

CREATE TABLE s1.babel_4982_t (id VARCHAR(100))
GO



CREATE FUNCTION babel_4982_ddl_trigger()
RETURNS event_trigger AS
$$
BEGIN
INSERT INTO babel_4982_t VALUES (current_setting('search_path'));
END;
$$
SECURITY DEFINER
SET search_path = s1, pg_catalog, pg_temp
LANGUAGE plpgsql;
CREATE EVENT TRIGGER babel_4982_ddl_trigger
ON ddl_command_end
EXECUTE PROCEDURE babel_4982_ddl_trigger();
SELECT set_config('search_path', 'master_dbo, sys, '||current_setting('search_path'), false);
GO
~~START~~
text
master_dbo, sys, "$user", public
~~END~~


SHOW search_path
GO
~~START~~
text
master_dbo, sys, "$user", public
~~END~~


CREATE TABLE babel_4982_t2 (id INT)
GO

SHOW search_path
GO
~~START~~
text
master_dbo, sys, "$user", public
~~END~~


BEGIN
GO

SHOW search_path
GO
~~START~~
text
master_dbo, sys, "$user", public
~~END~~


DROP TABLE babel_4982_t2
GO

SHOW search_path
GO
~~START~~
text
master_dbo, sys, "$user", public
~~END~~


COMMIT
GO

-- two entries since two DDLs after trigger was created
SELECT * FROM s1.babel_4982_t
GO
~~START~~
varchar
s1, pg_catalog, pg_temp
s1, pg_catalog, pg_temp
~~END~~


DROP EVENT TRIGGER babel_4982_ddl_trigger
GO

DROP FUNCTION babel_4982_ddl_trigger
GO

DROP TABLE s1.babel_4982_t
GO

DROP SCHEMA s1
GO
64 changes: 64 additions & 0 deletions test/JDBC/input/BABEL_4982.mix
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
-- psql
CREATE SCHEMA s1
GO

CREATE TABLE s1.babel_4982_t (id VARCHAR(100))
GO

CREATE FUNCTION babel_4982_ddl_trigger()
RETURNS event_trigger AS
$$
BEGIN
INSERT INTO babel_4982_t VALUES (current_setting('search_path'));
END;
$$
SECURITY DEFINER
SET search_path = s1, pg_catalog, pg_temp
LANGUAGE plpgsql;

CREATE EVENT TRIGGER babel_4982_ddl_trigger
ON ddl_command_end
EXECUTE PROCEDURE babel_4982_ddl_trigger();

SELECT set_config('search_path', 'master_dbo, sys, '||current_setting('search_path'), false);
GO

SHOW search_path
GO

CREATE TABLE babel_4982_t2 (id INT)
GO

SHOW search_path
GO

BEGIN
GO

SHOW search_path
GO

DROP TABLE babel_4982_t2
GO

SHOW search_path
GO

COMMIT
GO

-- two entries since two DDLs after trigger was created
SELECT * FROM s1.babel_4982_t
GO

DROP EVENT TRIGGER babel_4982_ddl_trigger
GO

DROP FUNCTION babel_4982_ddl_trigger
GO

DROP TABLE s1.babel_4982_t
GO

DROP SCHEMA s1
GO

0 comments on commit 845747c

Please sign in to comment.