is truncate happening in some other process? does it speed up once you kill the initial python process? does this truncate take time with other kinds of INSERT statements? is the table very large? overall you need to perform more observations here as to what conditions cause this "truncate" to take a lot of time. there's nothing happening in SQLAlchemy that affects this much, particularly for MySQL which is not very aggressive about locking tables.
On Wednesday, December 14, 2022 at 12:19:53 AM UTC-5 chandra...@gmail.com wrote: > I tried this, kept commit and close statements and removed dispose > statement, but yet the problem is not solved, it's taking time to truncate > the table. > > On Wednesday, 14 December 2022 at 05:19:27 UTC+5:30 yaakovb...@gmail.com > wrote: > >> Is it possible your sessions hasn't committed the change / closed the >> transaction? >> >> Also, I don't think dispose is helping you here. Consider removing it? >> >> How about modifying: >> >> def add_user(): >> session = Session() >> session.add(User(**{'user_id': 1, 'name': 'user name'})) >> session.commit() >> session.close() >> # consider removing >> # session.bind.dispose() >> >> >> On Tuesday, December 13, 2022 at 8:13:14 AM UTC-5 chandra...@gmail.com >> wrote: >> >>> On creating all tables using alembic for migrations and then truncate >>> any empty table gets completed quickly, BUT once lambda function is >>> triggered to insert some data in a table through SQLAlchemy ORM Session >>> query (as given below) and then truncate the table takes very much time. >>> Where is the problem? >>> >>> ``` >>> from sqlalchemy import create_engine >>> from sqlalchemy.orm import sessionmaker >>> >>> engine = create_engine("mysql+pymysql://....") >>> Session = sessionmaker(bind=engine) >>> >>> def add_user(): >>> session = Session() >>> session.add(User(**{'user_id': 1, 'name': 'user name'})) >>> session.close() >>> session.bind.dispose() >>> >>> ``` >>> >> -- 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 sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/d1c8298d-d7f2-4686-8ba7-26fb162994c9n%40googlegroups.com.