[Performance Issue]: fetchall is 3x slower with SQLAlchemy + duckdb_engine than DuckDB API #1179
Open
1 task done
Labels
bug
Something isn't working
What happened?
Switching from writing queries in raw SQL with DuckDB's API for execution to SQLAlchemy + duckdb_engine, I have found performance slowdowns of 3-50x.
For example:
This query using DuckDB runs at about 0.026s/query on average using random values for the parameterization.
I tried converting this to SQLAlchemy in the following manner:
print(stmt) gives:
Which appears to be functionally the same, but runs about 50x slower.
Even a simple select statement runs 3x slower compared with DuckDB's raw SQL (pasting the SQL output from printing the SQLAlchemy statement directly into conn.execute() for DuckDB). I timed it, and almost all the relative performance slowdown for simple selection appears to be on the fetch step.
Compiling the statement produced by SQLAlchemy into raw SQL and then executing and retrieving the result with DuckDB's conn.execute(sql) works quickly.
Please let me know if you think there's something I am missing here that's resulting in the performance hit. Despite this issue, duckdb_engine is great software and much appreciated - worst case scenario, compiling to raw SQL and running with DuckDB's native API for execution and fetching may work for my purposes.
Thank you!
DuckDB Engine Version
0.14.0
DuckDB Version
1.1.3
SQLAlchemy Version
2.0.36
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: