Repeated column values are no longer compressed for a cursor once an execution ended with an empty fetch
还没有人认领这个 Issue。
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
- 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")
- 主要语言
- Python
- 星标
- 458
- 派生
- 123
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
oracle/python-oracledb 的其他 Issue
-
enhancement
难度 5/5 一周以上 新手友好度 35/100
oracle/python-oracledb#642 · 1 条评论 ·
-
bug
难度 4/5 3-5 天 新手友好度 25/100
oracle/python-oracledb#641 · 6 条评论 ·
-
bug patch available
难度 3/5 半天 新手友好度 76/100
oracle/python-oracledb#640 · 4 条评论 ·
-
bug
难度 3/5 1-2 天 新手友好度 57/100
oracle/python-oracledb#639 ·
-
Client Library or Database
难度 4/5 3-5 天 新手友好度 55/100
oracle/python-oracledb#633 · 2 条评论 ·
查看 oracle/python-oracledb 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug improve content
难度 1/5 1 小时以内 新手友好度 92/100
opensafely/documentation#2102 ·
维护者通常 1 天内回复
-
difficulty:1 documentation
难度 2/5 1-3 小时 新手友好度 82/100
MakazhanAlpamys/Soup#3533 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
onyx-dot-app/onyx#18730 ·
维护者通常 1 天内回复