Skip to content

[Bug]: vector index builders turn Column objects into "Doc.id" strings in DDL #31400

Description

@Ariznawlll

DRAFT 22 (SDK, 2026-10-27) — to be filed

Title: [Bug]: vector index create passes str(Column) ("Doc.id") into DDL — documented Column-object input produces invalid SQL

Description

IVFFLATVectorIndex / HNSWVectorIndex (sqlalchemy_ext/vector_index.py) accept column: Union[str, Column] and normalize it with:

self._column_name = str(column) if not isinstance(column, str) else column
...
sql_parts = [f"CREATE INDEX {self.name} USING {self.index_type} ON {table_name}({column_name})"]

But str() of a SQLAlchemy Column is not the column name — verified on the repo's own SQLAlchemy version:

>>> str(Doc.id)                      # ORM mapped attribute
'Doc.id'                             # class-qualified
>>> str(Doc.__table__.c.id)         # Table-level Column
'docs.id'                            # table-qualified

So every documented Column-object invocation emits broken DDL:

IVFFLATVectorIndex.create_index(engine, "docs", "ft", Doc.embedding, lists=100)
# CREATE INDEX ft USING ivfflat ON docs(Doc.id) LISTS 100 ...
#                                                ^^^^^^ unknown column "Doc.id" → server error
# (or quietly wrong if a dot-containing identifier ever matches)

Same defect in HNSWVectorIndex (same _column_name = str(column) line) and in the drop path implicitly (drop uses only name/table, fine).

