Skip to content

feat(hnsw): ignore and record rows an index cannot store; SHOW INDEX IGNORED (#31493) - #31596

Merged
XuPeng-SH merged 14 commits into
matrixorigin:mainfrom
cpegeric:issue_31493
Nov 2, 2026
Merged

XuPeng-SH merged 14 commits into
matrixorigin:mainfrom
cpegeric:issue_31493

Conversation

@cpegeric

@cpegeric cpegeric commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #31583

Fixes #31493

What this PR does / why we need it:

An HNSW index whose stored type cannot hold a row's vector (for example a vecf32 element above 65504 in a float16 index) stalled its ISCP sync forever: the same row failed on every replay, every later change was missing from the index, and queries kept using the stale index.

This PR implements the contract of #31583 for HNSW (decided by @cpegeric, 2026-10-28 and 2026-10-30; design doc docs/design/20261028-index-ignored-rows.md):

  • A limit on the rows an index leaves out. CREATE INDEX ... MAX_BAD_RECORDS n sets how many source rows the index may leave out because it cannot store them; ALTER TABLE ... ALTER REINDEX idx hnsw MAX_BAD_RECORDS = n changes it. It is 0 unless given, like BigQuery's maxBadRecords, applies to each partition's index of a partitioned table, and is shown by SHOW CREATE TABLE.
  • Ignore and record, up to the limit. Within the limit a row is left out and recorded in a per-index hidden ignored table, following Elasticsearch's ignore_malformed / _ignored; the ignored rows follow the source rows, and REINDEX and TRUNCATE start them over. One row more fails a synchronous build, which rolls back, and stops an asynchronous build or sync with a permanent ISCP error instead of retrying it forever. A build that can store none of the rows it reads fails within the limit too. REINDEX, with a higher limit if needed, rebuilds the index and restarts a stopped one.
  • Bounded memory. A build, and a sync that rebuilds the index, spill the rows they ignore to a local file, as they spill the index itself, and write them in batches of 1024 in the transaction that commits the index; memory does not grow with the limit or with the partitions built at the same time. An incremental sync holds only its own changes and counts the ignored table after them.
  • Restore follows the index's limit. A restore or clone restores the index with its MAX_BAD_RECORDS and rebuilds it from the restored rows like REINDEX: an index within its limit comes back with the same ignored rows, and one stopped by the limit comes back stopped, with the same error.
  • Error codes. Each reason (dimension, NaN or infinite element, out of range) is a moerr error code, as are the limit and the all-bad build errors. The ignored table stores the code; its message is optional.
  • Visible to users.
    • SHOW INDEX IGNORED FROM [db.]tbl [WHERE expr] returns Key_name, Primary_key, Error_code, Reason, Ignored_at for every index and partition.
    • SHOW INDEX STATUS FROM [db.]tbl [WHERE expr] returns, per index (and partition), State (running / retrying / stopped), Error_message, Ignored_rows, Max_bad_records and Synced_at. The sync jobs are kept by the system account, so an account cannot read them itself; the statement shows those of the caller's account.
    • Both require SELECT on the table.
  • Existing indexes. Only CREATE INDEX creates the ignored table. An index created before this change keeps its previous behaviour until it is dropped and created again; no upgrade step.

Validation

  • Black box: pessimistic_transaction/vector/vector_hnsw_ignored.sql, one section per design-doc claim I1–I10 (including a tenant account and a user without SELECT); vector_hnsw_quantization.sql C14 updated; the pessimistic_transaction/vector (1082/0), vector (3362/0) and ddl (8825/0) suites pass.
  • Black box, adversarial SQL against a live instance (23/23): 3,000 ignored rows spilled across batches in a synchronous build and an asynchronous first sync, at and past the limit; incremental syncs counting the whole table, a stopped index not retried and restarted by REINDEX; an update freeing its place; the limit per partition; a snapshot RESTORE of an index within its limit and of a stopped one; TRUNCATE and DROP INDEX; 400 bad rows from 8 concurrent sessions counted exactly; no spill file left.
  • Unit: pkg/common/moerr, pkg/catalog, pkg/iscp, pkg/vectorindex/..., pkg/indexplugin/..., pkg/sql/colexec/table_function, pkg/sql/parsers/..., pkg/sql/plan, pkg/frontend pass; pkg/sql/compile pass. The tracker, permanent-error and build tests pass under -race -count=50.
  • golangci-lint: 0 issues on the changed packages.

🤖 Generated with Claude Code

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@fengttt fengttt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait. This is a pretty big thing.

I wonder what happens to the rows get into the ignored table. Will we ever fish them out? Is there a way for forcing a retry? -- mainly IF, it failed to index and ignored because of OUR bug, we fixed out bug, then what? I think we need to force a retry on those ignored. -- of course if you decide this is not necessary, let's just reindex, I think it is fine.

There is update/delete tests etc, do we know test cases cover full build/and incremental etc ... I am not sure those test cases cover async catch up cases, but I may be wrong.

@cpegeric

Copy link
Copy Markdown
Contributor Author

Oh wait. This is a pretty big thing.

I wonder what happens to the rows get into the ignored table. Will we ever fish them out? Is there a way for forcing a retry? -- mainly IF, it failed to index and ignored because of OUR bug, we fixed out bug, then what? I think we need to force a retry on those ignored. -- of course if you decide this is not necessary, let's just reindex, I think it is fine.

There is update/delete tests etc, do we know test cases cover full build/and incremental etc ... I am not sure those test cases cover async catch up cases, but I may be wrong.

@fengttt import valid f32 vector and create async index with quantization bf16 vector. some vectors may cause overflow and get rejected/error only in ISCP/CDC update. The error is permanant and currently ISCP will keep retry forever but it always fails and make ISCP don't have any update afterwards. No retry can fix it. Put the malformed vector in the ignored table as a report and ignore it is the proper way to handle malformed vector (after quantization). The f32 vector in source table is correct and valid by itself but overflow/underflow after quantization. Update/Delete don't be affected because ASYNC index don't have DML operation. Only ISCP is involved. Synchronous CREATE INDEX will error out as before without going to ignored table. REINDEX/RESTORE will involve ignored table because the data is already in the table and should keep ignored.

@XuPeng-SH

XuPeng-SH commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 4f355468d2232c4b534dbd64061afe918482f0a7

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 4f355468d2232c4b534dbd64061afe918482f0a7

Assessment: approve

Complete review found no unresolved actionable defects. Prior BF16 classification, privilege and memory findings are resolved. The explicit uniform MAX_BAD_RECORDS contract supersedes the earlier create/rebuild distinction; transactional updates, restore and recovery paths are consistent with it.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • Recovered matching-head receipts confirm TestIgnoredRowsSql, TestUnstorableCode and TestIgnoredSpill passed.

  • Generated parser matches byte-for-byte; all 54 changed Go files passed formatting checks.

  • Frozen CI reports successful build, UT, SCA, coverage, proxy and pessimistic multi-CN BVT.

  • audit-review.log and validation-evidence.json reconcile retained receipts and logs. discussion-assessment.json covers all 37 discussion entries.

Limitations:

  • Native, GPU, race and public-SQL checks were not independently rerun locally; author-reported results lack supplied raw logs. Compatibility CI was skipped.

  • The combined parser-check command exited 1 on trailing whitespace in expected SHOW CREATE output; its generation and formatting stages passed.

@iamlinjunhong iamlinjunhong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 4f355468d2232c4b534dbd64061afe918482f0a7 against base bc168358728aaa8141ae7a3c9d8f27bb8cb33e75. Approve. No unresolved, confirmed findings remain within this PR's HNSW scope.

The previous review's three findings were rechecked against the original reviewed revision and this head:

  • BF16 overflow classification is fixed: the shared guard checks BF16 values before float16 narrowing. The author explicitly replied in the original thread; corresponding unit and SQL regression coverage is present.
  • COPY ADD INDEX now follows the author's explicit revised contract: every build uses MAX_BAD_RECORDS, defaulting to zero. The default rejects unstorable rows for CREATE, ADD INDEX and COPY; an explicit positive limit permits partial builds. This supersedes the previous create/rebuild policy distinction. The author also replied directly to the original finding.
  • Incremental tracking no longer loads historical ignored keys: it checks existence with LIMIT 1 and tracks touched keys. The author replied directly. Builds and snapshot rebuilds now spill ignored rows and persist batches of at most 1024.

Also checked the subsequent SHOW authorization fixes, error classification, limit enforcement, index/ignored-row/watermark transaction boundaries, REINDEX recovery, restore integration, partition handling and existing-index behavior. The earlier empty-result/subquery privilege and rebuild-memory findings are addressed. This assessment does not assert formal approval of the design document, which remains marked proposed.

Supplied exact-head CI/check snapshot: 30 total: 14 success, 14 skipped, 2 neutral. CI Required succeeded; no failed or pending checks appear in the snapshot, but not all 30 checks have a success conclusion. CI run.

Validation: reviewed the 63-file delta, generated parser semantic changes, relevant callers, tests and discussion history. The read-only PR artifact check passed and the source worktree remains clean. git diff --check reports one trailing space in the SHOW CREATE expected-output fixture (vector_hnsw_ignored.result:180); this is not a correctness finding. Local targeted tests were skipped because source tracing and supplied exact-head CI left no concrete uncertainty requiring additional execution. No local UT, BVT, native HNSW, GPU, race or server execution is claimed; author-reported execution totals were not independently reproduced.

@XuPeng-SH

XuPeng-SH commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 4f355468d2232c4b534dbd64061afe918482f0a7

New discussion was assessed; the previous review remains unchanged.

cpegeric and others added 11 commits November 1, 2026 09:23
…n#31493)

An HNSW index that cannot store a row's vector (e.g. a vecf32 element above
65504 in a float16 index) no longer stalls its ISCP sync. The row is left out
of the index and recorded in a new per-index hidden table of type `ignored`
(primary key, reason, time), following Elasticsearch's ignore_malformed.
The ignored rows track the source rows: a delete or an update to a storable
value removes them; REINDEX and TRUNCATE start them over.

A synchronous CREATE INDEX still rejects such a row. REINDEX (including
FORCE_SYNC/restore), the ALTER TABLE rebuild and incremental sync ignore and
record it. A query vector the index cannot store is still rejected.

SHOW INDEX IGNORED FROM [db.]tbl [WHERE expr] lists the ignored rows of every
index (and partition) with Key_name, Primary_key, Reason and Ignored_at.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An index created before ignored tables existed keeps its previous behavior:
its build fails on a row it cannot store and SHOW INDEX IGNORED skips it.
Only CREATE INDEX creates the ignored table; REINDEX does not add it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… IGNORED

- SHOW INDEX IGNORED lists primary keys of the table's rows, so it now
  requires SELECT on the table: the ignored-table scans carry the base table
  as their parent and the plan-based privilege check applies.
- The ISCP ignored-row tracker is algorithm-neutral: every consumer flushes it
  at its commit point (index SQL, cuVS, fulltext2, HNSW), keys are read in the
  writer's value representation, and byte keys compare by value.
- The rule that a user's CREATE INDEX rejects an unstorable row is a shared
  compile-plugin helper.
- CheckStorable compares each element with the overflow boundary of the
  stored type instead of converting the vector; a test proves it rejects
  exactly what ToStorage rejects, with the same error.
- The design doc claims I1-I8 each head a section of the black-box suite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An HNSW index now has an ignored-rows table (algo_table_type 'ignored'),
so the ALTER COPY case's listing of the index's hidden tables has three
rows, as vector_index_plugin_smoke.sql already expects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
pkg/vectorindex/ignored.go imported pkg/catalog for the ignored table's
column names. In a gpu build catalog reaches vectorindex again
(catalog -> objectio -> vectorindex/metric -> cuvs -> vectorindex), so
every MO_CL_CUDA=1 build failed with an import cycle; CPU builds, which CI
runs, do not have the cuvs edge.

IgnoredRowsSql now takes the column names (IgnoredColumns), and the two
callers pass catalog's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… bounded sync

- CheckStorable widens every element type other than float32/float64 to
  float32, as ToStorage does, so a vecbf16 value beyond the float16 range
  is recorded instead of stalling the sync. TestCheckStorableMatchesToStorage
  checks it against ToStorage for every column type and storage kind.
- A copying ALTER TABLE that adds an index rejects a row the index cannot
  store, as CREATE INDEX does; the indexes it rebuilds still record such
  rows. The compile context reports the indexes the statement adds
  (IsNewIndex), from AlterCopyOpt.NewPluginIndexes.
- An incremental sync no longer reads the ignored rows: it asks only
  whether the table has one, and records the keys it touches only then,
  so its memory follows its own changes. Removals stay batched by 1024.
- Design doc: consistency, recovery, retry and bounds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… table

When the table has no ignored-rows table (an ordinary table, or an index
without one) the plan reads no table, so no privilege tip was produced and
the statement ran unchecked. Check SELECT on the named table in that case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…GNORED

The named-table check ran only when the plan read no table, so a WHERE subquery on
another table skipped it. SELECT on the named table is now required whatever the plan
reads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nored rows

An index may leave out at most MAX_BAD_RECORDS source rows it cannot store (CREATE INDEX
option, changed by ALTER REINDEX, 0 unless given, per partition index). One row more fails a
synchronous build and stops an asynchronous build or sync with a permanent ISCP error instead
of retrying it; a build that can store none of its rows fails too. REINDEX restarts a stopped
index, and a restore follows the restored limit.

- Builds and first syncs spill the rows they ignore to a local file and write them in the
  transaction that commits the index, so memory does not grow with the limit.
- Each reason is a moerr code; the ignored table stores the code, its message is optional.
- SHOW INDEX IGNORED gains Error_code; SHOW INDEX STATUS shows each index's sync state,
  error, ignored rows and limit to the account that owns it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Results of SHOW INDEX IGNORED and STATUS are not saved: result_scan would read them back
  without the SELECT check on the table.
- Prepared SHOW INDEX IGNORED and STATUS are planned again on every EXECUTE: their plans hold
  the state of the index jobs when they were built.
- SHOW INDEX STATUS names a partition as users know it, and shows no sync time for a job
  stopped before its first sync.
- The build's log names the first row it leaves out; docs match the code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CLAassistant

CLAassistant commented Nov 1, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ cpegeric
✅ XuPeng-SH
❌ codex
You have signed the CLA already but the status is still pending? Let us recheck it.

@XuPeng-SH

XuPeng-SH commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: a9569d594532bba52698c2e4c5f3fb4276fc427b

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: a9569d594532bba52698c2e4c5f3fb4276fc427b

Assessment: approve

Reviewed all 63 changed files and reconciled all 42 discussion entries. Earlier BF16, memory-growth and authorization findings are resolved. The accepted uniform MAX_BAD_RECORDS policy supersedes the older CREATE-versus-REINDEX distinction. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • Isolation preflight passed; source remained unchanged.

  • Full common/moerr package passed: 90 test/subtest pass events.

  • Actual ignored.go file-list tests passed: SQL batching, error-code classification and spill handling.

  • Repository parser regeneration matched exactly; all 54 changed Go files were gofmt-clean.

  • Frozen-head CI records 14 successful, 14 skipped and 2 neutral checks, including build, unit tests, static analysis, proxy BVT and pessimistic multi-CN BVT.

  • discussion-assessment.json covers every discussion key exactly once. validation-evidence.json reconciles local logs and receipts; final audit passed.

Limitations:

  • Native HNSW integration, full frontend/ISCP suites, race, GPU and public SQL/restore scenarios were not independently executed locally; supplied CI and reported author evidence supplement source review.

  • Compatibility CI was skipped; per-case raw CI logs were unavailable.

  • git diff --check reports one accepted trailing space in the exact SHOW CREATE result fixture.

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design: the HNSW scope and owner decisions in the 2026-10-30 ignored-rows design are sound: omitted rows are explicit persisted index state, MAX_BAD_RECORDS bounds missing coverage rather than one batch, and deterministic row failures are separated from retriable infrastructure errors. Existing-index behavior is an explicit compatibility boundary.

Reviewed a9569d5: traced synchronous build and incremental/snapshot sync, transaction/watermark ordering, permanent-error handling, ignored-state replacement/removal, spill-file lifetime, reindex/clone paths, parser/parameter propagation, SHOW planning and table/tenant authorization. Checked the changed unit and SQL oracles, including limit rollback, restart by REINDEX, partition accounting and denied-user controls. No blocking issue found. Reused author package/race/adversarial SQL results and green exact-head CI; no new local tests.

@mergify

mergify Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue

50 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Mon 2 Nov, 09:05 · rule main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue 09:55 · a9569d5

Reason

The pull request can't be updated

GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/ci-scope-check.yml without workflows permission
GitHub only lets Mergify write to .github/workflows/ with the workflows permission. An organization owner can accept Mergify's pending permissions at https://dashboard.mergify.com/orgs/matrixorigin/repositories.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

@mergify

mergify Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

queue

🛑 The queue request has been cancelled: new commits were pushed

Details

@cpegeric pushed to this pull request after queue was requested. Review the new commits and request it again.

This branch was successfully deployed

No deployments
ci — 1bfc0906 Deployed Nov 2, 2026 by cpegeric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/feature size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: float16 HNSW CDC stalls after committed out-of-range vector and hides later valid rows

8 participants