[Django] #16043: Specialization cache should be filled/shared with parent object cache (multitable inheritance)

10 views
Skip to first unread message

Django

unread,
May 17, 2011, 8:54:36 AM5/17/11
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
----------------------------+----------------------------------------------
Reporter: zimnyx | Owner: nobody
Type: | Status: new
Cleanup/optimization | Component: Database layer (models, ORM)
Milestone: | Severity: Normal
Version: SVN | Triage Stage: Unreviewed
Keywords: | Easy pickings: 0
Has patch: 0 |
----------------------------+----------------------------------------------
Here is some multi-table inheritance example:
{{{
class Owner(models.Model):
nick = models.CharField(max_length=100)

class Car(models.Model):
owner = models.ForeignKey(Owner)
some_id = models.CharField(max_length=100)

class MiniMorris(Car):
mini_type = models.CharField(max_length=1)

}}}

{{{

- model: auto.Owner
pk: 1
fields:
nick: Homer

- model: auto.Car
pk: 1
fields:
owner: 1
some_id: 'minii A'

- model: auto.MiniMorris
pk: 1
fields:
mini_type: 'e'
}}}

{{{
>>> c = Car.objects.select_related('owner').get(pk=1)
>>> # SELECT "auto_car"."id", "auto_car"."owner_id", "auto_car"."some_id",
"auto_owner"."id", "auto_owner"."nick" FROM "auto_car" INNER JOIN
"auto_owner" ON ("auto_car"."owner_id" = "auto_owner"."id") WHERE
"auto_car"."id" = 1

>>> c.owner
<Owner: Owner object>
>>> # No SQL, cache hit.

>>> m = c.minimorris
>>> # SELECT "auto_car"."id", "auto_car"."owner_id", "auto_car"."some_id",
"auto_minimorris"."car_ptr_id", "auto_minimorris"."mini_type" FROM
"auto_minimorris" INNER JOIN "auto_car" ON ("auto_minimorris"."car_ptr_id"
= "auto_car"."id") WHERE "auto_minimorris"."car_ptr_id" = 1
>>> # SQL is fine, we need to obtain this specialization

>>> m.owner
<Owner: Owner object>
>>> # SELECT "auto_owner"."id", "auto_owner"."nick" FROM "auto_owner"
WHERE "auto_owner"."id" = 1
>>> # Redundant SQL. This could be obtained from cache.

}}}

SQL issued by "m.owner" is redundant as owner is already cached in parent
object.

--
Ticket URL: <http://code.djangoproject.com/ticket/16043>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 31, 2011, 2:40:36 AM5/31/11
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
-------------------------------------+-------------------------------------
Reporter: zimnyx | Owner: nobody
Type: | Status: new
Cleanup/optimization | Component: Database layer
Milestone: | (models, ORM)
Version: SVN | Severity: Normal
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

This looks a lot like #15250, but it's not exactly the same bug. At least,
the patch currently available on #15250 does not fix this issue.

I'm attaching a test case in the form of a patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/16043#comment:1>

Django

unread,
Sep 21, 2013, 4:46:37 AM9/21/13
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
-------------------------------------+-------------------------------------

Reporter: zimnyx | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: master
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by aaugustin):

The issue still exists. However, it can be reproduced without
select_related. The problem is really in model inheritance. So the test
case I wrote two years ago is inappropriate.

--
Ticket URL: <https://code.djangoproject.com/ticket/16043#comment:3>

Django

unread,
Oct 9, 2015, 9:35:54 PM10/9/15
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
-------------------------------------+-------------------------------------

Reporter: zimnyx | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

#25173 seems to be a duplicate and also has a test.

--
Ticket URL: <https://code.djangoproject.com/ticket/16043#comment:4>

Django

unread,
Jun 2, 2016, 8:49:49 PM6/2/16
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
-------------------------------------+-------------------------------------
Reporter: zimnyx | Owner: czpython
Type: | Status: assigned

Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by czpython):

* owner: nobody => czpython
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/16043#comment:5>

Django

unread,
Jun 4, 2016, 8:53:57 PM6/4/16
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
-------------------------------------+-------------------------------------
Reporter: zimnyx | Owner: czpython
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by czpython):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/16043#comment:6>

Django

unread,
Jun 5, 2016, 1:00:15 AM6/5/16
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
-------------------------------------+-------------------------------------
Reporter: zimnyx | Owner: czpython
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by phildini):

I believe the PR czpython made for this ticket is
https://github.com/django/django/pull/6721.

--
Ticket URL: <https://code.djangoproject.com/ticket/16043#comment:7>

Django

unread,
Jun 5, 2016, 1:45:06 AM6/5/16
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
-------------------------------------+-------------------------------------
Reporter: zimnyx | Owner: czpython
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by czpython):

* has_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/16043#comment:8>

Django

unread,
Jun 5, 2016, 1:46:03 AM6/5/16
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
-------------------------------------+-------------------------------------
Reporter: zimnyx | Owner: czpython
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by czpython):

Removed the has patch set flag as PR 6721 is only the base for this.
The fix will be in a separate PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/16043#comment:9>

Django

unread,
Aug 10, 2017, 12:40:09 PM8/10/17
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
-------------------------------------+-------------------------------------
Reporter: Piotr Czachur | Owner: Paulo

Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"bfb746f983aa741afa3709794e70f1e0ab6040b5" bfb746f9]:
{{{
#!CommitTicketReference repository=""
revision="bfb746f983aa741afa3709794e70f1e0ab6040b5"
Refs #16043 -- Refactored internal fields value cache.

* Removed all hardcoded logic for _{fieldname}_cache.
* Added an internal API for interacting with the field values cache.

Thanks carljm and MarkusH for support.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/16043#comment:10>

Django

unread,
May 26, 2018, 6:40:46 PM5/26/18
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
-------------------------------------+-------------------------------------
Reporter: Piotr Czachur | Owner: Paulo
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Paulo):

* status: assigned => closed
* resolution: => fixed


--
Ticket URL: <https://code.djangoproject.com/ticket/16043#comment:11>

Django

unread,
May 26, 2018, 8:16:03 PM5/26/18
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
-------------------------------------+-------------------------------------
Reporter: Piotr Czachur | Owner: Paulo
Type: | Status: new
Cleanup/optimization |

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: closed => new
* resolution: fixed =>


Comment:

I think a regression test should be added before closing this ticket.

--
Ticket URL: <https://code.djangoproject.com/ticket/16043#comment:12>

Django

unread,
May 26, 2018, 8:23:07 PM5/26/18
to django-...@googlegroups.com
#16043: Specialization cache should be filled/shared with parent object cache
(multitable inheritance)
-------------------------------------+-------------------------------------
Reporter: Piotr Czachur | Owner: Paulo
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => fixed


Comment:

After investigation, I found that this was fixed by
78c5e7b90eee10067d39a8ba6588e6b53ba00d82 which did add an appropriate
test.

--
Ticket URL: <https://code.djangoproject.com/ticket/16043#comment:13>

Reply all
Reply to author
Forward
0 new messages