aws / pg_tle

Framework for building trusted language extensions for PostgreSQL
Apache License 2.0
333 stars 31 forks source link

Add missing dependencies on control/SQL functions when TLE is created via cascade #234

Closed adamguo0 closed 1 year ago

adamguo0 commented 1 year ago

Issue #, if available: #228

Description of changes:

Add dependencies on control and sql functions when an extension is created via cascade. Previously these dependencies were recorded only for the top-level extension. This PR moves this logic to CreateExtensionInternal where it is run for each cascading TLE.

Running the scenario reported in #228:

postgres=# create extension pg_tle;
CREATE EXTENSION
postgres=# select pgtle.install_extension(
postgres(#     'ofoo',
postgres(#     '1',
postgres(#     'ofoo',
postgres(#     'create function ofoo_exists() returns int language sql as $$select 1$$'
postgres(# );
 install_extension
-------------------
 t
(1 row)

postgres=# select pgtle.install_extension(
postgres(#     'obar',
postgres(#     '1',
postgres(#     'obar',
postgres(#     'create function obar_exists() returns int language sql as $$select 1$$',
postgres(#     array['ofoo']
postgres(# );
 install_extension
-------------------
 t
(1 row)

postgres=# create extension obar cascade;
NOTICE:  installing required extension "ofoo"
CREATE EXTENSION
postgres=# select * from pg_extension;
  oid  | extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition
-------+---------+----------+--------------+----------------+------------+-----------+--------------
 14331 | plpgsql |       10 |           11 | f              | 1.0        |           |
 16385 | pg_tle  |       10 |        16384 | f              | 1.2.0      | {16417}   | {""}
 16440 | ofoo    |       10 |         2200 | f              | 1          |           |
 16442 | obar    |       10 |         2200 | f              | 1          |           |
(4 rows)

postgres=# select * from pg_depend where objid = 16440;
 classid | objid | objsubid | refclassid | refobjid | refobjsubid | deptype
---------+-------+----------+------------+----------+-------------+---------
    3079 | 16440 |        0 |       3079 |    16385 |           0 | n
    3079 | 16440 |        0 |       2615 |     2200 |           0 | n
    3079 | 16440 |        0 |       1255 |    16437 |           0 | n
    3079 | 16440 |        0 |       1255 |    16436 |           0 | n
(4 rows)

postgres=# select 16437::regproc, 16436::regproc;
       regproc        |       regproc
----------------------+---------------------
 pgtle."ofoo.control" | pgtle."ofoo--1.sql"
(1 row)

ofoo (which is created through cascading from obar) has dependencies recorded correctly on its control and sql functions.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.