Repository navigation
feat(mysql): type vector columns and parameters as number[] - #8
Merged
Merged
Conversation
A MySQL 9 VECTOR was unknown, so a number[] parameter type-checked and then failed on every driver. A parameter is now wrapped in to_vector() and bound as the text of its floats, which also works on the drivers that write values into the statement's text, where bytes compared with a vector are refused.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This review covers the first pass over MySQL 9 VECTOR support: typing, binding, decoding and docs.
- Engine typing:
column_typemaps protocol type 242 to an array of non-nullfloat4, for columns and for?parameters typed by context. to_vector(?)rewrite:vectors_as_textwraps each 242-typed?aftersettleand the cardinality pass have used the unwrapped text. Its spans line up withraw.params, assettlealready assumes. The structured-parameter span remap inengine/core/src/structured.rsworks from span deltas, so it absorbs the added length.- Parameter encoding: on MySQL,
encodesends an array parameter as its JSON text throughvectorText.VECTORis the onlyType::Arraythe MySQL engine produces, so no other parameter takes this path.NaN, the infinities and non-numbers are refused, and null elements are already caught bynullElement. MySQL'sSTRING_TO_VECTORaccepts scientific notation, soJSON.stringify's1e-7form is safe. - Decoding:
byKind("float[]")routes vector columns throughcoerce. AUint8Array(mariadb's, and PlanetScale's viabytesOffor charset 63) is read as little-endian float32s, honouringbyteOffset. mysql2's decoded arrays and Bun.sql's PostgresFloat32Arraygo down the existing paths, unchanged. - Docs: the
VECTORrows, a Vectors section and theBun.sqllimitation on the MySQL page, plus a row in the shared data types table.
claude-opus-5-5 | 𝕏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

MySQL 9's
VECTOR(protocol type 242) was typedunknown, so anumber[]parameter type-checked and then failed at run time on every driver.What changes
engine/mysql/src/mysql.rs): type 242 is an array offloat4whose elements are never null, for a column and for a?the prepare types from its context. Each such?is sent asto_vector(?), and the map back to the author's text keeps the placeholder's place.number[]on every driver that reads one. mysql2 decodes the floats itself; mariadb and PlanetScale hand over the little-endian bytes, whichsrc/values.tsreads. A parameter is bound as the JSON text of its floats. A non-number element,NaNor an infinity is refused before the statement runs, with the parameter named.packages/mysql/engine.wasmrebuilt.Why text and not bytes
All three driver paths bind bytes for an insert. But mariadb and PlanetScale write values into the statement's text, where bytes are a binary string, and MySQL refuses one beside
=with a vector (Incorrect arguments to =).to_vector('[…]')works in every position on every driver.Verified
.sqlimport type-checks as{ id: number; v: number[]; vn: number[] | null }, and a string element is a type error. Inserts,where v = :v, NULL vectors and reads all round-trip, and the stored values matchvector_to_string.VECTORat all (ERR_MYSQL_UNSUPPORTED_COLUMN_TYPE, and the connection closes); the docs say so.RESULTS.mdonly in the 24 S11 round-trip rows thatmainalready fails.VECTOR, so CI covers this through the engine and loader unit tests.