Hello,
given an SQLAlchemy engine `con` (cx_oracle dialect) and a moderately
complex SQLAlchemy selectable object `sql`, the following code will
consistently take ~15 seconds:
con.execute(sql).fetchall()
Whereas with the exact same engine and query the following code will only
take a fraction of a second:
compiled = sql.compile(dialect=con.dialect)
statement = compiled.string
params = compiled.params
con.execute(statement, params).fetchall()
So, apparently something goes horribly wrong when executing an selectable.
I assume that there is something wrong on my side as a general error in
SQLAlchemy in this regard would probably have been noticed. However: How do
I even debug this? In the end, I did trace the problem down to the `
do_execute` function in engine.default:
def do_execute(self, cursor, statement, parameters, context=None):
cursor.execute(statement, parameters)
Both of my code examples visit this line of code with the exact same values
for `statement` and `parameters`, though the way they get there is slightly
different and so are the `cursor` and `context` objects. When I try to step
further down in the debugger, the next frame would be `output_type_handler`
in dialects.oracle.cx_oracle. However, the time is already lost before
stepping into that function. That is, just entering this frame takes ~15
seconds in my first code but is near instantaneous in my second code.
I do not really know how to continue debugging from this point. Anybody
have any advice or any ideas what might be going on here? The only
difference that looks even remotely relevant to me at that point is that
within the `context` we have a value for `context.compiled` for the first
code and None for the second code. I tried setting it to None in the
debugger but that had no effect on the execution speed. The cursors look
both the same to me in both codes.
At this point I do not even know what else to look for and would appreciate
any advice how to proceed. After not finding anything in the local context
I would assume the problem is somewhere in some global state but without
intimate knowledge of the inner working of SQLAlchemy I don't think I will
be able to find the root cause.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/b6c933f0-5ad5-468d-ba15-ba49e9c3fb55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.