Opened 5 years ago
Closed 5 years ago
#31473 closed Cleanup/optimization (fixed)
Use PostgreSQL TRUNCATE … RESTART IDENTITY keyword to reset sequences in sql_flush()
Reported by: | Jon Dufresne | Owned by: | Jon Dufresne |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Rather than executing an additional query per truncated table, can truncate and reset sequences in a single query by using the RESTART IDENTITY
syntax.
My project uses the sql_flush()
operation internally and profiling shows that it can consume a large percentage of the runtime. Reducing the number of queries to one should help provide a small performance improvement.
Change History (4)
comment:1 by , 5 years ago
Has patch: | set |
---|
comment:2 by , 5 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
https://github.com/django/django/pull/12733