Performance delta between execute and executemany #300
Replies: 2 comments 2 replies
-
Both python-oracledb and cx_Oracle use the same approach, and yes, calling execute() 1000 times will take considerably longer than calling executemany() with 1000 rows. Each call to execute() requires a round trip whereas executemany() only requires one round trip. This has not changed! For performance reasons you should definitely use executemany()! |
Beta Was this translation helpful? Give feedback.
-
Is the round-trip simply due to actually executing the statement, or is there overhead due to getting metadata, etc.? If the former, then the numbers are a bit puzzling, because this code is being executed over a fast network. |
Beta Was this translation helpful? Give feedback.
-
We noticed a huge performance delta between inserting using
execute
andexecutemany
. Details are:We are inserting 8900 rows into a table that has no indices and no constraints. After reading the data into a Python dictionary, we execute an insert in a loop using a statement of the form
The simplified code is:
Running this code on 8913 records took ~10 minutes.
We attempted to improve the performance by:
cursor.prepare()
. This did not helpexecutemany()
instead ofexecute()
and pass in 1000 records at a time toexecutemany
. This dropped the time from 10 minutes to 6 seconds.We're preparing a test case to attach to an issue, but we can't figure out where the time is going. Our best guess is that the driver is doing round trips to the DB on every call of
execute()
but we can't figure out why. We didn't experience this kind of issue when usingcx-oracle
.This is a general-purpose utility (i.e.,, the INSERT statement gets generated dynamically). Using
setinputsizes
would be kind of painful. It would be equally painful to usesetinputsizes
elsewhere in the code. It seems like this is something that the driver should do automatically on the first invocation and then cache with the cursor.Or am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions