Skip to content

setinputsizes(CLOB) is extremely slow, do we need to setinputsizes(CLOB)? #189

@zzzeek

Description

@zzzeek

Hey Anthony -

today on setinputsizes(), apparently CLOB is incredibly slow. Omitting it, an INSERT seems to proceed without issue, and I've tried somewhat larger text sizes up to a few dozen megs in size and it still round trips correctly. The only thing setinputiszes(CLOB) seems to get me is that I can persist a blank string '' without it turning into NULL.

Can I get some clarity on this one? test program below produces:

0.05559845399693586
11.789099370995245

e.g., calling setinputsizes(CLOB) makes a modest insert of 1000 rows 200 times slower, with cx_Oracle 6.3.

import cx_Oracle
import decimal

conn = cx_Oracle.connect(
    user="scott",
    password="tiger",
    dsn=cx_Oracle.makedsn(
        "oracle1120", 1521,
    )
)

def setup():
    cursor = conn.cursor()
    try:
        cursor.execute("drop table t")
    except:
        pass

    cursor.execute("""
    CREATE TABLE t (
        x CLOB
    )
    """)
    return cursor



def go1(cursor):
    cursor.executemany(
        "insert into t (x) values (:x)",
        [
            {"x": "text %s" % i} for i in range(1000)
        ]
    )

def go2(cursor):
    cursor.setinputsizes(x=cx_Oracle.CLOB)
    cursor.executemany(
        "insert into t (x) values (:x)",
        [
            {"x": "text %s" % i} for i in range(1000)
        ]
    )

import timeit

cursor = setup()
print(timeit.timeit("go1(cursor)", "from __main__ import go1, cursor", number=5))

cursor = setup()
print(timeit.timeit("go2(cursor)", "from __main__ import go2, cursor", number=5))


Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions