Repeated column values are no longer compressed for a cursor once an execution ended with an empty fetch
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 48/100
Piste de recherche
Start by reviewing the runnable reproducer in the issue and trace the Thin mode fetch path handling message type 21 and repeated column values; the payload does not name source files or tests. Reproduce cases A and B against Oracle Database, then compare the cursor behavior after the empty fetch. Done means the repeated values remain compressed on later executions, with a regression test covering that sequence.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
- What versions are you using?
- Oracle Database 23ai Free 23.26.3.0.0 and Oracle Database 19c Enterprise Edition 19.3.0.0.0 (container
images): both behave the same way - python-oracledb 26.1.0, Thin mode
- Python 3.14.10, Linux x86_64,
sys.maxsize > 2**32: True
- Is it an error or a hang or a crash?
Neither: it's a performance problem. Rows come back up to 200 times larger than they need to.
- What error(s) or behavior you are seeing?
When a column value is equal to the one in the previous row, the database leaves it out, and the row's bit
vector (message type 21) says which values were left out. For a given cursor, this stops once one of its
executions has ended with a fetch that returned no rows. That happens whenever the number of rows is exactly
prefetchrows plus a multiple of arraysize: the last full batch makes the client ask for more, and the
answer is only the end of the data.
From then on, every execution of that cursor gets whole rows, whatever its bind values, prefetchrows and
arraysize are (cases A, E and F below). The execution with the empty fetch is still compressed; the ones
after it aren't. Compression only comes back when the statement is parsed again: other SQL text (case C), or
the statement leaving the statement cache. An execution that finds no rows at all doesn't cause it (case D).
With the statement cache, this means that a query whose row count once happened to be an exact multiple of the
fetch size receives uncompressed rows for the rest of the session. In the script below, that's 20.18 MB
instead of 0.10 MB for each later execution of the same 10,000 rows.
Output with 23ai (19c gives the same numbers, except 0.10 MB instead of 0.11 MB for the first executions):
python-oracledb 26.1.0, database 23.26.3.0.0
A: the first execution ends with an empty fetch
execution 1: 'select * from dup_repro' prefetchrows=1000 arraysize=1000: 10000 rows, 0.11 MB received
execution 2: 'select * from dup_repro' prefetchrows=1000 arraysize=1000: 10000 rows, 20.18 MB received
execution 3: 'select * from dup_repro' prefetchrows=1000 arraysize=1000: 10000 rows, 20.18 MB received
B: never an empty fetch
execution 1: 'select * from dup_repro' prefetchrows=999 arraysize=1000: 10000 rows, 0.11 MB received
execution 2: 'select * from dup_repro' prefetchrows=999 arraysize=1000: 10000 rows, 0.10 MB received
execution 3: 'select * from dup_repro' prefetchrows=999 arraysize=1000: 10000 rows, 0.10 MB received
C: as A, then other SQL text
execution 1: 'select * from dup_repro' prefetchrows=1000 arraysize=1000: 10000 rows, 0.11 MB received
execution 2: 'select * from dup_repro' prefetchrows=1000 arraysize=1000: 10000 rows, 20.18 MB received
execution 3: 'select * from dup_repro where 1 = 1' prefetchrows=1000 arraysize=1000: 10000 rows, 0.11 MB received
D: the first execution finds no rows
execution 1: 'select * from dup_repro where id <= :n' {'n': 0} prefetchrows=999 arraysize=1000: 0 rows, 0.00 MB received
execution 2: 'select * from dup_repro where id <= :n' {'n': 10000} prefetchrows=999 arraysize=1000: 10000 rows, 0.10 MB received
execution 3: 'select * from dup_repro where id <= :n' {'n': 10000} prefetchrows=999 arraysize=1000: 10000 rows, 0.10 MB received
E: an empty fetch with n = 5000, then other bind values
execution 1: 'select * from dup_repro where id <= :n' {'n': 5000} prefetchrows=1000 arraysize=1000: 5000 rows, 0.05 MB received
execution 2: 'select * from dup_repro where id <= :n' {'n': 10000} prefetchrows=999 arraysize=1000: 10000 rows, 20.18 MB received
execution 3: 'select * from dup_repro where id <= :n' {'n': 7777} prefetchrows=999 arraysize=1000: 7777 rows, 15.69 MB received
F: other bind values, then an empty fetch
execution 1: 'select * from dup_repro where id <= :n' {'n': 10000} prefetchrows=999 arraysize=1000: 10000 rows, 0.11 MB received
execution 2: 'select * from dup_repro where id <= :n' {'n': 7777} prefetchrows=999 arraysize=1000: 7777 rows, 0.08 MB received
execution 3: 'select * from dup_repro where id <= :n' {'n': 3000} prefetchrows=1000 arraysize=1000: 3000 rows, 0.03 MB received
execution 4: 'select * from dup_repro where id <= :n' {'n': 10000} prefetchrows=999 arraysize=1000: 10000 rows, 20.18 MB received
execution 5: 'select * from dup_repro where id <= :n' {'n': 7777} prefetchrows=999 arraysize=1000: 7777 rows, 15.69 MB received
Expected: the executions after an empty fetch are compressed like those in case B (about 0.10 MB for
10,000 rows here).
The byte counts match what strace shows on the socket. It isn't specific to Thin mode: a C program using
OCI 23.26 shows the same pattern. Its query needs a where clause, because for a select * of whole table
rows OCI asks for a row format that is never compressed. So it seems to be the database's doing.
Is this expected? If it isn't, could it be passed on to the database team?
- Does your application call init_oracle_client()?
No (Thin mode).
- Include a runnable Python script that shows the problem.
Usage: python repro_compression.py user password host:port/service. It needs no privileges beyond creating
a table: it creates dup_repro (10,000 rows, every column value repeated) and drops it at the end. Bytes are
counted on the client socket.
"""
Repeated column values in fetched rows stop being compressed for a cursor once one of its executions ended
with an empty fetch. Self-contained: python-oracledb thin mode, bytes counted on the client socket.
Usage: python repro_compression.py user password host:port/service
Creates the table dup_repro (10,000 rows, every column value repeated) and drops it at the end.
"""
import socket
import sys
import oracledb
received = 0
_recv = socket.socket.recv
def counting_recv(self, *args, **kwargs):
global received
data = _recv(self, *args, **kwargs)
received += len(data)
return data
socket.socket.recv = counting_recv
USER, PASSWORD, DSN = sys.argv[1:4]
SQL = "select * from dup_repro"
def run(case, steps):
"""Runs each (sql, binds, prefetchrows, arraysize) step on one cursor of a new connection"""
global received
print(case)
with oracledb.connect(user=USER, password=PASSWORD, dsn=DSN) as conn:
cursor = conn.cursor()
for n, (sql, binds, prefetch, fetch) in enumerate(steps, 1):
cursor.prefetchrows = prefetch
cursor.arraysize = fetch
received = 0
cursor.execute(sql, binds)
rows = cursor.fetchall()
print(f" execution {n}: {sql!r} {binds or ''} prefetchrows={prefetch} arraysize={fetch}: "
f"{len(rows)} rows, {received / 1e6:.2f} MB received")
with oracledb.connect(user=USER, password=PASSWORD, dsn=DSN) as conn:
print(f"python-oracledb {oracledb.__version__}, database {conn.version}")
cursor = conn.cursor()
cursor.execute("begin execute immediate 'drop table dup_repro purge'; exception when others then null; end;")
columns = ", ".join(f"rpad('x', 200, 'x') c{i}" for i in range(1, 11))
cursor.execute(f"create table dup_repro as select level id, {columns} from dual connect by level <= 10000")
# 1,000 rows with the execute, then 9 fetches of 1,000 and an empty one: executions 2 and 3 aren't compressed
run("A: the first execution ends with an empty fetch", [(SQL, None, 1000, 1000)] * 3)
# 999 rows with the execute, then 9 fetches of 1,000 and one of 1: all compressed
run("B: never an empty fetch", [(SQL, None, 999, 1000)] * 3)
# As A, then other SQL text in the same session: another cursor, compressed again
run("C: as A, then other SQL text", [(SQL, None, 1000, 1000)] * 2 + [(SQL + " where 1 = 1", None, 1000, 1000)])
# An execution that finds no rows at all, then executions that never end with an empty fetch
FILTERED = "select * from dup_repro where id <= :n"
run("D: the first execution finds no rows",
[(FILTERED, {"n": 0}, 999, 1000)] + [(FILTERED, {"n": 10000}, 999, 1000)] * 2)
# Other bind values after an empty fetch, and fetch sizes that never end with an empty fetch
run("E: an empty fetch with n = 5000, then other bind values",
[(FILTERED, {"n": 5000}, 1000, 1000), (FILTERED, {"n": 10000}, 999, 1000), (FILTERED, {"n": 7777}, 999, 1000)])
# The same with control executions first: compressed with both bind values until the empty fetch
run("F: other bind values, then an empty fetch",
[(FILTERED, {"n": 10000}, 999, 1000), (FILTERED, {"n": 7777}, 999, 1000), (FILTERED, {"n": 3000}, 1000, 1000),
(FILTERED, {"n": 10000}, 999, 1000), (FILTERED, {"n": 7777}, 999, 1000)])
with oracledb.connect(user=USER, password=PASSWORD, dsn=DSN) as conn:
conn.cursor().execute("drop table dup_repro purge")
- Langage dominant
- Python
- Étoiles
- 458
- Forks
- 123
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de oracle/python-oracledb
-
Free-threading supportOuverteenhancement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
oracle/python-oracledb#642 · 1 commentaire ·
-
connection.gettype with large type def throws error: dbms_pickler: raw variable length too longOuvertebug
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
oracle/python-oracledb#641 · 6 commentaires ·
-
bug patch available
Difficulté 3/5 Une demi-journée Accessibilité débutants 76/100
oracle/python-oracledb#640 · 4 commentaires ·
-
bug
Difficulté 3/5 1-2 jours Accessibilité débutants 57/100
oracle/python-oracledb#639 ·
-
Client Library or Database
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
oracle/python-oracledb#633 · 2 commentaires ·
Toutes les issues de oracle/python-oracledb
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
bug improve content
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
opensafely/documentation#2102 ·
Les mainteneurs répondent en général sous 1 jour
-
difficulty:1 documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
MakazhanAlpamys/Soup#3533 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
onyx-dot-app/onyx#18730 ·
Les mainteneurs répondent en général sous 1 jour