← Back to Pull requests

MDEV-33477 Prepared statement with only placeholders in TVC discards values #5798

Open
GoldenEmperor1177 opened this pull request with 249 lines diff across 3 files
View on GitHub
GoldenEmperor1177 GoldenEmperor1177 commented on Sep 30, 2026 16:21 UTC
Author

A table value constructor column whose values are all placeholders returned an empty value when executed as a prepared statement, e.g. EXECUTE IMMEDIATE 'SELECT * FROM (VALUES (?)) t' USING 'a'.

table_value_constr::prepare() computes the column types once, at PREPARE time, and caches them (MDEV-32225). At that time a placeholder has no value and only the "null" type, so the cached column type stayed wrong for later executions. Columns that also contain a literal in some row were not affected.

This patch recomputes the column types on each execution when the TVC contains a placeholder. The result is computed in the current execution's memory and the cached Item_type_holders are updated in place, so nothing new is allocated in the statement arena on re-execution and the MDEV-32225 protection still holds. TVCs without placeholders take the same path as before.

Tests: new cases in main.table_value_constr covering several parameter types, re-execution with changing types, UNION, a CTE and a stored procedure. The test fails without the fix. The main suite passes on debug and release builds, and the related tests pass under ASAN+UBSAN.

Jira: https://jira.mariadb.org/browse/MDEV-33477

Diff: 249 lines (+248 / -1) across 3 files Reviewer: gkodinov Review duration: 21347m
All Vouch review confidence checks passed
Residual risk 0.03 = Change Risk (0.39) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 249 lines diff across 3 files
0.39
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.94 · 2 substantive comment(s)
0.94
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
91%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.330
Real PR Conversation Timeline
4 items
gkodinov gkodinov approved these changes on Oct 01, 2026 08:34 UTC
Approved Reviewer

Thank you for your contribution! This is a preliminary review.

FWIW, I do not quite subscribe to the idea of the fix: to me the placeholder types should be determined once at PREPARE time and kept this way. But I realize that the SQL standard is not exactly clear about that either.
I'd also test for cases like values (? +12).

LGTM. Stay tuned for the final review.

GoldenEmperor1177 GoldenEmperor1177 commented on Oct 01, 2026 09:46 UTC
Author

Thank you for your contribution! This is a preliminary review.

> FWIW, I do not quite subscribe to the idea of the fix: to me the placeholder types should be determined once at PREPARE time and kept this way. But I realize that the SQL standard is not exactly clear about that either.

I'd also test for cases like values (? +12).

> LGTM. Stay tuned for the final review.

Hmm🧐 let me check it out real quick !

GoldenEmperor1177 GoldenEmperor1177 commented on Oct 01, 2026 16:18 UTC
Author

Thanks for the review! On the design: a plain SELECT ? already re-types its column on every EXECUTE (a string type for 'abc', LONGLONG for 42, NEWDECIMAL for 3.25), and the fix makes a TVC follow the same rule. As suggested I also tried values (? +12): over re-executions it returns 13, 112, 14.5, 19 (for '7') and NULL. It works inside a derived table and with two placeholders too, and I've added these cases to the test.

Reviewers
Assignees
GoldenEmperor1177 GoldenEmperor1177
Labels
risk: low confidence: 91.3% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 39.0% (MEDIUM) · Higher = larger blast radius
39.0%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 91.3% · Lower = rushed or shallow review
91.3%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 3.4% · Safe to merge
3.4%
Repository