fix: Prevent infinite recursion with self-referencing views
Fixes #2283 Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
This commit is contained in:
@@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- #2518, Fix a regression when embedding views where base tables have a different column order for FK columns - @wolfgangwalther
|
- #2518, Fix a regression when embedding views where base tables have a different column order for FK columns - @wolfgangwalther
|
||||||
- #2458, Fix a regression with the location header when inserting into views with PKs from multiple tables - @wolfgangwalther
|
- #2458, Fix a regression with the location header when inserting into views with PKs from multiple tables - @wolfgangwalther
|
||||||
- #2356, Fix a regression in openapi output with mode follow-privileges - @wolfgangwalther
|
- #2356, Fix a regression in openapi output with mode follow-privileges - @wolfgangwalther
|
||||||
|
- #2283, Fix infinite recursion when loading schema cache with self-referencing view - @wolfgangwalther
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
|
|||||||
@@ -895,8 +895,13 @@ allViewsKeyDependencies =
|
|||||||
(entry->>'resorigcol')::int as resorigcol
|
(entry->>'resorigcol')::int as resorigcol
|
||||||
from target_entries
|
from target_entries
|
||||||
),
|
),
|
||||||
recursion as(
|
-- CYCLE detection according to PG docs: https://www.postgresql.org/docs/current/queries-with.html#QUERIES-WITH-CYCLE
|
||||||
select r.*
|
-- Can be replaced with CYCLE clause once PG v13 is EOL.
|
||||||
|
recursion(view_id, view_schema, view_name, view_column, resorigtbl, resorigcol, is_cycle, path) as(
|
||||||
|
select
|
||||||
|
r.*,
|
||||||
|
false,
|
||||||
|
ARRAY[resorigtbl]
|
||||||
from results r
|
from results r
|
||||||
where view_schema = ANY ($1)
|
where view_schema = ANY ($1)
|
||||||
union all
|
union all
|
||||||
@@ -906,9 +911,12 @@ allViewsKeyDependencies =
|
|||||||
view.view_name,
|
view.view_name,
|
||||||
view.view_column,
|
view.view_column,
|
||||||
tab.resorigtbl,
|
tab.resorigtbl,
|
||||||
tab.resorigcol
|
tab.resorigcol,
|
||||||
|
tab.resorigtbl = ANY(path),
|
||||||
|
path || tab.resorigtbl
|
||||||
from recursion view
|
from recursion view
|
||||||
join results tab on view.resorigtbl=tab.view_id and view.resorigcol=tab.view_column
|
join results tab on view.resorigtbl=tab.view_id and view.resorigcol=tab.view_column
|
||||||
|
where not is_cycle
|
||||||
)
|
)
|
||||||
select
|
select
|
||||||
sch.nspname as table_schema,
|
sch.nspname as table_schema,
|
||||||
|
|||||||
Vendored
+4
@@ -2902,3 +2902,7 @@ $$;
|
|||||||
|
|
||||||
create trigger ins instead of insert on with_multiple_pks
|
create trigger ins instead of insert on with_multiple_pks
|
||||||
for each row execute procedure with_multiple_pks_insert();
|
for each row execute procedure with_multiple_pks_insert();
|
||||||
|
|
||||||
|
-- issue https://github.com/PostgREST/postgrest/issues/2283
|
||||||
|
create view self_recursive_view as table projects;
|
||||||
|
create or replace view self_recursive_view as table self_recursive_view;
|
||||||
|
|||||||
Reference in New Issue
Block a user