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

Gouping error on deleting [CORE3862] #4202

Closed
firebird-automations opened this issue May 31, 2012 · 6 comments
Closed

Gouping error on deleting [CORE3862] #4202

firebird-automations opened this issue May 31, 2012 · 6 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Marcelo R Vellame (marcelorv)

Duplicates CORE634

When i tryed to delete some records in table "a" by a subselect on table "a" join "b" join "c" dicovered that the grouping of function min() (and avg() too) is not working on delete for the same table.

To exemplify there goes a simple script:

create table iceSling (
id integer,
yearOfBirth integer,
name varchar(30),
CONSTRAINT someUniqueConstrain PRIMARY KEY (ID)
)
-- execute and commit the create

INSERT INTO ICESLING (ID, YEAROFBIRTH, NAME) VALUES ('1', '1980', 'ZECA');
INSERT INTO ICESLING (ID, YEAROFBIRTH, NAME) VALUES ('2', '1980', 'CHICO');
INSERT INTO ICESLING (ID, YEAROFBIRTH, NAME) VALUES ('3', '1983', 'LEILA');
-- execute and commit the inserts

--Now execute this selection: (this works just fine)
select *
from ICESLING where ID in (
select min(http://i.ID) from ICESLING i
where i.YEAROFBIRTH=1980
)

--Now execute try this:
--Notice that this is the same SQL form select, only changed "select *" for "delete"
--(here is the problem: the min() grouping is ignored and 2 records are deleted, only one shoud be deleted)
delete
from ICESLING where ID in (
select min(http://i.ID) from ICESLING i
where i.YEAROFBIRTH=1980
)

Obs. This happens for avg() too;
Obs.2 Max() works ok;
Obs.3 This happens only if is the selected and deleted table are the same
Obs.4 IceSling knocked FireBird :) (Oracle and Postgre worked just fine)

Commits: cdca8e3 91cdb8e 170b799 5b76e52 addfee3 FirebirdSQL/fbt-repository@a5ae04e

====== Test Details ======

Test case from this ticket was added into core-3362.fbt ("Cursors should ignore changes made by the same statement")

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

This is a known issue -- Firebird does not fully resolve the inner SELECT before executing the outer SELECT.

So, when the outer SELECT is evaluating row ID = 1, that ID = MIN( ID) and the row is deleted. The engine then proceeds to evaluate row ID = 2, that ID also = MIN( ID) so the row is deleted.

There are workarounds for this issue, which involve changing the SQL.

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

It duplicates CORE634 and probably other related tickets as well.

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Duplicate [ 3 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Link: This issue duplicates CORE634 [ CORE634 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

QA Status: No test

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Resolved [ 5 ]

QA Status: No test => Covered by another test(s)

Test Details: Test case from this ticket was added into core-3362.fbt ("Cursors should ignore changes made by the same statement")

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