Additionally in the same builders (for the same fix, not the main defect):

  • name/table_name/op_type are interpolated unescaped (family issue, one more site),
  • numeric knobs (lists, m, ef_construction, ef_search) are unvalidated ints interpolated raw — client-side sanity checks absent,
  • create_index/drop_index wrap failures in print(...) + return False — the same error-swallowing pattern filed for FulltextIndex today ([Bug]: fulltext create_index swallows server errors with print() #31382); consolidating that observation here so the fix PR can convert all three helpers to raising/logging at once.

Reproduction

from sqlalchemy import Column, Integer, Text
from sqlalchemy.orm import declarative_base
from matrixone.sqlalchemy_ext.vector_index import IVFFLATVectorIndex

Base = declarative_base()
class Doc(Base):
    __tablename__ = "docs"
    id = Column(Integer, primary_key=True)
    body = Column(Text)

idx = IVFFLATVectorIndex("ft", Doc.body)          # documented Union[str, Column] usage
print(idx._column_name)                            # 'Doc.body'  ← not 'body'!
idx.create_sql("docs")
# 'CREATE INDEX ft USING ivfflat ON docs(Doc.body) LISTS 100 op_type 'vector_l2_ops''
# server → unknown column 'Doc.body'

Pure-python verification of the str() behavior needs no server.

Impact

  • The natural, autocomplete-friendly call style (Doc.embedding rather than "embedding") — precisely the audience a SQLAlchemy integration targets — fails 100% of the time with a server-side unknown-column error that never mentions the real cause (str-vs-name conversion). <class>.<attr> shapes even look plausible in error logs.
  • ORM users' first touchpoint with the SDK vector stack breaks; workarounds (string column) are undocumented.

Expected behavior

  1. Normalize Column objects via column.name (or .key), e.g. column.name if isinstance(column, Column) else column — the class-qualified ORM-mapped attribute path works through that attribute.
  2. Escape/validate the interpolated pieces (backticks for identifiers, enum-check op_type, int() the knobs).
  3. Replace print()-swallow with raised/propagated errors (shared with the fulltext fix per [Bug]: fulltext create_index swallows server errors with print() #31382).
  4. Regression: parametrized over (str, Table-column, ORM-attribute) asserting create_sql("docs") always contains ON docs(body).

Activity

  1. added
    kind/bug
    on Oct 27, 2026
  2. added this to the MO-202610 milestone on Oct 27, 2026
  3. added theissue type on Oct 27, 2026
  4. added a commit that references this issue on Oct 30, 2026
    bbfe556
  5. XuPeng-SH commented on Oct 30, 2026

    @XuPeng-SH
    Contributor

    QA handoff for merged #31774 (main bbfe55669a1440424914d45a283a1d0e36f722fa): please verify the reported public SDK contract and its failure/recovery controls for vector index builders turn Column objects into "Doc.id" strings in DDL. This isolated QA run inspected the issue and merged PR but did not run tests or a live MatrixOne service at this SHA because the existing resource guard left insufficient headroom. The PR's author-reported validation is separate evidence, not a result of this QA run.

  6. Ariznawlll commented on Oct 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。列对象的名称映射已改善,但原 issue 要求的向量索引数值参数校验仍缺失,非法参数会直接进入生成的 DDL。

    关键证据

    • 官方 main@d39d8a40343ccd40bf665036388df7a40ee867f8;相关修复 PR fix(python): unify SDK query and analytics lifecycle contracts #31774 合并提交 bbfe55669a1440424914d45a283a1d0e36f722fa 在该版本祖先链。实际二进制和 SDK 同完整 SHA;本地隔离 1 CN / 1 TN / 1 LogService,Python 3.12、SQLAlchemy 2.0.43。
    • 三个独立库中,字符串列名、SQLAlchemy Table 列和 ORM 属性均生成 docs(v),IVF 的三种列引用均可实际创建和删除索引,底表仍有两行;HNSW 的三种引用已检查生成 DDL,但本机实际 HNSW 创建报错,原因尚未确定,不把它算作该问题的产品失败。
    • 相同三轮中,IVFVectorIndex('idx_check','v',lists='not-a-number').create_sql('docs') 未拒绝非法数字,生成的 SQL 含 lists = not-a-number;原 issue 明确要求检查数值参数。SDK 当前 DDL 渲染位置 直接插入该值。此处没有执行该无效 DDL,也不声称数据已损坏。

    待解决点

    • 请校验 IVF/HNSW 构造入口的数值参数及范围,并覆盖非法参数拒绝后无 DDL、正常参数和列对象创建;另需核实当前隔离环境的 HNSW 创建错误。未将失败断言加入 MOTR 成功结果,也未运行完整 suite。
  7. added a commit that references this issue on Oct 30, 2026
    91dfab2
  8. XuPeng-SH commented on Oct 30, 2026

    @XuPeng-SH
    Contributor

    新修复转 QA:#31889 已合入 main,合并提交 91dfab2132c4c4fcd3f9a115dbfa968b196b8b14。

    共享向量索引owner校验lists/m/ef_construction/ef_search(含后续赋值),非法数字在setup/DDL前拒绝;create/drop共享引用与异常传播路径。

    已核对 issue 正文、完整评论及当前合并源码/测试内容。历史失败按其原 SHA 保留;新修复直接覆盖上述残留,未发现适用于新修复的已验证反例或尚未完成的开发 follow-up。本轮仅源码/测试内容静态核对,没有运行 MatrixOne 服务或 SDK 回归;作者在 PR 内的运行结果是作者证据,不是本轮独立测试。转 Ariznawlll 继续验证,不代表验收通过。

    QA 待验范围:str/Table列/ORM属性,IVF及HNSW真实create/drop、非法数字/范围/修改后拒绝且无DDL、标识符/schema_translate_map;历史HNSW未归因错误需QA复核而非算通过。

  9. Ariznawlll commented on Oct 31, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。

    关键证据

    • 2026-10-31 本地隔离双 CN、TN、LogService,服务和 SDK 源码均为官方 main@4f894474ad10e1b9dc338868145a118a71c1fa23,修复 fix(python-sdk): unify SQL, transaction and driver boundaries #31889 在祖先链;本次 HNSW 使用 CPU 路径,不涉及 GPU。
    • IVF 和 HNSW 分别以字符串、SQLAlchemy Table 列和 ORM 属性三种输入实际创建并删除索引;含反引号的索引名可正确引用。非法 lists/m/ef 参数的 0、负数、字符串、布尔和小数在构造或后续赋值时拒绝;非法 op_type 拒绝,没有生成 qa_bad 索引。删除不存在的索引会传播数据库错误,源行与连接池保持正常,各 3/3。
    • 实际 schema_translate_map 将逻辑 schema 映射到测试库后成功创建并删除 IVF;补充的 vector DDL 模拟驱动合同重复三轮共 180 passed,覆盖更多标识符和映射边界。
    • 真实服务回归见 MOTR #298 的 issue_31400_vector_index_columns.py(提交 bb8aa94a);该 PR 尚未合入,完整 suite 未运行。

    待解决点

    • 无。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions