Skip to content

Fix bvt test for async index update - #22796

Merged
fengttt merged 7 commits into
matrixorigin:mainfrom
cpegeric:fixbvt
Nov 8, 2025
Merged

fengttt merged 7 commits into
matrixorigin:mainfrom
cpegeric:fixbvt

Conversation

@cpegeric

@cpegeric cpegeric commented Nov 7, 2025 •

Copy link
Copy Markdown
Contributor

User description

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #22794 #22792 #22780

What this PR does / why we need it:

  • disable some failed bvt test because of the async behaviour
  • disable bvt test that potentially cause w-w conflict
  • fix the ivf search bug when score is NULL.

PR Type

Bug fix, Tests


Description

  • Fix IVFFlat search to handle NULL distance scores correctly

  • Remove unnecessary NULL check on entry column in search query

  • Skip problematic async index tests due to write-write conflicts

  • Adjust test parameters and timing for async operations

  • Add issue annotations to test cases for tracking


Diagram Walkthrough

flowchart LR
  A["IVFFlat Search Query"] -->|Remove entry NULL check| B["Simplified WHERE clause"]
  B -->|Add result filtering| C["Skip NULL distances in results"]
  D["Async Index Tests"] -->|Add issue markers| E["Mark problematic tests"]
  D -->|Adjust parameters| F["Increase probe_limit and sleep duration"]
  D -->|Remove conflicting queries| G["Skip write-write conflict cases"]
Loading

File Walkthrough

Relevant files
Bug fix
1 files
search.go
Handle NULL distance scores in search results                       
+6/-2     
Tests
10 files
vector_ivf_async.sql
Adjust async test parameters and remove conflicting query
+2/-4     
vector_ivf_async.result
Update expected results for adjusted async tests                 
+4/-6     
vector_hnsw.sql
Add issue markers for async conflict tests                             
+5/-0     
vector_hnsw_f64.sql
Add issue markers for async conflict tests                             
+5/-0     
vector_hnsw_async.sql
Add issue markers and comments for async tests                     
+5/-0     
vector_hnsw_f64_async.sql
Add issue markers and comments for async tests                     
+5/-0     
vector_hnsw.result
Update formatting and expected results                                     
+15/-0   
vector_hnsw_f64.result
Update formatting and expected results                                     
+15/-0   
vector_hnsw_async.result
Update formatting for async test results                                 
+5/-0     
vector_hnsw_f64_async.result
Update formatting for async test results                                 
+5/-0     

@qodo-code-review

qodo-code-review Bot commented Nov 7, 2025 •

Copy link
Copy Markdown

PR Compliance Guide 🔍

(Compliance updated until commit 94a33bb)

Below is a summary of compliance checks for this PR:

Security Compliance
⚪
SQL injection

Description: The SQL query string is constructed via fmt.Sprintf with interpolated identifiers and
values, risking SQL injection if any inputs (e.g., table names, list contents, or
ArrayToString(query)) can be influenced by untrusted sources; parameterization or proper
escaping should be verified.
search.go [166-178]

Referred Code
sql := fmt.Sprintf(
	"SELECT `%s`, %s(`%s`, '%s') as vec_dist FROM `%s`.`%s` WHERE `%s` = %d AND `%s` IN (%s) ORDER BY vec_dist LIMIT %d",
	catalog.SystemSI_IVFFLAT_TblCol_Entries_pk,
	metric.MetricTypeToDistFuncName[metric.MetricType(idxcfg.Ivfflat.Metric)],
	catalog.SystemSI_IVFFLAT_TblCol_Entries_entry,
	types.ArrayToString(query),
	tblcfg.DbName, tblcfg.EntriesTable,
	catalog.SystemSI_IVFFLAT_TblCol_Entries_version,
	idx.Version,
	catalog.SystemSI_IVFFLAT_TblCol_Entries_id,
	instr,
	rt.Limit,
)
Ticket Compliance
⚪
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
⚪
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

⚪
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
Missing logging: The new logic that skips NULL vector distances and changes the SQL query does not add any
audit logging for critical search operations, leaving uncertainty about audit trail
completeness.

Referred Code
sql := fmt.Sprintf(
	"SELECT `%s`, %s(`%s`, '%s') as vec_dist FROM `%s`.`%s` WHERE `%s` = %d AND `%s` IN (%s) ORDER BY vec_dist LIMIT %d",
	catalog.SystemSI_IVFFLAT_TblCol_Entries_pk,
	metric.MetricTypeToDistFuncName[metric.MetricType(idxcfg.Ivfflat.Metric)],
	catalog.SystemSI_IVFFLAT_TblCol_Entries_entry,
	types.ArrayToString(query),
	tblcfg.DbName, tblcfg.EntriesTable,
	catalog.SystemSI_IVFFLAT_TblCol_Entries_version,
	idx.Version,
	catalog.SystemSI_IVFFLAT_TblCol_Entries_id,
	instr,
	rt.Limit,
)

//fmt.Println("IVFFlat SQL: ", sql)
//os.Stderr.WriteString(sql)
//os.Stderr.WriteString("\n")

res, err := runSql(sqlproc, sql)
if err != nil {
	return


 ... (clipped 20 lines)
Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Edge-case handling: While NULL distances are now filtered client-side, no explicit error/context is provided
for cases where all candidates are NULL or when the distance function fails, which may
hinder debugging.

Referred Code
for _, bat := range res.Batches {
	for i := 0; i < bat.RowCount(); i++ {
		if bat.Vecs[1].IsNull(uint64(i)) {
			continue
		}

		pk := vector.GetAny(bat.Vecs[0], i, true)
Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
SQL construction: The SQL string is built via fmt.Sprintf with interpolated values (e.g., query vector
string and IN list), and while these may be trusted/internal, the lack of parameterization
in the added code warrants verification against injection risks.

Referred Code
sql := fmt.Sprintf(
	"SELECT `%s`, %s(`%s`, '%s') as vec_dist FROM `%s`.`%s` WHERE `%s` = %d AND `%s` IN (%s) ORDER BY vec_dist LIMIT %d",
	catalog.SystemSI_IVFFLAT_TblCol_Entries_pk,
	metric.MetricTypeToDistFuncName[metric.MetricType(idxcfg.Ivfflat.Metric)],
	catalog.SystemSI_IVFFLAT_TblCol_Entries_entry,
	types.ArrayToString(query),
	tblcfg.DbName, tblcfg.EntriesTable,
	catalog.SystemSI_IVFFLAT_TblCol_Entries_version,
	idx.Version,
	catalog.SystemSI_IVFFLAT_TblCol_Entries_id,
	instr,
	rt.Limit,
)
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

Previous compliance checks

Compliance check up to commit 16b11bc
Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
⚪
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
⚪
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

⚪
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
Critical actions unlogged: The new branch that skips null vector distances and the changed SQL querying path
introduce conditional behavior without any added logging for who/what/when, making audit
trails for search results and NULL handling unclear.

Referred Code
for _, bat := range res.Batches {
	for i := 0; i < bat.RowCount(); i++ {
		if bat.Vecs[1].IsNull(uint64(i)) {
			continue
		}

		pk := vector.GetAny(bat.Vecs[0], i, true)
Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Null handling gap: The SQL removed the IS NOT NULL filter and later skips rows where Vecs[1] is null without
surfacing context or metrics, which may silently change result counts without error or
warning.

Referred Code
sql := fmt.Sprintf(
	"SELECT `%s`, %s(`%s`, '%s') as vec_dist FROM `%s`.`%s` WHERE `%s` = %d AND `%s` IN (%s) ORDER BY vec_dist LIMIT %d",
	catalog.SystemSI_IVFFLAT_TblCol_Entries_pk,
	metric.MetricTypeToDistFuncName[metric.MetricType(idxcfg.Ivfflat.Metric)],
	catalog.SystemSI_IVFFLAT_TblCol_Entries_entry,
	types.ArrayToString(query),
	tblcfg.DbName, tblcfg.EntriesTable,
	catalog.SystemSI_IVFFLAT_TblCol_Entries_version,
	idx.Version,
	catalog.SystemSI_IVFFLAT_TblCol_Entries_id,
	instr,
	rt.Limit,
)
Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status:
Internal error text: Tests assert on messages like "internal error: malformed vector input: abc"
which may reveal internal details if surfaced to end users; unclear from diff whether
these are user-facing or test-internal.

Referred Code
select * from vector_index_07 order by  L2_DISTANCE(b, "abc") ASC LIMIT 2;
internal error: malformed vector input: abc
create table vector_index_08(a bigint auto_increment primary key, b vecf32(128),c int,key c_k(c));
Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
SQL construction risk: The SQL string is built via fmt.Sprintf embedding types.ArrayToString(query) and instr
without visible parameterization or sanitization in this diff, which could pose injection
risks depending on upstream validation.

Referred Code
sql := fmt.Sprintf(
	"SELECT `%s`, %s(`%s`, '%s') as vec_dist FROM `%s`.`%s` WHERE `%s` = %d AND `%s` IN (%s) ORDER BY vec_dist LIMIT %d",
	catalog.SystemSI_IVFFLAT_TblCol_Entries_pk,
	metric.MetricTypeToDistFuncName[metric.MetricType(idxcfg.Ivfflat.Metric)],
	catalog.SystemSI_IVFFLAT_TblCol_Entries_entry,
	types.ArrayToString(query),
	tblcfg.DbName, tblcfg.EntriesTable,
	catalog.SystemSI_IVFFLAT_TblCol_Entries_version,
	idx.Version,
	catalog.SystemSI_IVFFLAT_TblCol_Entries_id,
	instr,
	rt.Limit,
)

@matrix-meow matrix-meow added size/M Denotes a PR that changes [100,499] lines and removed size/S Denotes a PR that changes [10,99] lines labels Nov 7, 2025

This branch was previously deployed

1 inactive deployment
ci — 94a33bb5 Deployed Nov 8, 2025 by fengttt
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 Review effort 2/5 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants