Repository navigation
Description
DRAFT 20 (SDK, 2026-10-27) — to be filed
Title: [Bug]: IVFConfig/HNSWConfig enable-flags run SET on one pooled connection only — "enabled" is per-connection and lost on recycle
Description
IVFConfig.enable_ivf_indexing()/disable/.../configure_ivf, HNSWConfig.enable_hnsw_indexing()... (sqlalchemy_ext/ivf_config.py, hnsw_config.py) implement the documented "enable X indexing" APIs as:
with self.engine.begin() as conn:
_exec_sql_safe(conn, "SET experimental_ivf_index = 1") # session-scope SETSET ... in MatrixOne/MySQL semantics is a session variable — but engine.begin() checks out one pooled connection, sets the flag, and returns it to the pool. So:
- Only one pool connection carries the flag. With pool_size 5 + overflow (the SDK's own defaults: pool_size=5, max_overflow=10), the other 4-14 connections never get the SET. The very next query may land on a different connection — experimental features (IVF/HNSW index usage) silently off, then on, intermittently per query.
- Recycle invalidates it entirely:
pool_recycle=3600(SDK default) or anypool_pre_pinginvalidation replaces that connection — after recycle no connection has the flag, whileconfigure_ivf()long returned True andget_ivf_status()(which runs SHOW VARIABLES on yet another fresh connection!) reports...experimental_ivf_index = off. The status API and the enable API talk to different connections, so they can disagree within the same second. vector_manager._build_setup_sql(["SET experimental_ivf_index=1", "SET probe_limit=N"])has the same shape — its SETUP statements only bind to whichever pooled connection the caller later does NOT guarantee (depends on the executor path taking the same connection).
Correct approaches exist in the SDK itself: ConnectionHook (connection_hooks.py) exists precisely to run SET-on-connect for every pooled connection — the IVF/HNSWConfig helpers bypass it instead of composing with it. (ConnectionHook has its own id()-set bug filed today — #31396 — but its architecture is the right one.)
Secondary defect in the same module: _exec_sql_safe does sql.replace('%', '%%') only on the exec_driver_sql branch, not on the text() branch — two execution paths with different escaping for identical input; a LIKE containing % round-trips differently depending on which driver-connection facade a caller's SQLAlchemy version provides. And set_probe_limit interpolates limit unvalidated into SET (minor, but should be int()-asserted).
Reproduction
Conceptual (needs server, no assertion dependency):
cfg = IVFConfig(engine)
assert cfg.enable_ivf_indexing() # True — flagged ONE pooled connection
cfg.get_ivf_status() # runs on ANOTHER connection → often reports ivf_enabled=False
# and a vector search executed right after may or may not use the IVF index
# depending on which pooled connection the driver picks — flaky by constructionImpact
- "Enable IVF/HNSW" is the primary documented step for every vector-index workflow; with default pools it is ineffective for 80%+ connections immediately and 100% ineffective after one recycle. Symptoms are the worst kind: intermittent index usage — slow queries sometimes, EXPLAIN plans that flip, search-quality variance.
get_ivf_status()contradicting a successfulenable_*()confuses every diagnosing engineer ("I enabled it!").- The module overlaps with (and contradicts) the ConnectionHook mechanism; two competing enable paths with different behavior semantics confuse users about which to call.
Expected behavior
- Enable/disable APIs should schedule the flag on every current and future pool connection — either reuse ConnectionHook (attach an action for the flag) or execute SET via an event-listener on connect; or store the desired state and have the pool's
do_connectcallback apply it. get_ivf_status()should read from the same connection the SET ran on (or aggregate all pooled connections), not a random one.- Unify the
%-escaping between the two_exec_sql_safebranches (escape neither, or escape both — pick per actual driver semantics). - Regression: enable → exhaust all pool connections → assert each received the SET (stub executor or event spy); after
engine.dispose(), re-enable and re-assert.
Activity
Ariznawlll commentedon Oct 29, 2026
结论
测试不通过。补充真实 MatrixOne 连接池验证:IVFConfig 返回启用成功,但另一条已借出的物理连接仍为关闭;连接池 dispose 后新连接也恢复关闭。本轮补充原问题,不新提重复 issue。
关键证据
main@c6683bd2f531dcaa80e153c0924dac619c49dc9d;SDK 与隔离本地服务构建一致,Python 3.14 / SQLAlchemy 2.1.6;3 个新建库验证,每库包含真实 VECF32(2) 数据、NULL 行和已创建的 IVFFLAT 索引。experimental_ivf_index=0,调用同引擎IVFConfig.enable_ivf_indexing()返回 True;在 A 上直接重读仍为 0,另借物理连接 B 为 1。各轮均记录 CONNECTION_ID 证明是两条不同连接。engine.dispose(),再次get_ivf_status()返回ivf_enabled=False、无错误。(1,[0,0]),(2,[1,1]),(3,NULL),同连接 SELECT 1 正常。源码IVFConfig.enable_ivf_indexing临时借用一条连接 SET 后归还,与实测一致。待解决点
Ariznawlll commentedon Oct 29, 2026
结论
测试不通过。HNSW 也已补充真实连接池与建索引验证:无连接参数的启用调用返回 True,另一条已借出的连接仍因开关未启用而无法建索引;明确传入该连接后创建正常。补充原 issue,不另提重复问题。
关键证据
main@c6683bd2f531dcaa80e153c0924dac619c49dc9d,SDK 与本地隔离服务构建一致,Python 3.14 / SQLAlchemy 2.1.6;3 组独立库复现。experimental_hnsw_index=0并保持借出;同引擎HNSWConfig.enable_hnsw_indexing()返回 True。A 执行CREATE INDEX ix_setup USING hnsw ON hnsw_setup_control(v) op_type 'vector_l2_ops'报20101: experimental_hnsw_index is not enabled。SHOW INDEX 仍仅 PRIMARY,已有两行向量未变。enable_hnsw_indexing(A)后,在 A 上重试同一 DDL 成功,索引为 PRIMARY、ix_setup;完整数据未变且 SELECT 1 正常。另一个真实 1000 行表也验证了 A/B 开关分别为 0/1、dispose 后新连接状态为 False。HNSWConfig的无参分支另借连接;带参分支直接作用于指定连接。待解决点
fix(python): unify SDK query and analytics lifecycle contracts (#31774)
XuPeng-SH commentedon Oct 30, 2026
QA handoff for merged #31774 (main
bbfe55669a1440424914d45a283a1d0e36f722fa): please verify per-physical-connection IVF/HNSW pool settings, concurrent checked-out connections and reconnect. This isolated QA run inspected the issue and merged source but did not run tests or a live MatrixOne service at this SHA because resource headroom under the existing guard was insufficient. Earlier QA counterexamples and PR author-reported validation remain scoped to their recorded versions and are not results of this QA run.Ariznawlll commentedon Oct 30, 2026
结论
测试不通过。IVF/HNSW 设置在连接池重新借用和重建后生效,但
get_ivf_status()仍把已启用状态报告为 False,与 issue 的状态一致性要求不符。关键证据
main@a54850983d9cddaacc97e38a84515ec724c937b7;修复 PR fix(python): unify SDK query and analytics lifecycle contracts #31774 合并提交bbfe55669a1440424914d45a283a1d0e36f722fa为祖先。SDK 和隔离 1 CN / 1 TN / 1 LogService 二进制对应同一 SHA,Python 3.12、SQLAlchemy 2.0.43。dispose()后新连接同为 1,禁用后为 0,3/3。使用 BIGINT 主键表和启用的 HNSW 连接实际创建索引成功,行数保持 3;%在两种执行分支均原样返回,非法 probe_limit 被拒绝。MOTR #298 覆盖上述通过部分,定向 3/3。get_ivf_status()返回ivf_enabled=False且error=None;直接在池连接执行SHOW VARIABLES LIKE 'experimental_ivf_index'返回字符串ON,同一连接SELECT @@experimental_ivf_index为 1,3/3。当前ivf_config.py用ivf_setting[1] == '1'判断,不能识别返回的ON;这不是连接未启用。此前 HNSW 建索引错误经核实是测试表使用 INT 而非要求的 BIGINT 主键,已修正,不归为产品失败。待解决点
fix(python): restore SDK SQL and execution contracts (#31953)
XuPeng-SH commentedon Oct 31, 2026
新修复转 QA:#31953 已合入 main,merge SHA
569d521cfae73ba80c42f58366c172ce4ef84ed7。旧连接池修复已在此前 QA 记录通过;本次修复剩余 ON/OFF 与 1/0 状态解码并拒绝未知表示。请验证启停、并发借还、dispose 重连后的 IVF/HNSW 状态一致性;不要把 DDL 开关等同于查询计划或召回率。
验证证据:作者记录离线多 SQLAlchemy 矩阵、187 个 native 合同、19 个全文 SQL 检查;当前 head 独立 reviewer 记录 315 个 focused Python tests、11 个 SDK online cases 及三个 Go owner package 通过。上述均为 PR 作者/评审者报告,不是本轮独立本地实测。本轮读取 issue 完整评论、修复范围及远端合并状态,未运行服务或测试;未发现适用于新合并版本的已验证反例或未完成的开发 follow-up。转 @Ariznawlll 继续验证,不代表验收通过。完整 BVT、多 CN、长稳和生产环境验证不在本轮证据范围内。
Ariznawlll commentedon Nov 2, 2026
结论
测试通过。IVF/HNSW 开关在连接池借还及重建后保持一致,IVF 状态接口正确识别开启、关闭与未知值。
关键证据
main@35202093259793e48dcd7abc8ff418f07190f746;修复 fix(python): restore SDK SQL and execution contracts #31953 的 merge569d521cfae73ba80c42f58366c172ce4ef84ed7在该 SHA 的祖先链。隔离本地单 CN / TN / LogService;服务git_version()、二进制构建记录 SHA 一致,vcs.modified=false。Python 3.12,分别使用 SQLAlchemy 1.4.54 与 2.1.6。dispose()重建连接池后开关仍为 1,get_ivf_status()返回ivf_enabled=True且无错误。禁用后返回 False,HNSW 在启用的连接上真实建索引,源表保持 3 行。两个 SQLAlchemy 版本各独立重复 3 轮,全部通过。probe_limit为 0、负数、布尔值和非法字符串均抛ValueError;未知 IVF 状态值在 SDK 定向测试中返回错误而非错误地报告已启用或关闭。SQLAlchemy 1.4.54 / 2.1.6 的状态 ON、off、1、0、bytes 和未知值定向用例各 3 轮通过;未知值由模拟结果构造,不宣称服务返回过该值。异常相关 SDK 测试共每轮 8 项,包含依赖诊断,不能全部归为本 issue。qa_pool_前缀测试库数量为 0。MOTR #298 已扩展连接池回归,两种 SQLAlchemy 版本经 MOTR runner 各 3/3;SDK 回归需要显式启用,默认跳过。待解决点