Skip to content

Reading large chunk of data from cursor returned from a stored procedure is extremely slow #482

@smsteel

Description

@smsteel
  1. What versions are you using?
    Oracle Database 11.2.0.4
    platform.platform: Linux-3.10.0-1127.el7.x86_64-x86_64-with-centos-7.8.2003-Core
    sys.maxsize > 2**32: True
    platform.python_version: 3.6.10
    cx_Oracle.version: 8.0.1
    cx_Oracle.clientversion: (12, 2, 0, 1, 0)

  2. Describe the problem

We have a stored procedure with OUT parameter REF CURSOR. When we had aroud ~1k records returned performance was good enough. Now it goes beyond 140 seconds with 50k.

While executing the same procedure and parameters, reading cursor from PL/SQL Developer IDE is very fast, so query is not the problem.

  1. Include a runnable Python script that shows the problem.
import cx_Oracle

dsn = cx_Oracle.makedsn('ip', 1521, 'db')
pool = cx_Oracle.SessionPool(
  user='...',
  password='...',
  dsn=dsn,
  min=1,
  max=10,
  increment=1,
  threaded=True,
  encoding="UTF-8"
)
connection = pool.acquire(purity=cx_Oracle.ATTR_PURITY_NEW)
cursor = connection.cursor()

data = cursor.var(cx_Oracle.CURSOR)

cursor.callproc('proc_name, [
  # couple of in params here
  data
])
data_cursor = data.getvalue()
rows = data_cursor.fetchmany()
while rows:
  for records in data_cursor:
    print(records)
  rows = data_cursor.fetchmany()

So what's strange code execution stops on first data_cursor.fetchmany() and most of the time (like 130s of 140s) is running first fetchmany(), then it reads very fast and continuing calls of fetchmany() goes fast as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpatch availableAwaiting inclusion in official release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions