[Bug]: COPY ALTER during pending ASYNC IVFFLAT initialization drops training and returns empty ANN results
Los mantenedores suelen responder en 1 día
@cpegeric ya está trabajando en esto.
Desde el 26/11/2026.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
Description
Tested on MatrixOne main commit c0cef5c9cce2164fedd201c188bfffe4d2d09a96 (git_version() = c0cef5c) with experimental_ivf_index=1.
If an unrelated COPY ALTER (for example, ADD COLUMN) runs while ASYNC IVFFLAT initialization is still pending, the ALTER succeeds but the replacement index permanently loses its initialization path. Both centroids and entries remain empty. Indexed ANN returns no rows while mode=force returns the correct base-table rows.
Unlike a normal initialization failure, the replacement ISCP job keeps advancing its watermark and reports running with no visible error, so the false-empty index does not recover by waiting.
Runnable reproduction
The script includes an initialization-complete positive control followed by the pending-initialization failure. It discovers the hidden IVFFLAT tables from mo_catalog.mo_indexes; no hard-coded internal table names are needed.
Python reproducer (requires `pymysql`)
import time
import pymysql
conn = pymysql.connect(host='127.0.0.1', port=6001,
user='root', password='111', autocommit=True)
DB = 'qa_ivf_add_ready'
def fetch(cur, sql, params=None):
cur.execute(sql, params)
return cur.fetchall() if cur.description else ()
def hidden(cur, table, kind):
rows = fetch(cur, """
SELECT index_table_name FROM mo_catalog.mo_indexes
WHERE algo='ivfflat' AND algo_table_type=%s
AND table_id IN (
SELECT rel_id FROM mo_catalog.mo_tables
WHERE reldatabase=%s AND relname=%s)
""", (kind, DB, table))
return rows[0][0] if rows else None
def counts(cur, table):
result = {}
for kind in ('metadata', 'centroids', 'entries'):
name = hidden(cur, table, kind)
result[kind] = fetch(cur,
f'SELECT COUNT(*) FROM {DB}.`{name}`')[0][0] if name else None
return result
def wait_counts(cur, table, centroids, entries, timeout=40):
deadline = time.time() + timeout
last = None
while time.time() < deadline:
try:
last = counts(cur, table)
if last['centroids'] >= centroids and last['entries'] >= entries:
return last
except Exception as e:
last = str(e).splitlines()[0][:500]
time.sleep(0.25)
return last
def run(cur, name, sql):
try:
rows = fetch(cur, sql)
print(name, 'OK', rows)
except Exception as e:
print(name, 'ERR', str(e).splitlines()[0][:800])
with conn.cursor() as cur:
cur.execute('SET experimental_ivf_index=1')
cur.execute(f'DROP DATABASE IF EXISTS {DB}')
cur.execute(f'CREATE DATABASE {DB}')
cur.execute(f'USE {DB}')
# Positive control: wait for training before the same COPY ALTER.
cur.execute('CREATE TABLE ready_t(id INT PRIMARY KEY,v VECF32(2))')
cur.execute("INSERT INTO ready_t VALUES(1,'[1,2]'),(2,'[3,4]')")
cur.execute("CREATE INDEX ivf USING ivfflat ON ready_t(v) "
"LISTS=1 OP_TYPE 'vector_l2_ops' ASYNC")
print('ready-before-alter', wait_counts(cur, 'ready_t', 1, 2))
run(cur, 'ready-alter', 'ALTER TABLE ready_t ADD COLUMN x INT DEFAULT 0')
print('ready-after-alter', wait_counts(cur, 'ready_t', 1, 2))
run(cur, 'ready-ann',
"SELECT id FROM ready_t ORDER BY l2_distance(v,'[5,6]') "
"LIMIT 2 BY RANK WITH OPTION 'mode=post'")
# Failure: ALTER immediately, while the deferred build is still pending.
cur.execute('CREATE TABLE pending_t(id INT PRIMARY KEY,v VECF32(2))')
cur.execute("INSERT INTO pending_t VALUES(1,'[1,2]')")
cur.execute("CREATE INDEX ivf USING ivfflat ON pending_t(v) "
"LISTS=1 OP_TYPE 'vector_l2_ops' ASYNC")
run(cur, 'pending-immediate-alter',
'ALTER TABLE pending_t ADD COLUMN x INT DEFAULT 0')
run(cur, 'pending-insert',
"INSERT INTO pending_t(id,v,x) VALUES(2,'[3,4]',2)")
print('pending-after-alter',
wait_counts(cur, 'pending_t', 1, 2, timeout=30))
run(cur, 'pending-ann',
"SELECT id FROM pending_t ORDER BY l2_distance(v,'[5,6]') "
"LIMIT 2 BY RANK WITH OPTION 'mode=post'")
run(cur, 'pending-force',
"SELECT id FROM pending_t ORDER BY l2_distance(v,'[5,6]') "
"LIMIT 2 BY RANK WITH OPTION 'mode=force'")
run(cur, 'pending-init-sql', """
SELECT LENGTH(JSON_UNQUOTE(JSON_EXTRACT(job_spec,'$.InitSQL'))),
watermark,job_status
FROM mo_catalog.mo_iscp_log
WHERE table_id IN (
SELECT rel_id FROM mo_catalog.mo_tables
WHERE reldatabase='qa_ivf_add_ready' AND relname='pending_t')
AND drop_at IS NULL
""")
Observed output:
ready-before-alter: {'metadata': 3, 'centroids': 1, 'entries': 2}
ready-alter: OK
ready-after-alter: {'metadata': 3, 'centroids': 1, 'entries': 2}
ready-ann: (2),(1)
pending-immediate-alter: OK
pending-insert: OK
pending-after-alter: {'metadata': 3, 'centroids': 0, 'entries': 0}
pending-ann: ()
pending-force: (2),(1)
pending InitSQL length: 0
In an independent reproduction, SHOW INDEX STATUS still reported running with Error_message=NULL, the base table contained both committed rows, and the replacement job's watermark advanced while centroids and entries remained zero. A second fresh database produced the same result.
Expected behavior
COPY ALTER must preserve or restart pending IVFFLAT training. Once the ALTER succeeds, the replacement index must eventually contain the source rows and return ANN results consistent with the exact-scan control. If initialization cannot safely be preserved, the ALTER should fail explicitly or the index should remain ineligible for indexed ANN until it is rebuilt; a running, error-free, permanently empty index is incorrect.
Code analysis and controls
pkg/sql/compile/alter.go handles an unaffected IVFFLAT index through AlterCopyInitSQL. At the tested commit, pkg/vectorindex/ivfflat/plugin/compile/compile.go returns an empty initialization SQL for this path, assuming metadata and centroids were cloned and entries can be rebuilt from the source log.
That assumption is false before initial training: the pending source has no centroids to clone. The replacement therefore has neither a model nor an ivf_create initialization statement. Replay can advance its watermark, but cannot create the missing centroids/entries.
Controls distinguish this from a general COPY ALTER problem:
- Waiting for centroids/entries before the identical
ADD COLUMNpreserves the model and correct ANN results. - A no-ALTER ASYNC IVFFLAT control builds normally.
- Immediate
TRUNCATE TABLEfollowed by reinsertion also rebuilds correctly.
This also differs from the pending-RENAME defect: RENAME leaves stale non-empty InitSQL and repeated visible worker errors; COPY ALTER discards the pending initialization and registers empty InitSQL, with an advancing watermark and no error.
Duplicate check
Searched IVFFLAT COPY ALTER, ASYNC ADD COLUMN, empty InitSQL, and missing centroids/entries. #31611 concerns COPY ALTER itself failing during concurrent HNSW initialization; #29042 concerns PRE membership after an already-built IVFFLAT index is copied; #28837 concerns FULLTEXT2. None covers this pending-IVFFLAT empty-training path.
- Lenguaje dominante
- Go
- Estrellas
- 1.9k
- Forks
- 312
- Merge medio
- 22 h 59 min
- PR fusionados (30 d)
- 736
Preparar el entorno
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de matrixorigin/matrixone
-
kind/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
matrixorigin/matrixone#33363 ·
Los mantenedores suelen responder en 1 día
-
kind/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
matrixorigin/matrixone#33362 ·
Los mantenedores suelen responder en 1 día
-
SLEEP rejects NULL and negative durations that MySQL acceptsPosiblemente ocupada @XuPeng-SH la tomó hace 7 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
matrixorigin/matrixone#32653 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: TestChangeWatchProxy loses its first tenant connection during PingContext in Ubuntu CIPosiblemente ocupada @XuPeng-SH la tomó hoy. Abiertokind/bug needs-triage
matrixorigin/matrixone#33371 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[Bug]: TestDaemonClaimSQLRoundTrip exhausts its shared deadline during the stale claim update in Ubuntu CIPosiblemente ocupada @XuPeng-SH la tomó hoy. Abiertokind/bug needs-triage
matrixorigin/matrixone#33370 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de matrixorigin/matrixone
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
pg-sharding/spqr#3314 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
slavakurilyak/awesome-ai-agents#1051 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
google-gemini/gemini-api-cli#247 ·
Los mantenedores suelen responder en 1 día