Vector Distance Crash Tests Grammar - #438
Conversation
- 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.
This reverts commit c20ba2d.
- 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).
There was a problem hiding this comment.
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.sqlto create/populatetest.vtwith 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
vtschema is created in aquery_initrule, but vector_distance.yy does not definequery_initand 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. Ifdistance_funcexpands tov3/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 thevector_stringrule, so it won’t generate the intended vector literals.
| TO_VECTOR ( 'vector_string' )
randgen/conf/vector_distance/vector_distance2.yy:51
vector_stringalternatives are not quoted, so after switching toTO_VECTOR(vector_string)they would expand toTO_VECTOR([0.1,...]), which is invalid SQL. These should be SQL string literals likeTO_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.
| 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 |
| # 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 |
| query: | ||
| SELECT distance_func FROM vector_test LIMIT _digit ; |
vinperothas
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Shall be updated that the schema is created inside init_vectors.sql
init_vectors.sqlto correct vector dimensions and ensure all required IDs are represented for testing.README.mdto provide guidance on the usage and structure of the new grammar files.vector_distance.yyfor extended RQG grammar, covering various error paths and valid queries for VECTOR_DISTANCE.vector_distance.zzas 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