Skip to content

[Bug]: prepared numeric consumers regress across scalar and derived query boundaries #29501

Closed

Description

@XuPeng-SH

Origin and disposition

Follow-up from the independent review of #29462, exact head 386c1434232af5ccf153b7c2d23e1240be90d021 and exact base b06ff850d4c54af2aeb920136f6e39d6b88f940b. The maintainer explicitly requested that these two demonstrated regressions be tracked as a follow-up issue. This issue supersedes the merge-blocking disposition in the earlier review; it does not change the observed behavior.

Problem

Prepared string parameters lose numeric consumer semantics when the parameter crosses a scalar subquery or derived table boundary. The PR's new bindPreparedConsumerArguments handling is restricted to a direct ParamRef; after projection/subquery the parent consumer sees a different expression and misses the conversion. The old QUERY specialization path was removed. This is one shared consumer-boundary defect, not two isolated function bugs.

Reproduction 1: scalar subquery ABS

PREPARE p FROM 'select abs((select ?))';
SET @v='-1.5';
EXECUTE p USING @v;
DEALLOCATE PREPARE p;
  • Exact base: 1.5.
  • Reviewed head: Error 20203 (HY000): invalid argument cast to int, bad value -1.5.
  • Reproduced with SQL PREPARE/EXECUTE and binary prepared statements. '-2.5' also fails, and a later valid binding does not recover.
  • Independent MySQL 8.0.45 oracle: 1.5; NULL stays NULL.

Reproduction 2: derived table SUM

PREPARE p FROM 'select sum(x) from (select ? x limit 1) d';
SET @v='1.5';
EXECUTE p USING @v;
DEALLOCATE PREPARE p;
  • Exact base: 1.5.
  • Reviewed head: invalid argument aggregate function sum, bad value [VARCHAR] through SQL PREPARE or [TEXT] through the binary protocol. NULL also fails in this path.
  • Reproduced with 1.5, 2.5, NULL and valid after NULL on both protocols.
  • Independent MySQL 8.0.45 oracle: 1.5, 2.5, NULL respectively.

Scope controls

select abs(?) and exact unsigned comparisons above 2^53 pass on both base and head. select abs(x) from (select ? x limit 1) d and select abs(coalesce(?, '0')) fail on the base too, so those are pre-existing adjacent defects, not regressions proven by #29462. Keep this separation in diagnosis and acceptance.

Fix direction

Reconcile parameter source type and numeric consumer conversions at the existing binder/type-propagation owner through query boundaries. Preserve one prepared execution route; avoid restoring per-execution specialization or accumulating SQL-shape branches. Check downstream metadata and plan-cache reuse across type changes, NULL and retry as applicable.

Acceptance

  • Both exact SQL reproducers return the expected numeric/NULL results via SQL PREPARE and binary protocol.
  • Rebind each prepared statement across two string values, NULL and a subsequent valid value without wrong cached types or errors.
  • Direct ABS and exact unsigned comparison controls remain correct.
  • Add compact, orthogonal regression cases to an existing public SQL/issue suite. Do not merely test the internal helper.
  • Verify base/head attribution and explain any separately fixed inherited variants.

Activity

  1. self-assigned this
    on Sep 29, 2026
  2. added
    kind/bug
    severity/s0
    on Sep 29, 2026
  3. XuPeng-SH commented on Sep 29, 2026

    @XuPeng-SH
    ContributorAuthor

    Fixed by PR #29462 commit 95e565b. Prepared SUM/AVG/ABS/SIGN/SLEEP now use the existing numeric consumer conversion for non-direct string expressions, covering scalar and derived query boundaries. Embedded SQL PREPARE and binary-protocol regressions passed with two values, NULL and recovery; #25408 and #27443 neighboring families passed. Commit-bound review: #29462 (review).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions