[Bug]: RENAME during pending ASYNC IVFFLAT initialization leaves a permanently empty index

Open
#33,278 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@cpegeric is already working on this.

Since Nov 26, 2026.

Assessment

This issue has not been assessed yet.

Description

kind/bug severity/s0

Description

Tested on MatrixOne main commit c0cef5c9cce2164fedd201c188bfffe4d2d09a96 (git_version() = c0cef5c), using autocommit and experimental_ivf_index=1. Both the RENAME TABLE and RENAME COLUMN variants were rerun on this commit.

Creating an ASYNC IVFFLAT index and immediately renaming either its source table or its indexed vector column leaves initialization permanently stuck. The visible index remains running with no error, its watermark remains 0-0, its entries table stays empty, and indexed ANN queries return false-empty results while an exact mode=force scan returns the correct rows.

This is specific to pending IVFFLAT initialization. A no-rename IVFFLAT control builds successfully, and renaming after initialization also works.

Minimal reproduction: RENAME TABLE

The following script uses only autocommit DDL; no transactional-DDL behavior is required. It includes a no-rename control and queries the hidden entries table through mo_catalog.mo_indexes.

Runnable 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_async_rename_auto'

def fetch(cur, sql, params=None):
    cur.execute(sql, params)
    return cur.fetchall() if cur.description else ()

def hidden_table(cur, table, kind):
    return 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)
        LIMIT 1
    """, (kind, DB, table))[0][0]

def status(cur, table):
    return fetch(cur, f'SHOW INDEX STATUS FROM {table}')

def wait_built(cur, table, timeout=45):
    entries = hidden_table(cur, table, 'entries')
    deadline = time.time() + timeout
    last = None
    while time.time() < deadline:
        try:
            last = fetch(cur, f'SELECT COUNT(*) FROM {DB}.`{entries}`')[0][0]
            if last > 0:
                return last, status(cur, table)
        except Exception as e:
            last = str(e).splitlines()[0]
        time.sleep(0.25)
    return last, status(cur, table)

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}')

    cur.execute('CREATE TABLE control_t(id INT PRIMARY KEY,v VECF32(2))')
    cur.execute("INSERT INTO control_t VALUES(1,'[1,2]')")
    cur.execute("CREATE INDEX ivf USING ivfflat ON control_t(v) "
                "LISTS=1 OP_TYPE 'vector_l2_ops' ASYNC")
    print('control-build', wait_built(cur, 'control_t'))

    cur.execute('CREATE TABLE t(id INT PRIMARY KEY,v VECF32(2))')
    cur.execute("INSERT INTO t VALUES(1,'[1,2]')")
    cur.execute("CREATE INDEX ivf USING ivfflat ON t(v) "
                "LISTS=1 OP_TYPE 'vector_l2_ops' ASYNC")
    cur.execute('RENAME TABLE t TO t_new')

    print('rename-initial-status', status(cur, 't_new'))
    print('rename-build', wait_built(cur, 't_new', timeout=30))
    cur.execute("INSERT INTO t_new VALUES(2,'[2,3]')")
    time.sleep(2)
    print('rename-final-status', status(cur, 't_new'))
    print('iscp-log', fetch(cur, """
        SELECT job_state,watermark,job_status
        FROM mo_catalog.mo_iscp_log
        WHERE table_id IN (
          SELECT rel_id FROM mo_catalog.mo_tables
          WHERE reldatabase=%s AND relname='t_new')
          AND drop_at IS NULL
    """, (DB,)))
    for mode in ('post', 'force'):
        print(mode, fetch(cur,
            "SELECT id FROM t_new ORDER BY l2_distance(v,'[2,3]') "
            f"LIMIT 2 BY RANK WITH OPTION 'mode={mode}'"))

Observed output, abbreviated to the relevant fields:

control-build:         entries=1
rename-build:          entries=0 after 30 seconds
rename-final-status:   running, Error_message=NULL
iscp watermark:        0-0, job_status.ErrorMsg=''
mode=post:             ()
mode=force:            (2),(1)

The service log repeatedly retries ivf_create and reports:

invalid input: index maintenance config does not match its owner

Thus the empty index is not a normal build delay.

RENAME COLUMN variant

The same failure occurs when the indexed vector column is renamed while initialization is pending:

SET experimental_ivf_index=1;
CREATE DATABASE qa_ivf_async_rename_col;
USE qa_ivf_async_rename_col;

CREATE TABLE t(id INT PRIMARY KEY, v VECF32(2));
INSERT INTO t VALUES(1,'[1,2]'),(2,'[3,4]');
CREATE INDEX ivf USING IVFFLAT ON t(v)
  LISTS=1 OP_TYPE 'vector_l2_ops' ASYNC;

-- Execute immediately, before the asynchronous build completes.
ALTER TABLE t RENAME COLUMN v TO v2;
INSERT INTO t VALUES(3,'[5,6]');

-- After waiting 30 seconds:
-- entries=0, watermark=0-0, STATUS=running, Error_message=NULL
SELECT id FROM t ORDER BY l2_distance(v2,'[5,6]')
LIMIT 3 BY RANK WITH OPTION 'mode=post';
-- actual: empty

SELECT id FROM t ORDER BY l2_distance(v2,'[5,6]')
LIMIT 3 BY RANK WITH OPTION 'mode=force';
-- actual: 3,2,1

In this variant, the worker keeps generating sampling SQL for the removed column v and repeatedly reports column v does not exist.

Expected behavior

RENAME must atomically update all state needed by a pending index build. Initialization must finish against the renamed table/column and subsequent ANN queries must include the committed rows. If a rename cannot safely be supported during initialization, the DDL should fail explicitly; it must not succeed while leaving a healthy-looking index that returns false-empty results indefinitely.

Code analysis and controls

For ASYNC creation, pkg/vectorindex/ivfflat/plugin/compile/compile.go captures the original source table and vector key in the deferred ivf_create InitSQL.

  • RENAME TABLE: pkg/iscp/watermark_updater.go updates the registered table/source fields but does not rewrite the source name embedded in InitSQL. pkg/vectorindex/maintenance_config.go then rejects the stale source during owner validation.
  • RENAME COLUMN: live IndexDef.Parts is updated, but the deferred ivf_create still samples the old KeyPart.

Controls used to isolate the pending-IVFFLAT path:

  • No-rename ASYNC IVFFLAT builds successfully.
  • RENAME TABLE/COLUMN after IVFFLAT initialization succeeds and later DML is indexed.
  • Immediate RENAME with ASYNC HNSW succeeds.
  • Immediate RENAME with classic FULLTEXT and FULLTEXT2 succeeds.

Duplicate check

Searched IVFFLAT ASYNC RENAME, RENAME COLUMN, stale InitSQL, and the two error strings. #30275 is HNSW COPY ALTER with duplicate-key CDC retries; #29042 concerns PRE membership on an already-built IVFFLAT index after physical copy. Neither covers stale deferred initialization caused by RENAME.

Dominant language
Go
Stars
1.9k
Forks
312
Avg merge
22h 59m
Merged PRs (30d)
736

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from matrixorigin/matrixone

All issues in matrixorigin/matrixone

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.