-
Notifications
You must be signed in to change notification settings - Fork 364
Description
Details
We are experiencing a linear time complexity when returning larger query-sets (anything over 10k rows). To eliminate all possible factors stemming from table structure and/or query complexity, I ended up creating a row generator which unfortunately suffers the same fate, but demonstrates the problem nicely.
The following query takes about 2 minutes to complete for 100k rows when executed in terminal:
import cx_Oracle
conn = cx_Oracle.connect('admin/{password}@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SID=ORCL)))')
cur = conn.cursor()
cur.arraysize = 500
raw = """
WITH data(r) AS (
SELECT 1 r FROM dual
UNION ALL
SELECT r+1 FROM data WHERE r < 100000)
SELECT r FROM data
"""
cur.execute(raw).fetchall()
Ultimately in troubleshooting this we noticed the same time complexities with fetchmany(x) and playing with arraysize while testing with the following:
import time
def result_iter(cursor):
result_count = 0
while True:
result_count += cur.arraysize
start = time.time()
results = cursor.fetchmany(numRows=cur.arraysize)
print(result_count)
print(start - time.time())
if not results:
break
for result in results:
yield result
results = []
for batch in result_iter(cur.execute(raw)):
results.append(batch)
For comparison sake, here is the same raw sql code executed in Data Grip utilizing jdbc drivers:
Can you think of anything that would be responsible for this performance with my current installation/settings? Thanks a ton in advance!
Answer the following questions:
-
What is your version of Python? Is it 32-bit or 64-bit?
3.5.3 64-bit -
What is your version of cx_Oracle?
6.1 -
What is your version of the Oracle client (e.g. Instant Client)? How was it
installed? Where is it installed?
Instant Client ~/lib -
What is your version of the Oracle Database?
Oracle Standard Edition Two 12.1.0.2.v10 -
What is your OS and version?
MacOS Sierra 10.12.6 -
What compiler version did you use?
Apple LLVM version 9.0.0 (clang-900.0.38) -
What environment variables did you set? How exactly did you set them?
export ORACLE_HOME=/Users/user-name/instantclient_12_2
export LD_LIBRARY_PATH=/Users/user-name/instantclient_12_2
export DYLD_LIBRARY_PATH=/Users/user-name/instantclient_12_2
export OCI_DIR=/Users/user-name/instantclient_12_2 -
What exact command caused the problem (e.g. what command did you try to
install with)? Who were you logged in as? -
What error(s) you are seeing?
I did not get any errors just incredibly slow execution. RDS Database CPU remains under 3% during execution.