Skip to content

test: Plain-C experiment for placeholder values fetched through a string buffer - #646

Open
krlmlr wants to merge 8 commits into
mainfrom
claude/experiment-638
Open

krlmlr wants to merge 8 commits into
mainfrom
claude/experiment-638

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

An experiment record for #638, as asked on #641. It reduces the problem to plain C against libmariadb and libmysqlclient, with MariaDB 11.8 and MySQL 8.4 servers, and tries fixes in plain C first. There are no package code changes. The record is experiments/2026-11-29-mysql-placeholder-values/README.md, with the C program, the recorded output of each server × client combination, and a copy of the workflow for replication. .github/workflows/experiment-638.yaml runs only on pushes to this branch and is a harness to drop before any fix merges.

Findings (from run 46290841620, reproduced unchanged in run 46291919028):

  • Root cause. RMariaDB binds string result columns with an empty buffer and refetches at the reported length. When a DOUBLE column is bound as a string, both libmariadb and libmysqlclient format the number to fit the buffer and report the length of the text that fit. With buffer_length 0, 1.5 reports length 0 and comes back as ""; 0.1 reports length 1 and comes back as "0". This happens on all four server × client combinations, whenever the column arrives as DOUBLE. Integers, dates, strings and blobs report their full length and come back right.
  • Why MySQL shows it. MySQL reports ? as VAR_STRING at prepare time and the real type (DOUBLE, LONGLONG) only after execution, so RMariaDB binds a string buffer for a DOUBLE value. MariaDB reports NULL at prepare time and the parameter's own type after each execution. A blob parameter comes back from MySQL as a non-binary string.
  • MySQL keeps the type of a reused statement. After an execution with 1.5, it reports DOUBLE for every later set, NULL included, so a later 'abc' comes back as 0 with every fetch strategy. A NULL first set reports the prepare-time type.
  • Fixes in plain C. A 256-byte buffer with a refetch for longer values, rebinding with the post-execute type, STMT_ATTR_UPDATE_MAX_LENGTH with mysql_stmt_store_result(), and an empty buffer with a refetch of at least 64 bytes are all correct on both MariaDB combinations. On MySQL they are correct except for the sticky type (1.5 followed by 'abc'). Only rebinding with the post-execute type plus re-preparing when a parameter changes type is correct on all four combinations in every case.

experiments/ is added to .Rbuildignore. The libmariadb on the MySQL runner comes from Ubuntu via apt-get download, because libmariadb-dev conflicts with mysql-server there.

Accepted limitations

https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ


Generated by Claude Code

Reduce `SELECT ? AS x` returning "" on MySQL 8.4 with libmysqlclient
to a plain-C program against libmariadb and libmysqlclient,
with candidate fixes as variants,
and a push-triggered workflow that runs it on MariaDB and MySQL servers.
The workflow is an experiment harness to drop before any fix merges.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Report the post-execute type of a fresh statement next to a reused one,
add type-changing parameter sequences and an extreme DOUBLE,
and point the libmariadb build at the client headers rather than the server ones.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
A reused statement on MySQL keeps a DOUBLE result type and returns 0 for a later string parameter,
so try preparing the statement again when a parameter changes its type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Add the experiment's README with the method, the findings as quoted excerpts, and how to replicate,
the output of each server and client combination,
and the registry of experiments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
The MariaDB and MySQL runners unpack different Connector/C versions,
from the MariaDB repository and from Ubuntu respectively.
Refresh the package lists before `apt-get download`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Keep a copy of the workflow beside the experiment and point Method and Replicate at it,
since the workflow under .github/workflows/ is dropped before any fix merges.
Qualify the post-execute types MariaDB reports for IF(?, ?, ?), and correct the runner image.
Bound shown()'s buffer, check result metadata and store_result for failure,
and skip a memcpy from a NULL buffer in repro.c.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

Three review rounds. The first found two Mediums: the record had no replication path once the branch workflow is dropped, and a workflow comment misstated the Connector/C versions. It also found some Lows in repro.c. All are fixed in 892e282 and 257f2c5, and a re-run gave identical outputs (run 46291919028, byte for byte on all four jobs). The second round found a Medium: the replication steps didn't name the workflow file its paths filter expects. That is fixed in c04be63, and the third round found nothing above Low.


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Handover: the fix built from this record is draft #656. This experiment PR is complete and has no open items besides your review. This session is being archived, so nobody is watching this PR any more.


Generated by Claude Code

This branch has not been deployed

No deployments
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.

2 participants