[Django] #30122: Add index in object_id column in LogEntry table to make fetch query faster.

16 views
Skip to first unread message

Django

unread,
Jan 22, 2019, 11:52:22 AM1/22/19
to django-...@googlegroups.com
#30122: Add index in object_id column in LogEntry table to make fetch query faster.
------------------------------------------------+------------------------
Reporter: Shashank Parekh | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
------------------------------------------------+------------------------
In **''history_view''** function, we use ''object_id'' and
''content_type'' to fetch the logs. Usually, we will have lots of entries
based on ''content_type'' compare with ''object_id''.

It is ideal to index ''object_id'' to make fetch query faster.

I can work on this task.

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

Django

unread,
Jan 23, 2019, 2:47:21 AM1/23/19
to django-...@googlegroups.com
#30122: Add index in object_id column in LogEntry table to make fetch query faster.
-------------------------------------+-------------------------------------

Reporter: Shashank Parekh | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

Hi Shashank.

Without really looking, this ''seems'' reasonable.

What's the query being generated? Is that using a table scan? If so,
you're just talking about adding an index right?

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

Django

unread,
Jan 23, 2019, 12:05:05 PM1/23/19
to django-...@googlegroups.com
#30122: Add index in object_id column in LogEntry table to make fetch query faster.
-------------------------------------+-------------------------------------

Reporter: Shashank Parekh | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

If we decide to add an index we should consider a composite
`(content_type_id, object_id)` one and maybe make the `content_type`
foreign key `db_index=False` given there's no use case for querying
`LogEntry` by `object_id` without `content_type_id` and that most (if not
all) supported database engines are able to use the first parts of a
composite index rendering the `content_type_id` index useless.

--
Ticket URL: <https://code.djangoproject.com/ticket/30122#comment:2>

Django

unread,
Jan 23, 2019, 12:18:46 PM1/23/19
to django-...@googlegroups.com
#30122: Add index in object_id column in LogEntry table to make fetch query faster.
-------------------------------------+-------------------------------------

Reporter: Shashank Parekh | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

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

* easy: 1 => 0


Comment:

Seems related to #23435: "GenericForeignKey should be indexed".

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

Django

unread,
Jan 24, 2019, 2:56:21 AM1/24/19
to django-...@googlegroups.com
#30122: Add index in object_id column in LogEntry table to make fetch query faster.
-------------------------------------+-------------------------------------

Reporter: Shashank Parekh | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

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

Comment (by Claude Paroz):

I think this is a duplicate of #17659 (blocked because `object_id` is a
`TextField` currently unindexable on MySQL). See also #28661.

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

Django

unread,
Jan 24, 2019, 12:31:45 PM1/24/19
to django-...@googlegroups.com
#30122: Add index in object_id column in LogEntry table to make fetch query faster.
-------------------------------------+-------------------------------------

Reporter: Shashank Parekh | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage:
| Unreviewed
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: => duplicate


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

Reply all
Reply to author
Forward
0 new messages