Skip to content

PHP crashes when processing a MySQL DB query with a new Vector format introduced in MySQL 9.0 #15432

Closed
@richloh

Description

@richloh

Description

In MySQL version 9, Oracle added support for vector data types.
These are needed for AI-operations and eliminate the need for dedicated vector databases like Weaviate or Pinecone. Postgres also has a similar feature.

When viewing a Mysql response with a vector data type, php crashes.

Steps to reproduce the behavior:

1. Spin up any mysql database with version 9, e.g. using

docker run --rm \
--name mysql-container \
-e MYSQL_ROOT_PASSWORD="" \
-e ALLOW_EMPTY_PASSWORD=yes \
-e MYSQL_DATABASE=test \
-p 3306:3306 \
bitnami/mysql:9.0

2. Run the mysql query

Run the mysql query SELECT STRING_TO_VECTOR("[1.05, -17.8, 32]"). This returns a vector in the new binary Mysql 9 vector format.

Here some sample code for this:

<?php
$conn = new mysqli("127.0.0.1", "root", "", "test");
echo $conn->query('SELECT STRING_TO_VECTOR("[1.05, -17.8, 32]")')->fetch_assoc();

3. Observe output

This is the output that is returned by PHP 8.3.3:

PHP Warning:  mysqli::query(): Unknown type 242 sent by the server. Please send a report to the developers in /home/richard/enneo/test/db.php on line 9
PHP Stack trace:
PHP   1. {main}() /home/richard/enneo/test/db.php:0
PHP   2. mysqli->query($query = 'SELECT STRING_TO_VECTOR("[1.05, -17.8, 32]")') /home/richard/enneo/test/db.php:9

Warning: mysqli::query(): Unknown type 242 sent by the server. Please send a report to the developers in /home/richard/enneo/test/db.php on line 9

Call Stack:
    0.0001     489424   1. {main}() /home/richard/enneo/test/db.php:0
    0.0013     531656   2. mysqli->query($query = 'SELECT STRING_TO_VECTOR("[1.05, -17.8, 32]")') /home/richard/enneo/test/db.php:9

zend_mm_heap corrupted
fish: Job 1, 'php db.php' terminated by signal SIGABRT (Abort)

Expected output

A php data variable that holds the results, preferrably an array of floats with an array length that matches the vector length.
The native mysql client also has this type of output (as of v9).

PHP Version

PHP 8.3.3

Operating System

Ubuntu 22.04

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions