Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #16715 -- Fixed join promotion logic for nested nullable FKs
The joins for nested nullable foreign keys were often created as INNER when they should have been OUTER joins. The reason was that only the first join in the chain was promoted correctly. There were also issues with select_related etc. The basic structure for this problem was: A -[nullable]-> B -[nonnull]-> C And the basic problem was that the A->B join was correctly LOUTER, the B->C join not. The major change taken in this patch is that now if we promote a join A->B, we will automatically promote joins B->X for all X in the query. Also, we now make sure there aren't ever join chains like: a LOUTER b INNER c If the a -> b needs to be LOUTER, then the INNER at the end of the chain will cancel the LOUTER join and we have a broken query. Sebastian reported this problem and did also major portions of the patch.
- Loading branch information
Showing
5 changed files
with
246 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.db import models | ||
|
||
|
||
class Person(models.Model): | ||
name = models.CharField(max_length=200) | ||
|
||
|
||
class Movie(models.Model): | ||
title = models.CharField(max_length=200) | ||
director = models.ForeignKey(Person) | ||
|
||
|
||
class Event(models.Model): | ||
pass | ||
|
||
|
||
class Screening(Event): | ||
movie = models.ForeignKey(Movie) | ||
|
||
class ScreeningNullFK(Event): | ||
movie = models.ForeignKey(Movie, null=True) | ||
|
||
|
||
class Package(models.Model): | ||
screening = models.ForeignKey(Screening, null=True) | ||
|
||
class PackageNullFK(models.Model): | ||
screening = models.ForeignKey(ScreeningNullFK, null=True) |
Oops, something went wrong.