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

For select statement can not see any changes made in DO block #7713

Closed
BobyBel77 opened this issue Aug 17, 2023 · 5 comments · Fixed by #7714
Closed

For select statement can not see any changes made in DO block #7713

BobyBel77 opened this issue Aug 17, 2023 · 5 comments · Fixed by #7714

Comments

@BobyBel77
Copy link

There are many changes started from In Firebird 3.0.
One of them is "PSQL Cursor Stabilization". This is basic functionality and now for stability statement cannot see it's own changes.

I have 5 different cases with insert record in do block with different visibility in for cycle:

  1. for select ... from ... into - do not see any changes
  2. for execute statement 'select ... from ... ' into - see changes
  3. If create view (select from ...) and after that use created view - see changes
  4. If use cursor - open, fetch, ... see any changes
  5. If create stored procedure with suspend evry row from select - do not see changes

You can find the SQLS:
01 - create tables, view, SP, trigger and data.
02 - 5 samples of the different cases

Regards,
Boris Belchev

01. CREATE_DB_TABLES.txt
02. TESTS.txt

@hvlad
Copy link
Member

hvlad commented Aug 18, 2023

Case 5 doesn't corresponds to the description, actually it is copy of case 2.

As @dyemanov already said in support only the case 3 (with a view) is suspicious, all else as expected.

@hvlad hvlad self-assigned this Aug 18, 2023
@aafemt
Copy link
Contributor

aafemt commented Aug 18, 2023

I don't see in documentation what was the purpose for cursors to be an exception from rules?

@hvlad
Copy link
Member

hvlad commented Aug 18, 2023

I don't see in documentation what was the purpose for cursors to be an exception from rules?

It is impossible to detect if given SQL operator is executed within the scope of the explicit cursor, or no.
Thus it is impossible to conclude if cursor should see changes by that operator or no.

@hvlad
Copy link
Member

hvlad commented Aug 18, 2023

Issue with view is related with a way of how engine handles view with subqueries in select list.
Looking for correct fix.

hvlad added a commit that referenced this issue Aug 19, 2023
stability of implicit cursor could be broken, if cursor's select expression is based
on view with sub-query in select list, or
on table with sub-query in computed field.
@hvlad
Copy link
Member

hvlad commented Aug 19, 2023

A bit more test cases, based on metadata above.

  1. Stable (no view, select with sub-query)
delete from TABLE_BBB;
insert into TABLE_BBB (AAA_ID, DBL)
select A.ID,
       case when A.ID > 2 then (select sum(B.DBL) from TABLE_BBB B where B.AAA_ID < A.ID)
            else A.ID * 10
       end DBL
  from TABLE_AAA A
order by A.ID;
  1. Not stable (view with sub-query)
delete from TABLE_BBB;
insert into TABLE_BBB (AAA_ID, DBL)
select A.ID, A.DBL
  from TABLE_AAA_VIEW A
order by A.ID;
  1. Stable (view with join and group by, no subquery)
CREATE OR ALTER VIEW TABLE_AAA_VIEW_J(ID,  DBL)
AS
select A.ID,
       case when A.ID > 2 then sum(B.DBL) else A.ID * 10 end DBL
  from TABLE_AAA A left join TABLE_BBB B on B.AAA_ID < A.ID
group by A.ID;

delete from TABLE_BBB;
insert into TABLE_BBB (AAA_ID, DBL)
select A.ID, A.DBL
  from TABLE_AAA_VIEW_J A
order by A.ID;
  1. Not stable (use computed field with sub-query, no view)
alter table TABLE_AAA
  add dbl_expr computed by (
    case
      when TABLE_AAA.ID > 2 then (select sum(B.DBL) from TABLE_BBB B where B.AAA_ID < TABLE_AAA.ID)
      else TABLE_AAA.ID * 10
    end );
commit

delete from TABLE_BBB;
insert into TABLE_BBB (AAA_ID, DBL)
select A.ID, A.dbl_expr
  from TABLE_AAA A
order by A.ID;

@hvlad hvlad linked a pull request Aug 19, 2023 that will close this issue
hvlad added a commit that referenced this issue Aug 25, 2023
hvlad added a commit that referenced this issue Aug 25, 2023
stability of implicit cursor could be broken, if cursor's select expression is based
on view with sub-query in select list, or
on table with sub-query in computed field.
hvlad added a commit that referenced this issue Aug 25, 2023
stability of implicit cursor could be broken, if cursor's select expression is based
on view with sub-query in select list, or
on table with sub-query in computed field.
@hvlad hvlad closed this as completed Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment