#24200 closed Cleanup/optimization (fixed)
Make introspection bypass statement caching on Oracle
Reported by: | Shai Berger | Owned by: | Josh Smeaton |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.8alpha1 |
Severity: | Normal | Keywords: | oracle introspection |
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
This comes from looking at the Oracle errors encountered in the initial fix for #24163.
The Django Oracle backend currently uses a statement cache. This means that if a statement is re-executed (soon enough after the previous execution), a compiled statement is fetched from the cache and performance is greatly improved.
However, this causes problems with introspection during migrations; a compiled select * from T
statement embeds in it the structure of table T
, and if a column is dropped, then a cached select * from T
will fail on "ORA-01007: variable not in select list". This is actually what happens -- get_table_description on Oracle uses a select * from T
query.
We have run into the problem in the past, but haven't understood it properly; so we introduced a workaround of disconnecting from the database after relevant schema changes, and a database feature connection_persists_old_columns
to control its use. But in fact, simple cache-busting (e.g. rephrasing the query as select * from %(table)s where 0 > %(counter)d
with counter advancing each time) should solve the problem and make the disconnection, as well as the database feature, redundant.
I think this fix should go also into 1.8, but definitely into master.
Change History (10)
comment:1 by , 10 years ago
comment:3 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 10 years ago
The flush shared_pool just flushes server side statements AFAIK, and doesn't work with the recommended privileges (you need system-like privs).
comment:5 by , 10 years ago
Is this something that we want to include for 1.8, or is this going to be targeting master? I'll put together a patch for it within the next few days if inclusion for 1.8 is the goal.
comment:6 by , 10 years ago
You have until the beta release to submit non-release blocker bug fixes of which this seems to fall into.
comment:8 by , 10 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Triage Stage: | Accepted → Ready for checkin |
https://github.com/django/django/pull/4101/
New PR implementing Shai's original proposal which turned out to be a much better idea.
comment:9 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I don't think we need to get too crazy with regards to cache busting. Simply setting the stmtcachesize to 0 and back to 20 clears the cache. We could also try to request a connection with caching disabled for migrations.