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 field position after ALTER POSITION [CORE2932] #3315

Closed
firebird-automations opened this issue Mar 19, 2010 · 13 comments
Closed

Wrong field position after ALTER POSITION [CORE2932] #3315

firebird-automations opened this issue Mar 19, 2010 · 13 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Gabor Boros (gaborboros)

I got ugly(random?) field position after an ALTER TABLE ... ALTER ... POSITION statement.
Described on firebird-devel in "Strange ALTER POSITION result" thread.

Commits: 119d1e1 a1d62c1 FirebirdSQL/fbt-repository@063d5b6

@firebird-automations
Copy link
Collaborator Author

Modified by: @asfernandes

assignee: Adriano dos Santos Fernandes [ asfernandes ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @asfernandes

summary: Ugly field position after ALTER POSITION => Wrong field position after ALTER POSITION

@firebird-automations
Copy link
Collaborator Author

Modified by: @asfernandes

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

resolution: Fixed [ 1 ]

Fix Version: 3.0 Alpha 1 [ 10331 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

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

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

It seems that new position can be evaluated wrong in case when field is "moved" to the end of field list after some manipulations.
Sample:

recreate table test(
f01 int
,f02 int
,f03 int
,f04 int
,f05 int
,f06 int
,f07 int
,f08 int
,f09 int
,f10 int
);
commit;

set echo on;
show table test; -- 1
set echo off;

alter table test drop f01, drop f02, drop f03, drop f04;
commit;

-- move field f10 to the "start" of DDL:
alter table test alter f10 position 3;
-- after this DDL must be: f05 f06 f10 f07 f08 f09
commit;

set echo on;
show table test; -- 2
set echo off;

alter table test add n01 int, add n02 int, add n03 int, add n04 int, add n05 int, add n06 int;
commit;

alter table test drop n01, drop n02, drop n03, drop n04;
-- after this DDL must be: f05 f06 f10 f07 f08 f09 n05 n06
commit;

set echo on;
show table test; -- 3
set echo off;

-- move field f10 to the "end" of DDL: exchange positions of n05 and f10
alter table test alter f10 position 7, alter n06 position 3;
-- after this DDL result must be: f05 f06 n05 f07 f08 f09 f10 n06
commit;

set echo on;
show table test; -- 4

Result for "show table test; -- 4":

F05 INTEGER Nullable -- 1
F06 INTEGER Nullable -- 2
N06 INTEGER Nullable -- 3
F07 INTEGER Nullable -- 4
F08 INTEGER Nullable -- 5
F09 INTEGER Nullable -- 6
N05 INTEGER Nullable -- 7
F10 INTEGER Nullable -- 8 <<<<<<<<<<<<<<<<<< ??? <<<<<<<<<<<<<<

So, field `F10` is appeared at the position #⁠8 rather than #⁠7 as itwas required.

But if change
-- move field f10 to the "end" of DDL: exchange positions of n05 and f10
alter table test alter f10 position 7, alter n06 position 3;

To:
-- move field f10 to the "end" of DDL: exchange positions of n05 and f10
alter table test alter n06 position 3, alter f10 position 7;

(i.e. first move `n06` to the beginning of DDL, and after this - move `f10` to the end)

-- then all works fine:

show table test; -- 4
F05 INTEGER Nullable -- 1
F06 INTEGER Nullable -- 2
N06 INTEGER Nullable -- 3
F07 INTEGER Nullable -- 4
F08 INTEGER Nullable -- 5
F09 INTEGER Nullable -- 6
F10 INTEGER Nullable -- 7
N05 INTEGER Nullable -- 8

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

PS. Tested on WI-T3.0.0.31773

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

One more sample, shorter than previous:

SQL> recreate table t(f01 int, f02 int, f03 int);
SQL> commit;
SQL> alter table t drop f01, drop f02;
SQL> commit;
SQL> alter table t add new_a int, add new_b int;
SQL> commit;
SQL> show table t;
F03 INTEGER Nullable
NEW_A INTEGER Nullable
NEW_B INTEGER Nullable

SQL> alter table t alter f03 position 3;
SQL> commit;

SQL> show table t;
F03 INTEGER Nullable ---------------- position was not changed!
NEW_A INTEGER Nullable
NEW_B INTEGER Nullable

SQL> alter table t alter f03 position 2;
SQL> commit;

SQL> show table t;
F03 INTEGER Nullable ---------------- position was not changed!
NEW_A INTEGER Nullable
NEW_B INTEGER Nullable

@firebird-automations
Copy link
Collaborator Author

Modified by: @asfernandes

status: Closed [ 6 ] => Reopened [ 4 ]

resolution: Fixed [ 1 ] =>

Fix Version: 3.0 Alpha 1 [ 10331 ] =>

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

Pavel, I think this is wrong:

-- move field f10 to the "end" of DDL: exchange positions of n05 and f10
alter table test alter f10 position 7, alter n06 position 3;
-- after this DDL result must be: f05 f06 n05 f07 f08 f09 f10 n06

It must be:

F05 INTEGER Nullable
F06 INTEGER Nullable
N06 INTEGER Nullable
F07 INTEGER Nullable
F08 INTEGER Nullable
F09 INTEGER Nullable
N05 INTEGER Nullable
F10 INTEGER Nullable

I'm changing for this. Please retest.

@firebird-automations
Copy link
Collaborator Author

Modified by: @asfernandes

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

resolution: Fixed [ 1 ]

Fix Version: 3.0 Beta 2 [ 10586 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

> I think this is wrong

You're right, it was my mistake.
I've tested on WI-T3.0.0.31780 both cases -- now all works fine.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

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

QA Status: Done successfully

@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