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

Ensure validation of partitioned by columns in the insert from subquery #14317

Closed
wants to merge 7 commits into from

Conversation

BaurzhanSakhariev
Copy link
Contributor

@BaurzhanSakhariev BaurzhanSakhariev commented Jun 26, 2023

Relates to #14304 (fixes some other bugs as well)

Supersedes #14305

Comment on lines -178 to 179
return NestableCollectExpression.constant(val);
return NestableCollectExpression.constant(ref.valueType().implicitCast(val));
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise scalar function representing CHECK fails with "left and right must have the same type for comparison"

@BaurzhanSakhariev BaurzhanSakhariev changed the title WIP: Fix check constraint validation of partitioned by column in the insert from subquery Ensure validation of partitioned by columns in the insert from subquery Jun 26, 2023
@BaurzhanSakhariev BaurzhanSakhariev marked this pull request as ready for review June 26, 2023 14:18

// Partitioned by columns are not included into target columns in the insert-from-subquery code path.
// Ensure that column constraints are checked for partitioned columns as well.
for (int i = 0; i < table.partitionedByColumns().size(); i++) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be surrounded by if (partitionName != null)?

Copy link
Member

@seut seut Jun 26, 2023

Choose a reason for hiding this comment

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

Isn't the partition already created at this point? If so, bailing out here will leave an invalid partition behind. I think we are forced to do such checks on partition creation instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks! I added an assertion to the test about non-existing index and it fails now. Will move the check to the earlier phase.

@mfussenegger
Copy link
Member

Maybe worth double checking that the update integration of the indexer plays well with this too?
(I think it should, because update rewrites to insert, but just to be sure)

@BaurzhanSakhariev BaurzhanSakhariev marked this pull request as draft July 3, 2023 09:32
@BaurzhanSakhariev BaurzhanSakhariev force-pushed the b/parted-cols-bugs-fix branch 6 times, most recently from 316c6b7 to 39aca9e Compare July 5, 2023 07:15
@BaurzhanSakhariev BaurzhanSakhariev marked this pull request as ready for review July 5, 2023 09:31
@BaurzhanSakhariev
Copy link
Contributor Author

BaurzhanSakhariev commented Jul 5, 2023

Maybe worth double checking that the update integration of the indexer plays well with this too?
(I think it should, because update rewrites to insert, but just to be sure)

I tried to replicate problematic queries on UPDATE code path via ON CONFLICT() DO UPDATE SET but it looks to me, that such scenarios (on parted columns) are invalid anyway because:

  1. issues are about parted cols
  2. on conflict wants primary key
  3. if we have parted cols, we have to make them primary keys
  4. parted cols == primary keys cannot be updated
    See a6bea6e

@BaurzhanSakhariev BaurzhanSakhariev marked this pull request as draft July 5, 2023 10:38
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.

None yet

3 participants