Opened 7 months ago

Last modified 5 months ago

#35334 assigned Cleanup/optimization

Update Oracle backend supports_sequence_reset = True

Reported by: David Sanders Owned by: Anmol Multani
Component: Database layer (models, ORM) Version: 5.0
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The Oracle backend currently specifies supports_sequence_reset = False. It looks as though it's been this way since the flag was added to the Oracle backend since https://github.com/django/django/commit/0df4593f0ed.

This commit appears to have been for the 1.5 release [1] which was released in Feb 2013. A few months later Oracle 12.1 [2] was released in July 2013. It's quite hard to determine when ALTER SEQUENCE … RESTART support was introduced but from some pain-staking searching I found that apparently 12.1 included support for it but it wasn't documented until 18c [3]:

There is a new option for altering a sequence that appeared in 12.1 but was not documented until 18c:
alter SEQUENCE [schema_name.]{sequence_name} restart;

[1] https://docs.djangoproject.com/en/5.0/releases/1.5/
[2] https://en.wikipedia.org/wiki/Oracle_Database#Releases_and_versions
[3] https://www.red-gate.com/simple-talk/databases/oracle-databases/oracle-sequences-12c-features-including-identity/

Change History (3)

comment:1 by Simon Charette, 7 months ago

Triage Stage: UnreviewedAccepted

comment:2 by David Sanders, 7 months ago

Interestingly someone's already added the required sequence reset methods to db.backends.oracle.operations.DatabaseOperations to support flushing: https://github.com/django/django/blob/d658a3162fbeb68d148d1b2fcf4da4fe1437eddb/django/db/backends/oracle/operations.py#L526

The Oracle attribute DatabaseOperations.__sequence_reset_sql(), which uses a PL/SQL block, appears to have origins way back to 2007 when it was first added as _get_sequence_reset_sql()

It looks like that could be simplified to use the ALTER syntax?

Last edited 7 months ago by David Sanders (previous) (diff)

comment:3 by Anmol Multani, 5 months ago

Owner: changed from nobody to Anmol Multani
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top