Opened 13 years ago
Closed 13 years ago
#16427 closed New feature (wontfix)
truncate table method in ORM
Reported by: | Adam Nelson | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In the interest of having a more complete ORM, there should be a truncate table command available. This could be used in specialized cases where the user needs to delete very large tables (i.e. migrations on volatile tables, tables with data that gets purged regularly, etc...)
Change History (3)
comment:1 by , 13 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:2 by , 13 years ago
The solution to the sqlite issue is simply to do "DELETE table_name" for that backend when calling the truncate() method.
Sybase claims that TRUNCATE is SQL-92 compliant as part of the Transact-SQL extension.
The problem with the delete() method is that it's exceedingly slow. On tables with more than 1M records, DELETE can take up to 10 minutes to run compared to seconds to truncate - with the same outcome.
comment:3 by , 13 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
wontfixing, for the reasons aaugustin gave. If delete() is too slow use manual SQL truncate. https://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly . For specialised needs, this is good enough, and it's not hard to get the db table name for a model.
As far as I can tell,
TRUNCATE
is not part of SQL-92, and it isn't implemented by sqlite, so it isn't a good candidate for ORM support.What's wrong with
MyModel.objects.delete()
? At least sqlite will optimize this by performing a truncate. I don't know very well the internal of other database engines, but they may optimize it too.Finally, you can use raw SQL.
I'm leaning towards "wontfix", but let's wait for a core developer's opinion,