Skip to content

Vector Distance Crash Tests Grammar - #438

Open
saikumar-vs wants to merge 7 commits into
masterfrom
vector_branch1
Open

Vector Distance Crash Tests Grammar#438
saikumar-vs wants to merge 7 commits into
masterfrom
vector_branch1

Conversation

@saikumar-vs

@saikumar-vs saikumar-vs commented Jul 28, 2026

Copy link
Copy Markdown
Contributor
  • Introduced init_vectors.sql to correct vector dimensions and ensure all required IDs are represented for testing.
  • Added README.md to provide guidance on the usage and structure of the new grammar files.
  • Created vector_distance.yy for extended RQG grammar, covering various error paths and valid queries for VECTOR_DISTANCE.
  • Included vector_distance.zz as a companion gendata file to support the new grammar.

Steps to Test : perl runall-new.pl --post-gendata-sql=$PWD/conf/vector_1/init_vectors.sql --basedir= --grammar=conf/vector_1/vector_distance.yy --gendata=conf/vector_1/vector_distance.zz --threads=4 --queries=50000 --duration=600 --reporter=Shutdown,Backtrace,ErrorLog,QueryTimeout --debug --sqltrace

- Introduced `init_vectors.sql` to correct vector dimensions and ensure all required IDs are represented for testing.
- Added `README.md` to provide guidance on the usage and structure of the new grammar files.
- Created `vector_distance.yy` for extended RQG grammar, covering various error paths and valid queries for VECTOR_DISTANCE.
- Included `vector_distance.zz` as a companion gendata file to support the new grammar.

These changes enhance regression testing capabilities for vector distance calculations in the Percona Server.
This reverts commit e3c8e11.
- Introduced `init_vectors.sql` to correct vector dimensions and ensure all required IDs are represented for testing.
- Added `README.md` to provide guidance on the usage and structure of the new grammar files.
- Created `vector_distance.yy` for extended RQG grammar, covering various error paths and valid queries for VECTOR_DISTANCE.
- Included `vector_distance.zz` as a companion gendata file to support the new grammar.

These changes enhance regression testing capabilities for vector distance calculations in the Percona Server.
Adds Random Query Generator (RQG) assets to fuzz the new native
DISTANCE() and VECTOR_DISTANCE() functions in Percona Server.

* vector_distance2.yy: Grammar rules to fuzz function parameters,
  validate compile-time metric constants, and test runtime dimension
  enforcement.
* vector_distance2.sql: Table definitions and seed data including
  3D, 4D, and 16D vectors to trigger both narrow and wide SIMD
  dispatch routes.

Includes specific boundary conditions for NULL propagation, zero
vectors, and extreme FLT_MAX float32 values (which intentionally
trigger ERROR 1690 due to IEEE 754 limitations during intermediate
SIMD subtraction).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new Random Query Generator (RQG) “kit” under randgen/conf/vector_distance/ intended to fuzz-test Percona Server’s VECTOR_DISTANCE/DISTANCE behavior using a dedicated schema/data initializer, a grammar file, and a minimal gendata companion.

Changes:

  • Added an extended RQG grammar (vector_distance.yy) to exercise valid paths and multiple error paths for vector distance functions.
  • Added init_vectors.sql to create/populate test.vt with representative IDs/dimensions/anomaly vectors needed by the grammar.
  • Added documentation (README.md) and a companion gendata file (vector_distance.zz), plus an additional “v2” grammar+SQL pair (vector_distance2.yy/.sql).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
randgen/conf/vector_distance/vector_distance.yy New extended grammar for VECTOR_DISTANCE/DISTANCE fuzz coverage.
randgen/conf/vector_distance/init_vectors.sql Creates/populates test.vt with specific IDs and vector shapes for grammar stability.
randgen/conf/vector_distance/vector_distance.zz Minimal gendata file; currently documents schema creation incorrectly.
randgen/conf/vector_distance/README.md Usage guide; currently misstates how vt is created and omits init_vectors.sql in the “files” list.
randgen/conf/vector_distance/vector_distance2.yy Additional grammar; contains SQL-generation issues (e.g., missing FROM, incorrect TO_VECTOR usage).
randgen/conf/vector_distance/vector_distance2.sql Companion schema/data for vector_distance2.yy.
Comments suppressed due to low confidence (4)

randgen/conf/vector_distance/README.md:22

  • This section claims the vt schema is created in a query_init rule, but vector_distance.yy does not define query_init and the run instructions rely on init_vectors.sql via --post-gendata-sql. The description should match the actual setup mechanism.
Since this grammar needs `VECTOR`-typed columns (which `--gendata`'s built-in generator doesn't produce), it defines its own literal table (`vt`) with explicit columns in `query_init`, rather than using `_table`/`_field`. This is consistent with how `example.yy` itself falls back to literal SQL identifiers where the built-in generators don't fit.

randgen/conf/vector_distance/vector_distance2.yy:4

  • CREATE TABLE t_vec AS SELECT distance_func AS dist ; has no FROM clause. If distance_func expands to v3/v4/v16 (via vector_expr -> vector_col), this will fail with an unknown-column error rather than exercising VECTOR_DISTANCE/DISTANCE behavior.
      | CREATE TABLE t_vec AS SELECT distance_func AS dist ;

randgen/conf/vector_distance/vector_distance2.yy:21

  • TO_VECTOR ( 'vector_string' ) uses a literal string "vector_string" rather than expanding the vector_string rule, so it won’t generate the intended vector literals.
      | TO_VECTOR ( 'vector_string' )

randgen/conf/vector_distance/vector_distance2.yy:51

  • vector_string alternatives are not quoted, so after switching to TO_VECTOR(vector_string) they would expand to TO_VECTOR([0.1,...]), which is invalid SQL. These should be SQL string literals like TO_VECTOR('[0.1,...]').
        [0.1, 0.2, 0.3]
      | [1.5, 2.5, 3.5, 4.5]
      | [0.0, 0.0, 0.0]
      | [3.4028235E38, 3.4028235E38, 3.4028235E38]
      | [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7] ;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3 to +6
Two files, meant to be dropped into your own RQG checkout:

- `vector_distance.yy` — the query grammar
- `vector_distance.zz` — a minimal companion gendata file
Comment on lines +4 to +6
# The actual VECTOR-typed schema (table `vt`) is built inside the grammar's
# query_init rule, since RQG's built-in data generator predates support for
# the VECTOR column type and cannot declare VECTOR(n) columns natively.

-- ids 1, 2: original rows from the uploaded file, UNCHANGED, including the
-- under-width v384 (3 elements in a VECTOR(384) column). Kept deliberately as
-- a documented edge case: STRING_TO_VECTOR(v384) here vs v3 will NOT raise a
Comment on lines +1 to +2
query:
SELECT distance_func FROM vector_test LIMIT _digit ;

@vinperothas vinperothas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi Sai, Thanks for putting this together! The RQG grammar coverage for the VECTOR_DISTANCE edge cases looks really solid, and I appreciate the thoroughness of the boundary tests.

I did notice that the README.md and some of the block comments in init_vectors.sql (like the notes about 'our manual testing session' and 'your actual checkout') read a bit like a conversational chat rather than standard documentation.

Could we polish the README and the SQL comments to be more objective? Stripping out the conversational framing will make it a much cleaner guide

_bad_byte_literal:
0x0102030405 | 0x010203 | 0x0102030405060708090A | 0x01 ;

# Base Standard Vector Generators

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Impressive use of inline perl 👍

- Alternatives are `|`-separated, and may span multiple lines
- Underscore-prefixed tokens (`_table`, `_field`, `_digit`) are RQG's built-in generators, tied to whatever `--gendata` builds

Since this grammar needs `VECTOR`-typed columns (which `--gendata`'s built-in generator doesn't produce), it defines its own literal table (`vt`) with explicit columns in `query_init`, rather than using `_table`/`_field`. This is consistent with how `example.yy` itself falls back to literal SQL identifiers where the built-in generators don't fit.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shall be updated that the schema is created inside init_vectors.sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants