Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gbak cannot restore database with cyclic dependencies between views [CORE4812] #5110

Open
firebird-automations opened this issue May 26, 2015 · 8 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @cincuranet

Steps to reproduce:
*** 1:
CREATE OR ALTER VIEW CYCLE_A(
COL)
AS
select RDB$RELATION_ID from rdb$database
;
*** 2:
CREATE OR ALTER VIEW CYCLE_B(
COL)
AS
select RDB$RELATION_ID from rdb$database
;
*** 3:
CREATE OR ALTER VIEW CYCLE_A(
COL)
AS
select RDB$RELATION_ID from rdb$database
union all
select col from cycle_b
;
*** 4:
CREATE OR ALTER VIEW CYCLE_B(
COL)
AS
select RDB$RELATION_ID from rdb$database
union all
select col from cycle_a
;
*** 5: Backup database using gbak.
*** 6: Try restoring database using gbak. Fails with depth limit failure.

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

I wonder if the definition of circular views should be prevented?

{that's one way of solving this problem ;-]}

@firebird-automations
Copy link
Collaborator Author

Commented by: @cincuranet

As the i.e. FKs can have cyclic deps I believe this is valid scenario.

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

Understood but, FKs can't contain invalid references, and the restore of the FKs is agnostic to the circular'ness of the relationship.

The constraint are restored after the data has been restored and the index building doesn't re-check the constraint (it is checked when the FK is initially defined, so the data/values is guaranteed to be correct).

Further, with the introduction of recursive CTE's, the need for circular Views has been practically eliminated.

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

Cyclic views should be disallowed. Views should be "expanded" in compile time, so that does not work.

@firebird-automations
Copy link
Collaborator Author

Commented by: @cincuranet

@sean You can have cycles in computed fields (yes it's ugly). ;) That's more like the views.

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

When we do:
SQL> create procedure sp_a as begin end;
SQL> create procedure sp_b as begin end;
SQL> set term ^;
SQL> alter procedure sp_a as begin execute procedure sp_b; end^
SQL> alter procedure sp_b as begin execute procedure sp_a; end^
SQL> set term ;^
SQL> exit;

-- then ISQL -X shows almost the same: first it displays procedures with empty bodies and after it fills them.
Perhaps, restore do the same but it doesn`t show details:
...
gbak:started transaction
gbak:restoring stored procedure SP_A
gbak:restoring stored procedure SP_B
...

What if restore first will create all view like this:

create view v_a as
-- temp., "dummy" columns:
select 1 as field_of_num_type, '' as field_of_text_type, current_date as field_of_date_type, ...
from rdb$database;

create view v_b as
-- temp., "dummy" columns:
select 1 as field_of_num_type, '' as field_of_text_type, current_date as field_of_date_type, ...
from rdb$database;

-- and after all such 'dummy' views with necessary columns are created, continue with:

alter view v_a as <stored "real" select for v_a>;
alter view v_b as <stored "real" select for v_b>;
etc.

- ?

@firebird-automations
Copy link
Collaborator Author

Commented by: @cincuranet

That's what I'm doing in a code I'm writing right now.

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

> @sean You can have cycles in computed fields (yes it's ugly). ;) That's more like the views.

Jiri, it just crashs. Conceptually, this type of cyclic does not and cannot work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant