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 suggested join condition when joining 2 models #41202

Closed
lbrdnk opened this issue Apr 9, 2024 · 0 comments · Fixed by #41274
Closed

Wrong suggested join condition when joining 2 models #41202

lbrdnk opened this issue Apr 9, 2024 · 0 comments · Fixed by #41274
Assignees
Labels
Priority:P3 Cosmetic bugs, minor bugs with a clear workaround .Team/QueryProcessor :hammer_and_wrench: Type:Bug Product defects
Milestone

Comments

@lbrdnk
Copy link
Contributor

lbrdnk commented Apr 9, 2024

There is a case where wrong join condition is suggested while joining 2 models. More context can be found in this slack thread. Steps to reproduce follow.

  1. Use the following sql to create a postgres database:
create table organization (
    id serial primary key,
    account_id int
);

create table account (
    id serial primary key,
    organization_id int
);

create table contact (
    id serial primary key,
    organization_id int
);

alter table
    organization
add
    constraint fk_account foreign key (account_id) references account(id);

alter table
    account
add
    constraint fk_organization foreign key (organization_id) references organization(id);

alter table
    contact
add
    constraint fk_organization foreign key (organization_id) references organization(id);

insert into organization (account_id) values (NULL);
insert into account (organization_id) values (1);
insert into contact (organization_id) values (1);
update organization set account_id = 1 where id = 1;
  1. Add that database and use it as data source for next steps.

  2. Now create model Account model from plain mbql query with source Account.

  3. Create model Contact model from plain mbql query with source Contact.

  4. Now create a new mbql query with source Account model.

  5. Attempt to join Contact model in query builder.

Wrong join condition is suggested: only table Organization has column account_id. (Aside: both other tables have foreign keys to that table.)

Screen of incorrect join condition:

Screenshot 2024-04-09 at 19 25 48
@lbrdnk lbrdnk added Type:Bug Product defects Priority:P3 Cosmetic bugs, minor bugs with a clear workaround .Team/QueryProcessor :hammer_and_wrench: labels Apr 9, 2024
@lbrdnk lbrdnk self-assigned this Apr 9, 2024
@crisptrutski crisptrutski added this to the 0.49.6 milestone Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:P3 Cosmetic bugs, minor bugs with a clear workaround .Team/QueryProcessor :hammer_and_wrench: Type:Bug Product defects
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants