> For the complete documentation index, see [llms.txt](https://bamtech.gitbook.io/dev-standards/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bamtech.gitbook.io/dev-standards/performance/backend/output-sql-alchemy-orm-query.mo.md).

# output-sql-alchemy-orm-query.mo

## Owner: [Xavier Lefevre](https://github.com/xavierlefevre)

## Steps

If your performance issues seem to come from your SQL queries, you should take a look at the output of SQL Alchemy:

* Log/print the SQL Alchemy query:

  ```python
    logging.info(self.session.query(
        Revision.portfolio_id,
        func.max(Revision.valuation_date).label('max_date')
    ))
  ```
* Retrieve what's printed in your logs and format it: <https://sqlformat.org/>
* Test the query against the database to see how to optimize it
