MDEV-33477 Prepared statement with only placeholders in TVC discards values #5798
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.
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 !
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.
gkodinov
GoldenEmperor1177
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_holdersare 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_constrcovering several parameter types, re-execution with changing types, UNION, a CTE and a stored procedure. The test fails without the fix. Themainsuite passes on debug and release builds, and the related tests pass under ASAN+UBSAN.Jira: https://jira.mariadb.org/browse/MDEV-33477