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

PG17 - Add tests for MERGE ... WHEN NOT MATCHED BY SOURCE #7807

Merged
merged 6 commits into from
Jan 8, 2025

Conversation

naisila
Copy link
Member

@naisila naisila commented Dec 25, 2024

DESCRIPTION: Propagates MERGE ... WHEN NOT MATCHED BY SOURCE

It seems like there is not much needed to be done here. get_merge_query_def from ruleutils_17 is updated with "WHEN NOT MATCHED BY SOURCE" therefore deparse_shard_query parses the merge query for execution on the shard correctly.

Relevant PG commit: postgres/postgres@0294df2f1

Copy link

codecov bot commented Dec 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (release-13.0@32c058e). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff               @@
##             release-13.0    #7807   +/-   ##
===============================================
  Coverage                ?   89.50%           
===============================================
  Files                   ?      274           
  Lines                   ?    59989           
  Branches                ?     7506           
===============================================
  Hits                    ?    53695           
  Misses                  ?     4156           
  Partials                ?     2138           

@@ -1547,7 +1547,8 @@ FetchAndValidateInsertVarIfExists(Oid targetRelationId, Query *query)
}

/* NOT MATCHED can have either INSERT or DO NOTHING */
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's combine both the comments into one

ON t.tid = s.sid
WHEN MATCHED THEN
UPDATE SET balance = balance + delta, val = val || ' updated by merge'
WHEN NOT MATCHED THEN
Copy link
Contributor

@colm-mchugh colm-mchugh Jan 3, 2025

Choose a reason for hiding this comment

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

The PG17 commit (0294df2f1) also adds WHEN NOT MATCHED BY TARGET as an optional way to specify the already-supported WHEN NOT MATCHED, so let's check that Citus treats this correctly ? I.e., WHEN NOT MATCHED BY TARGET should have the same behavior as WHEN NOT MATCHED. So how about changing some of the WHEN NOT MATCHED THEN clauses to WHEN NOT MATCHED BY TARGET THEN ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, will do

INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source';

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the MERGE statements here are all have router plans ? (so they take the CreateRouterMergePlan() codepath in merge_planner.c). If so, how about adding some MERGE statements that require repartitioning (take the CreateNonPushableMergePlan() codepath in merge_planner.c) ? Regress test merge.sql has some examples (there's a couple of queries that have a comment "with repartition") and there's also an example in the docs on Merge (see "Exploring MERGE in Complex Scenarios") that might help in constructing a test with the schema here.

This (router vs repartition plan) may be an orthogonal concern, but I thought it was worth mentioning.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Colm, definitely worth mentioning. I should test this in my local first, I am not sure if there are any issues with it.

Copy link
Contributor

@colm-mchugh colm-mchugh left a comment

Choose a reason for hiding this comment

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

Lgtm, thanks for adding the additional tests. It basically "just works", as you state in the PR comment, thanks to the ruleutils API.

@naisila naisila merged commit 3e924db into release-13.0 Jan 8, 2025
153 checks passed
@naisila naisila deleted the naisila/merge branch January 8, 2025 21:03
naisila added a commit that referenced this pull request Mar 11, 2025
DESCRIPTION: Propagates MERGE ... WHEN NOT MATCHED BY SOURCE

It seems like there is not much needed to be done here.
`get_merge_query_def` from `ruleutils_17` is updated with "WHEN NOT
MATCHED BY SOURCE" therefore `deparse_shard_query` parses the merge
query for execution on the shard correctly.

Relevant PG commit:
postgres/postgres@0294df2f1
naisila added a commit that referenced this pull request Mar 12, 2025
DESCRIPTION: Propagates MERGE ... WHEN NOT MATCHED BY SOURCE

It seems like there is not much needed to be done here.
`get_merge_query_def` from `ruleutils_17` is updated with "WHEN NOT
MATCHED BY SOURCE" therefore `deparse_shard_query` parses the merge
query for execution on the shard correctly.

Relevant PG commit:
postgres/postgres@0294df2f1
naisila added a commit that referenced this pull request Mar 12, 2025
DESCRIPTION: Propagates MERGE ... WHEN NOT MATCHED BY SOURCE

It seems like there is not much needed to be done here.
`get_merge_query_def` from `ruleutils_17` is updated with "WHEN NOT
MATCHED BY SOURCE" therefore `deparse_shard_query` parses the merge
query for execution on the shard correctly.

Relevant PG commit:
postgres/postgres@0294df2f1
naisila added a commit that referenced this pull request Mar 12, 2025
DESCRIPTION: Propagates MERGE ... WHEN NOT MATCHED BY SOURCE

It seems like there is not much needed to be done here.
`get_merge_query_def` from `ruleutils_17` is updated with "WHEN NOT
MATCHED BY SOURCE" therefore `deparse_shard_query` parses the merge
query for execution on the shard correctly.

Relevant PG commit:
postgres/postgres@0294df2f1
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.

3 participants