I am trying to insert about 600 entries. I am using ORM, but after investigation and according to the docs, core seems to be the fastest one.
This is my implementation, and it's takingnearly 58 seconds to do the insert. Per docs SQLAlchemy Core: Total time for 100000 records 0.206904888153 secs
This is my implementation:
def bulk_insert_objects(self, simulation, default_mechanism, model, skus):
t0 = time.time()
table = inspect(model).local_table
self.session.execute(
table.insert(),
[
dict(
simulation_id=simulation.simulation_id,
product_id=i['product_id'],
store_level_2_id=i['store_level_2_id'],
data=default_mechanism,
)
for i in skus
],
)
print(
"SQLAlchemy Core: Total time for " + str(len(skus)) +
" records " + str(time.time() - t0) + " secs")
Total length of skus is 600.
My terminal looks like this, it performs INSERT INTO correctly, it takes a long time to finish that operation.
INFO sqlalchemy.engine.base.Engine INSERT INTO pricing.simulation_skus (simulation_id, product_id, data) VALUES (%(simulation_id)s, %(product_id)s, %(data)s)
2021-03-31 12:58:49,393 INFO sqlalchemy.engine.base.Engine ({'simulation_id': 185, 'product_id': 3859, 'data': '{"mechanism_cd": "dollar_amount"}'}, {'simulation_id': 185, 'product_id': 3859, 'data': '{"mechanism_cd": "dollar_amount"}'}, {'simulation_id': 185, 'product_id': 3859, 'data': '{"mechanism_cd": "dollar_amount"}'}, {'simulation_id': 185, 'product_id': 3859, 'data': '{"mechanism_cd": "dollar_amount"}'}, {'simulation_id': 185, 'product_id': 3859, 'data': '{"mechanism_cd": "dollar_amount"}'}, {'simulation_id': 185, 'product_id': 3859, 'data': '{"mechanism_cd": "dollar_amount"}'}, {'simulation_id': 185, 'product_id': 3859, 'data': '{"mechanism_cd": "dollar_amount"}'}, {'simulation_id': 185, 'product_id': 3861, 'data': '{"mechanism_cd": "dollar_amount"}'} ... displaying 10 of 630 total bound parameter sets ... {'simulation_id': 185, 'product_id': 723605, 'data': '{"mechanism_cd": "dollar_amount"}'}, {'simulation_id': 185, 'product_id': 723605, 'data': '{"mechanism_cd": "dollar_amount"}'})
After 58ish second, it finally completes.