Skip to content

[Bug]: panic when searching IVF-Flat entries table #23834

@iamlinjunhong

Description

@iamlinjunhong

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

3.0-dev

Commit ID

aea3d3f

Other Environment Information

- Hardware parameters:
- OS type:
- Others:

Actual Behavior

internal error: panic runtime error: index out of range [2] with length 2:
runtime.goPanicIndex
/Users/linjunhong/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.4.darwin-arm64/src/runtime/panic.go:115
github.com/matrixorigin/matrixone/pkg/sql/colexec.(*ColumnExpressionExecutor).Eval
/Users/linjunhong/workspace/matrixone/pkg/sql/colexec/evalExpression.go:690
github.com/matrixorigin/matrixone/pkg/sql/colexec.(*Projection).EvalProjection
/Users/linjunhong/workspace/matrixone/pkg/sql/colexec/evalProjection.go:56
github.com/matrixorigin/matrixone/pkg/sql/colexec/table_scan.(*TableScan).ExecProjection
/Users/linjunhong/workspace/matrixone/pkg/sql/colexec/table_scan/types.go:124
github.com/matrixorigin/matrixone/pkg/vm.Exec
/Users/linjunhong/workspace/matrixone/pkg/vm/types.go:518
github.com/matrixorigin/matrixone/pkg/vm.ChildrenCall
/Users/linjunhong/workspace/matrixone/pkg/vm/types.go:525
github.com/matrixorigin/matrixone/pkg/sql/colexec/top.(*Top).Call
/Users/linjunhong/workspace/matrixone/pkg/sql/colexec/top/top.go:110
github.com/matrixorigin/matrixone/pkg/vm.Exec

Expected Behavior

no panic

Steps to Reproduce

CREATE DATABASE IF NOT EXISTS vec_top_panic_repro_db;
USE vec_top_panic_repro_db;
set enable_vector_prefilter_by_default = 1;
set ivf_threads_search = 1;
set probe_limit = 2;
DROP TABLE IF EXISTS mem_memories;
CREATE TABLE mem_memories (
memory_id varchar(64) NOT NULL,
user_id varchar(64) NOT NULL,
session_id varchar(64) DEFAULT NULL,
memory_type varchar(20) NOT NULL,
content text NOT NULL,
initial_confidence float NOT NULL,
trust_tier varchar(10) DEFAULT NULL,
embedding vecf32(384) DEFAULT NULL,
source_event_ids json NOT NULL,
superseded_by varchar(64) DEFAULT NULL,
is_active smallint NOT NULL DEFAULT '1',
observed_at datetime(6) NOT NULL,
created_at datetime(6) NOT NULL,
updated_at datetime(6) DEFAULT NULL,
PRIMARY KEY (memory_id),
KEY idx_memory_user_session (user_id,session_id),
KEY idx_memory_superseded_by (superseded_by),
KEY idx_memory_user_active (user_id,is_active),
FULLTEXT ft_memory_content(content) WITH PARSER ngram,
KEY idx_memory_observed_at (observed_at),
KEY idx_memory_user_active_type_observed (user_id,is_active,memory_type,observed_at),
KEY idx_memory_user_type_active (user_id,memory_type,is_active),
KEY idx_memory_embedding USING ivfflat (embedding) lists = 10 op_type 'vector_l2_ops'
);
set @vec_seed = '[0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,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.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]';
INSERT INTO mem_memories (
memory_id, user_id, session_id, memory_type, content,
initial_confidence, trust_tier, embedding, source_event_ids,
superseded_by, is_active, observed_at, created_at, updated_at
)
SELECT
concat('seed_', result),
'u_seed',
's_seed',
'episodic',
concat('seed content ', result),
0.9,
'high',
@vec_seed,
cast('[]' as json),
NULL,
1,
now(6),
now(6),
now(6)
FROM generate_series(1, 12000) g;
SELECT mo_ctl('dn', 'flush', 'vec_top_panic_repro_db.mem_memories');
➤ mo_ctl(dn, flush, vec_top_panic_repro_db.mem_memories)[12,-1,0]  𝄀
{
  "method": "Flush",
  "result": [
    {
      "returnStr": "OK"
    }
  ]
}

SELECT mo_ctl('dn', 'checkpoint', '');
➤ mo_ctl(dn, checkpoint, )[12,-1,0]  𝄀
{
  "method": "Checkpoint",
  "result": [
    {
      "returnStr": "OK"
    }
  ]
}

prepare p_mem from 'SELECT mem_memories.memory_id AS mem_memories_memory_id, mem_memories.content AS mem_memories_content, mem_memories.initial_confidence AS mem_memories_initial_confidence, l2_distance(mem_memories.embedding, ?) AS l2_dist FROM mem_memories WHERE mem_memories.user_id = ? AND mem_memories.is_active = ? AND mem_memories.memory_type = ? AND mem_memories.embedding IS NOT NULL AND mem_memories.memory_id != ? ORDER BY l2_dist LIMIT ?';
set @u = 'u_miss';
set @a = 1;
set @t = 'episodic';
set @m = 'none';
set @l = 1;
execute p_mem using @vec_q, @u, @a, @t, @m, @l;
➤ mem_memories_memory_id[12,-1,0]  ¦  mem_memories_content[12,0,0]  ¦  mem_memories_initial_confidence[7,24,0]  ¦  l2_dist[8,9,0]
set @tbl_id = (
select rel_id
from mo_catalog.mo_tables
where relname = 'mem_memories' and reldatabase = 'vec_top_panic_repro_db'
limit 1
);
set @entries_tbl = (
select index_table_name
from mo_catalog.mo_indexes
where table_id = @tbl_id
and name = 'idx_memory_embedding'
and algo = 'ivfflat'
and algo_table_type = 'entries'
limit 1
);
select @entries_tbl;
➤ @entries_tbl[12,0,0]  𝄀
__mo_index_secondary_019cd229-4f79-75e7-a88b-98ebdbaf3ab3
set @ins_entries_sql = concat(
'INSERT INTO `', @entries_tbl, '`(`__mo_index_centroid_fk_version`,`__mo_index_centroid_fk_id`,`__mo_index_pri_col`,`__mo_index_centroid_fk_entry`) ',
'SELECT 922337203685477500, 1, concat(''null_inmem_'', result), NULL FROM generate_series(1, 12000) g'
);
prepare p_ins_entries from @ins_entries_sql;
execute p_ins_entries;
deallocate prepare p_ins_entries;
set @entries_sql = concat(
'SELECT __mo_index_pri_col, ',
'L2_DISTANCE(__mo_index_centroid_fk_entry, ''', @vec_q, ''') AS vec_dist ',
'FROM `', @entries_tbl, '` ',
'ORDER BY vec_dist LIMIT 1'
);
prepare p_entries from @entries_sql;
execute p_entries;

Additional information

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions