Skip to content

[P1][bug] RoutineViewer outParamResults reads from the LAST query result set — multiple SELECTs hide the real result #396

Closed

Description

@EVWorth

Context

Routine Viewer procedure execute extracts OUT param values from the final SELECT result.

Problem

src/components/routine/RoutineViewer.tsx:158-185 extracts outParamResults from queryResults[queryResults.length - 1] — assumes the last SELECT in the multi-statement SQL is the OUT-param SELECT (which executeProcedure does append, line 144-147). But: (a) the results state is set with the full queryResults array (line 153), so the Results section renders all sets — good. (b) outParamResults reads only the last set. A procedure that returns SELECT 'hello' AS greeting; SELECT 'val' AS p_out; would show outValue: 'hello' for p_out — wrong. The lastResult.columns[i].name is used as the key, so a procedure returning SELECT @p_out AS \p_out`; SELECT 'done'would correctly pick p_out from the second set, but a procedure returningSELECT 'greeting'; SELECT @p_out AS `p_out`` (the bug case) maps by col.name — if the greeting set's column is named greeting and the out set's column is named p_out, then outParamResults would have only p_out mapped (correct) — but only because of the column-name match. Bug is real when the procedure's own SELECT has different column names than the OUT param column names.

Files

  • src/components/routine/RoutineViewer.tsx:158-185 (outParamResults extraction)

Repro

  1. CREATE PROCEDURE foo(IN x INT) BEGIN SELECT 'hello' AS greeting; SET @p_out = x + 1; END
  2. Call foo — executeProcedure appends SELECT @p_out AS \p_out``
  3. queryResults = [{columns: [greeting], rows: [['hello']]}, {columns: [p_out], rows: [[5]]}]
  4. outParamResults picks last set → p_out = 5 (correct for this case because column names differ)
  5. If a procedure returns SELECT 'hello'; SELECT @p_out AS `p_out` with same column 'greeting' as the OUT-param SELECT, it gets confused

Expected

A procedure returning SELECT 'hello' AS greeting; SELECT @p_out AS \p_out`;` shows greeting: 'hello' in the Results section AND p_out: '' in the OUT params input.

Proposed fix

Tag the OUT-param SELECT with a sentinel column name prefix (e.g., SELECT @p_out AS \__out__p_out``) and filter queryResults for the set containing out columns. Or, simpler: append the OUT-param SELECT with UNION ALL markers and detect. Cleanest fix: the backend command (F2) returns a typed ProcedureResult { result_sets: Vec, out_params: HashMap<String, String> } — out_params is computed server-side, no ambiguity. Scope: M.

Acceptance

A procedure returning SELECT 'hello' AS greeting; SELECT @p_out AS \p_out`;` shows greeting: 'hello' in the Results section AND p_out: '' in the OUT params input.

Needs human verify

yes

Doc drift

no

Activity

  1. added
    audit
    severity/p1
    kind/bug
    area/routine
    on Jul 31, 2026
  2. EVWorth commented on Sep 5, 2026

    @EVWorth
    OwnerAuthor

    Re-examined now that #544 is fixed, and this does not reproduce.

    It could not be reached before

    Executing any procedure that returns rows panicked the executor (#544, fixed in #545), so the OUT-param extraction never ran at all.

    With that fixed, the extraction is correct

    The batch executeProcedure builds now comes back attributed like this, verified against MySQL 8:

    [0] statement_index=0  columns=[]            <- SET @p_out = NULL
    [1] statement_index=1  columns=[greeting]    <- from inside the procedure
    [2] statement_index=1  columns=[s]           <- also from inside
    [3] statement_index=2  columns=[p_out]       <- the appended SELECT @p_out
    

    The appended SELECT @p_out is a separate statement issued after the CALL returns, so its result set is always last. Reading queryResults[queryResults.length - 1] therefore always reads the OUT-param set.

    Including the collision case the issue calls out

    The issue's worst case is a procedure whose own SELECT emits a column named the same as the OUT parameter. Built and ran exactly that:

    CREATE PROCEDURE p396(OUT p_out INT)
    BEGIN
      SELECT 'from the body' AS p_out;
      SET p_out = 99;
    END
    p_out
    from the body     <- the procedure's own set
    p_out
    99                <- the appended SELECT, last, and what gets read
    

    The OUT parameter reads back as 99. The name collision does not matter, because the selection is positional and the position is always right.

    The issue text is self-aware about this — it works through the example and concludes "correct for this case because column names differ", then supposes a variant that cannot occur, since the appended SELECT's column name is the OUT parameter's own name.

    One real thing nearby, not worth reopening for

    The appended SELECT @p_out shows up as a visible result tab alongside the procedure's own output. That is noise rather than a wrong answer — the user sees an extra tab containing the value already displayed in the OUT params box. Mentioning it rather than filing it; say the word if it is worth its own issue.

    Closing as not reproducible.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/routineauditkind/bugseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions