mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.92k stars 563 forks source link

retrieving single value of nvarchar(max) column takes extremely long #1025

Closed 1knueller closed 2 years ago

1knueller commented 2 years ago

Environment

64-bit

Issue

Observed behavior:

I am selecting a single value from the db. The db is running local btw. The column typeis of type nvarchar(max) and in this specific record the value is a bit less than 8000 characters. I did not expect this to be performant but it takes 6 Minutes and 26 seconds to retrieve the value. The table only has 1 record at this time.

cnxn = pyodbc.connect(conn_str) cursor = cnxn.cursor() query = f'SELECT json FROM [mydb].[dbo].[Infos] where Code = \'{code}\' and Tag = \'{tag}\'' cursor.execute(query) value = cursor.fetchval()

Expected behavior:

this query should take milliseconds at maximum.

1knueller commented 2 years ago

After restarting my pc and executing only this query on the fresh db/python/jupyter session it takes fractions of a seconds.

I have no idea how this could take so long at some point.

v-chojas commented 2 years ago

Probably running out of memory and swapping heavily.