Skip to content

One-to-many queries join the same tables twice #216

Closed
@molexx

Description

@molexx

The StarwarsQueryExecutorTests.queryOneToManyJoinByID test looks like this:

query { 
  Humans(where:{id:{EQ: "1000"}}) {
    select {
      name, homePlanet, friends { name } 
    }
  }
}

and executes the following SQL:

    select
        human0_.id as id2_7_0_,
        character2_.id as id2_7_1_,
        character4_.id as id2_7_2_,
        human0_.name as name3_7_0_,
        human0_.favorite_droid_id as favorite6_7_0_,
        human0_.gender_code_id as gender_c7_7_0_,
        human0_.home_planet as home_pla4_7_0_,
        character2_.name as name3_7_1_,
        character2_.primary_function as primary_5_7_1_,
        character2_.favorite_droid_id as favorite6_7_1_,
        character2_.gender_code_id as gender_c7_7_1_,
        character2_.home_planet as home_pla4_7_1_,
        character2_.dtype as dtype1_7_1_,
        friends1_.source_id as source_i1_9_0__,
        friends1_.friend_id as friend_i2_9_0__,
        character4_.name as name3_7_2_,
        character4_.primary_function as primary_5_7_2_,
        character4_.favorite_droid_id as favorite6_7_2_,
        character4_.gender_code_id as gender_c7_7_2_,
        character4_.home_planet as home_pla4_7_2_,
        character4_.dtype as dtype1_7_2_,
        friends3_.source_id as source_i1_9_1__,
        friends3_.friend_id as friend_i2_9_1__ 
    from
        character human0_ 
    left outer join
        character_friends friends1_ 
            on human0_.id=friends1_.source_id 
    left outer join
        character character2_ 
            on friends1_.friend_id=character2_.id 
    left outer join
        character_friends friends3_ 
            on human0_.id=friends3_.source_id 
    left outer join
        character character4_ 
            on friends3_.friend_id=character4_.id 
    where
        human0_.dtype='Human' 
        and human0_.id=? 
    order by
        human0_.id asc,
        character2_.name asc,
        character4_.name asc

It seems that the joins to friends3_ and character4_ duplicate the joins to friends1_ and character2_ and are unnecessary?

This is tested using commit 0151eec from master which includes the fix for #198 .

Removing the where id=1000 clause makes no difference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions