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

Wrong value of the new field at the old records, created before that new field was added. [CORE5507] #5776

Closed
firebird-automations opened this issue Mar 24, 2017 · 5 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @hvlad

RECREATE TABLE T (ID INT NOT NULL, DESCR VARCHAR(32) NOT NULL);
COMMIT;

INSERT INTO T (ID, DESCR) VALUES (1, 'No F1 field');
COMMIT;

ALTER TABLE T ADD F1 VARCHAR(16) DEFAULT 'XYZ' NOT NULL;
COMMIT;

INSERT INTO T (ID, DESCR) VALUES (2, 'F1 field, default XYZ');
COMMIT;

SELECT * FROM T;
COMMIT;

ALTER TABLE T ALTER COLUMN F1 SET DEFAULT 'ABC';
COMMIT;

INSERT INTO T (ID, DESCR) VALUES (3, 'F1 field, default ABC');
COMMIT;

SELECT * FROM T;
COMMIT;

After the first select all is as expected:

      ID DESCR                            F1

============ ================================ ================
1 No F1 field XYZ
2 F1 field, default XYZ XYZ

after the second select
expected

      ID DESCR                            F1

============ ================================ ================
1 No F1 field ABC
2 F1 field, default XYZ XYZ
3 F1 field, default ABC ABC

actual

      ID DESCR                            F1

============ ================================ ================
1 No F1 field XYZ
2 F1 field, default XYZ XYZ
3 F1 field, default ABC ABC

Note value of the field F1 at the first record: it is expected that is should be the same as latest DEFAULT value.
Also note that 2nd and 3rd INSERTs assigns correct value to the omitted field - same as latest DEFAULT value.

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

When record in old format is read it should be converted to the most current format.
Engine look up default values for the new NOT NULL fields (not present in original format).
Default values is stored at RDB$RELATION_FIELDS (in source and BLR form).

Since ODS12 default value for the NOT NULL fields is stored at RDB$FORMAT.RDB$DESCRIPTOR blob also.
AFAIU, it was done to have ability to convert record into any format, not necessary most current.

The problem is that change of default value it is not recorded at RDB$FORMAT: new format is not created
and current format is not updated. New default stored in RDB$RELATION_FIELDS only (and it allows to
assign values to the fields omitted in INSERT statement).

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

Accordingly to the discussion happened in fb-devel, I recommend this ticket to be closed as "Won't fix".

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

After discussion in fb-devel i consider v3 behavior more correct than it was before.

@firebird-automations
Copy link
Collaborator Author

Modified by: @hvlad

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

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

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

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