当前位置: 动力学知识库 > 问答 > 编程问答 >

python - How can I use SQLAlchemy to do "mysql explain"

问题描述:

I have a sql like:

DBSession().query(Model).filter(***)

and I want to explain this sql using SQLAlchemy.

网友答案:

Your filter call can be turned into a string:

query = str(DBSession().query(Model).filter(***))

You can then use that to ask for a MySQL explanation:

DBSession().execute('EXPLAIN ' + query)

You may have to include any bound parameters the filters added to your query as a dictionary:

DBSession().execute('EXPLAIN ' + query, {'param_1': 'value1', 'param_2': 'value2'})
分享给朋友:
您可能感兴趣的文章:
随机阅读: