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

MERGE on distributed tables gives incorrect result #6674

Closed
marcocitus opened this issue Jan 30, 2023 · 2 comments
Closed

MERGE on distributed tables gives incorrect result #6674

marcocitus opened this issue Jan 30, 2023 · 2 comments
Assignees

Comments

@marcocitus
Copy link
Member

I think it's not correct to do any kind of pruning based on an ON clause condition, because the source is the outer table of the outer join.

drop table if exists source, target;

create table source (                                                                   
    id   integer, z int
);
create table target (
    id   integer, z int 
);
insert into source values (1,2);
insert into source values (3,4);

merge into target sda
using source sdn
on sda.id = sdn.id AND sda.id = 1
when not matched then
  insert (id, z)
  values (sdn.id, 5);

select * from target;
┌────┬───┐
│ id │ z │
├────┼───┤
│  15 │
│  35 │
└────┴───┘
(2 rows)

truncate target;
select create_distributed_table('target','id'), create_distributed_table('source', 'id');


merge into target sda
using source sdn
on sda.id = sdn.id AND sda.id = 1
when not matched then
  insert (id, z)
  values (sdn.id, 5);

-- missing rows
select * from target;
┌────┬───┐
│ id │ z │
├────┼───┤
│  15 │
└────┴───┘
(1 row)
@tejeswarm
Copy link
Contributor

tejeswarm commented Jan 30, 2023

This is a bit of an oddity or expected behavior which I was planning to document as a cautionary note (only for this phase II). In your test case, id 3 is not inserted because we generate single-shard task, id-3 is not part of the shard we routed the query to, hence it never appears in the target. I knew this behavior before, ideally for phase II, the NON MATCHED should have DO NOTHING in Citus, else it's hard to interpret the results for MERGE.
 
 In your test, if we change
insert into source values (3,4)
to
insert into source values (5,4)
it will match the expected PG result

@tejeswarm
Copy link
Contributor

Fixed in PR #6696

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

2 participants