the exact SQL here is some crap the MSSQL dialect has in do_begin() which
is the only way we could find to get SAVEPOINT to work.
However, even if this were removed, a new connection is in fact started
the first time you use a freshly checked out connection. Connections
returned to the pool have rollback() called unconditionally. The reasons
are straightforward - a newly checked out connection should act just like
a brand new one - no locks, no transactional state. a checked-in
connection needs to act like a "closed" one in that it isnt hanging onto
any locks.
>
> Ideally, our connection pool should provide connections without any
> transactions active and in unchained mode (@@trancount = 0,
> @@transtate = 1, @@tranchained = 0). The checkin code can rollback if
> @@trancount > 0.
>
> What is the suggested configuration to achieve this?
SQLAlchemy assumes autocommit=False which is per DBAPI spec (and note that
autocommit=False requires that a transaction is present). There is always
a transaction, and in fact this has nothing to do with SQLA - just use
pyodbc directly and you will see this is the case.
Some DBAPI's provide autocommit modes, but since these are not
standardized or universally available, and because SQLA has its own
"autocommit" that works very nicely and consistently, SQLA has no support
for them. I dont know what Pyodbc provides.
note however that this is not to say you can't add a connect hook to your
pool (using PoolListener) and set the pyodbc connections into "autocommit"
mode, if you identify such an option. as far as the conditional shoved
into do_begin() I still think we should just flatly deny SAVEPOINT support
on MSSQL for now which would obviate the need for that statement.
>
> Thanks for the information Mike. I do have a listener in place already
> but decided to poke in the configuration directly when creating the
> engine:
>
> 'connect_args' : {'autocommit' : True,
> }
>
> I found some very interesting results by experimenting with vanilla
> pyodbc and SA and seeing how they impacted the Sybase transaction log.
> Two transaction log IOs *per query* (one for BEGINXACT and one for
> ENDXACT) would have devastating performance impact. However, it seems
> that these are taken care of by the Sybase User Log Cache (ULC) (or
> some other as yet unknown mechanism) otherwise we would surely have
> noticed their impact.
>
> I will do some more testing on this tomorrow and followup with a
> summary. Auto-wrapping SA models over several thousand tables across
> hundreds of databases across dozens of dataservers has certainly
> brought up some interesting stuff!
oh, sybase. Youre using MSSQL dialect to talk to both huh ? :)
interesting do you think sybase and MSSQL should inherit from some
common base ? not surprising you're having probs with that.