> On Jun 7, 2022, at 5:46 AM, Trainer Go <[email protected]> wrote:
> 
> Hello guys,
> 
> Im executing 2 queries in my python program with sqlalchemy using the pyodbc 
> driver.
> The database is a Adaptive SQL Anywhere Version 7 32 Bit.
> 
> When im executing the queries in a DB UI it takes 5-6 seconds for both 
> together and when im using the same queries in my python programm it takes 
> 5-6 minutes instead of 6 seconds. What im doing wrong? Im new at this.

To start, debug one query at a time, not two.

Second, when you test a query in your DB UI, you’re probably already connected 
to the database. Your Python program has to make the connection — that’s an 
extra step, and it might be slow. If you step through the Python program in the 
debugger, you can execute one statement at a time (the connection and the 
query) to understand how long each step takes. That will help to isolate the 
problem.

Third, keep in mind that receiving results takes time too. If your DB UI is 
written in C or some other language that allocates memory very efficiently, it 
might be a lot faster than building a Pandas dataframe. 

You might want to eliminate Pandas entirely so you don’t have to question 
whether or not that’s the source of your slowdown. You could do this instead -

for row in conn.execute(my_query).fetchall():
    pass

That will force your Python program to iterate over the result set without 
being forced to allocate memory for all the results.

Hope this helps
Philip






> 
> would the connection string or query help?
> And i only selecting some datas from the db and converting it into two 
> dataframes so i dont inserting, updating or deleting datas.
> 
> I hope somebody can help me.
> 
> Best regards Manuel
> 
> -- 
> SQLAlchemy - 
> The Python SQL Toolkit and Object Relational Mapper
>  
> http://www.sqlalchemy.org/
>  
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/b306121e-913c-4ca5-bc2d-6308d76d1b76n%40googlegroups.com.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/8BD49EC5-8C61-42C4-A363-C5ED7278BD7D%40americanefficient.com.

Reply via email to