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

Fix crash caused by some form of ALTER TABLE ADD COLUMN statements. #7522

Merged
merged 3 commits into from
Mar 20, 2024

Conversation

emelsimsek
Copy link
Contributor

@emelsimsek emelsimsek commented Feb 20, 2024

DESCRIPTION: Fixes a crash caused by some form of ALTER TABLE ADD COLUMN statements. When adding multiple columns, if one of the ADD COLUMN statements contains a FOREIGN constraint ommitting the referenced columns in the statement, a SEGFAULT occurs.

For instance, the following statement results in a crash:

  ALTER TABLE lt ADD COLUMN new_col1 bool,
                          ADD COLUMN new_col2 int references rt;

Fixes #7520.

@emelsimsek emelsimsek changed the title Fix the crash Fix crash caused by some form of ALTER TABLE ADD COLUMN statements. Feb 20, 2024
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a test would be nice, at least the one noted in linked issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just going to note that I did not think this deserved a test :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally try to add all crashes that we fix as a test, for two reasons:

  1. Make sure that we don't regress in the future
  2. Generally these crashes happen because of using uncommon SQL features. And increasing our coverage for such uncommon features is quite useful for catching other issues too (e.g. we've caught issues introduced in new PG beta versions because our test suite tests some stuff better than Postgres).

Sometimes we don't of course, for instance if it's hard to reproduce the test reliably. But in this case I think adding the test should be very simple.

Copy link

codecov bot commented Feb 20, 2024

Codecov Report

Merging #7522 (4d0fb50) into main (0acb5f6) will decrease coverage by 0.04%.
The diff coverage is 66.66%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7522      +/-   ##
==========================================
- Coverage   89.69%   89.65%   -0.04%     
==========================================
  Files         283      283              
  Lines       60427    60428       +1     
  Branches     7524     7525       +1     
==========================================
- Hits        54197    54178      -19     
- Misses       4078     4097      +19     
- Partials     2152     2153       +1     


if (list_length(constraint->pk_attrs) > 0)
{
char *referencedColumn = strVal(lfirst(list_head(constraint->pk_attrs)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only considering head of the list feels a bit misleading because a pkey might cover more than one column too.

create table ref5(a int, b int, primary key(a, b));

@@ -44,6 +44,15 @@ ERROR: cannot execute ADD COLUMN command with PRIMARY KEY, UNIQUE, FOREIGN and
DETAIL: Adding a column with a constraint in one command is not supported because all constraints in Citus must have explicit names
HINT: You can issue each command separately such as ALTER TABLE referencing ADD COLUMN test_8 data_type; ALTER TABLE referencing ADD CONSTRAINT constraint_name CHECK (check_expression);
ALTER TABLE referencing ADD COLUMN test_8 integer CONSTRAINT check_test_8 CHECK (test_8 > 0);
-- error out properly even if the REFERENCES does not include the column list of the referenced table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the PR description include that this is specific the case we're fixing would be good.

@emelsimsek
Copy link
Contributor Author

@JelteF @onurctirtir, is this change good to go?

@emelsimsek emelsimsek merged commit fdd658a into main Mar 20, 2024
157 of 158 checks passed
@emelsimsek emelsimsek deleted the Fix-AddColumn-Crash branch March 20, 2024 08:06
JelteF pushed a commit that referenced this pull request Apr 16, 2024
…7522)

DESCRIPTION: Fixes a crash caused by some form of ALTER TABLE ADD COLUMN
statements. When adding multiple columns, if one of the ADD COLUMN
statements contains a FOREIGN constraint ommitting the referenced
columns in the statement, a SEGFAULT occurs.

For instance, the following statement results in a crash:

```
  ALTER TABLE lt ADD COLUMN new_col1 bool,
                          ADD COLUMN new_col2 int references rt;

```

Fixes #7520.

(cherry picked from commit fdd658a)
JelteF pushed a commit that referenced this pull request Apr 16, 2024
…7522)

DESCRIPTION: Fixes a crash caused by some form of ALTER TABLE ADD COLUMN
statements. When adding multiple columns, if one of the ADD COLUMN
statements contains a FOREIGN constraint ommitting the referenced
columns in the statement, a SEGFAULT occurs.

For instance, the following statement results in a crash:

```
  ALTER TABLE lt ADD COLUMN new_col1 bool,
                          ADD COLUMN new_col2 int references rt;

```

Fixes #7520.

(cherry picked from commit fdd658a)
JelteF pushed a commit that referenced this pull request Apr 16, 2024
…7522)

DESCRIPTION: Fixes a crash caused by some form of ALTER TABLE ADD COLUMN
statements. When adding multiple columns, if one of the ADD COLUMN
statements contains a FOREIGN constraint ommitting the referenced
columns in the statement, a SEGFAULT occurs.

For instance, the following statement results in a crash:

```
  ALTER TABLE lt ADD COLUMN new_col1 bool,
                          ADD COLUMN new_col2 int references rt;

```

Fixes #7520.

(cherry picked from commit fdd658a)
JelteF pushed a commit that referenced this pull request Apr 16, 2024
…7522)

DESCRIPTION: Fixes a crash caused by some form of ALTER TABLE ADD COLUMN
statements. When adding multiple columns, if one of the ADD COLUMN
statements contains a FOREIGN constraint ommitting the referenced
columns in the statement, a SEGFAULT occurs.

For instance, the following statement results in a crash:

```
  ALTER TABLE lt ADD COLUMN new_col1 bool,
                          ADD COLUMN new_col2 int references rt;

```

Fixes #7520.

(cherry picked from commit fdd658a)
JelteF pushed a commit that referenced this pull request Apr 17, 2024
…7522)

DESCRIPTION: Fixes a crash caused by some form of ALTER TABLE ADD COLUMN
statements. When adding multiple columns, if one of the ADD COLUMN
statements contains a FOREIGN constraint ommitting the referenced
columns in the statement, a SEGFAULT occurs.

For instance, the following statement results in a crash:

```
  ALTER TABLE lt ADD COLUMN new_col1 bool,
                          ADD COLUMN new_col2 int references rt;

```

Fixes #7520.

(cherry picked from commit fdd658a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ALTER TABLE ADD COLUMN commands may cause crash.
3 participants