mysql - "set session" in a SQLAlchemy session object -


i'm using sqlalchemy project, , need able specify session variable/setting 1 specific call performance reasons:

set session max_heap_table_size = 1024 * 1024 * 64; 

i can of course in mysql directly (on shell), how set session variable in sqlalchemy session?

use session event execute arbitrary sql statement on each new transaction. can use events on connection level, depends on use case.

here how on session level:

session = sessionmaker() @event.listens_for(session, 'before_flush') def set_max_heap_table_size(session, transaction, connection):     session.execute('set max_heap_table_size = 1024 * 1024 * 64') 

if unsure way works you, try them, write test cases , find out if works you.

there may 1 caveat (unsure): since connection not dropped returned pool, setting might persist. in case might want attach restore default, e.g. on after_flush event. not entirely sure on one, might want experiment. if unnecessary, use after_begin event, there no real before_close event wraps it, create issues.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -