Repository navigation
Description
What
CALL on any procedure that produces a result set panics the executor:
thread panicked at crates/mas-core/src/query/executor.rs:268:47:
index out of bounds: the len is 1 but the index is 1
Not a corner case. Reproduced against MySQL 8 through QueryExecutor::execute:
| Statement | Procedure body | Result |
|---|---|---|
CALL p_one() |
SELECT 'only' AS a; |
panic — len 1, index 1 |
CALL p_none() |
SET @noop = 1; |
ok, 1 set |
SET @p_out = NULL; CALL p_two(@p_out); SELECT @p_out; |
two SELECTs + SET |
panic — len 3, index 3 |
So a single CALL to a procedure containing one SELECT — the ordinary case — crashes. The routine viewer's Execute button builds exactly that batch, and typing CALL x() in the editor does too.
Seed used:
CREATE PROCEDURE p_one() BEGIN SELECT 'only' AS a; END
CREATE PROCEDURE p_two(OUT p_out INT)
BEGIN SELECT 'hello' AS greeting; SELECT 'second' AS s; SET p_out = 42; ENDCause
The fetch loop assumes one Either::Left per statement, as its own comment says:
Either::Left(qr) => {
// Statement complete. For SELECT this arrives after all rows;
// for DML/DDL it is the only item for that statement.
if stmt_idx >= 0 {
let idx = stmt_idx as usize;
let stmt = &statements[idx]; // <-- panicsA CALL breaks that. MySQL sends one result set per SELECT inside the procedure plus a final OK packet, so N+1 Lefts arrive for one statement. stmt_idx runs past the end of statements and the index panics.
A second defect in the same place
returns_rows decides result-set-versus-count from the statement verb, and its list is SELECT, SHOW, DESCRIBE, DESC, EXPLAIN, ANALYZE, TABLE, VALUES. CALL is not in it. Even without the panic, a procedure's rows would be discarded and reported as a rows-affected count.
Deriving this from the verb cannot work for CALL: whether it returns rows depends on the procedure body, not the statement text.
Suggested fix
Two changes at the same site:
- Do not index
statementsunconditionally. Whenidxis past the end, theLeftbelongs to a statement that already reported — attribute it to the last statement rather than panicking. - Treat a
Leftas a result set whenreturns_rows(stmt)or rows actually accumulated since the last one. That coversCALL, and keeps a zero-rowSELECTreporting as an empty result set rather than flipping to a count.
Baseline to preserve, both confirmed working today:
SELECT 1 AS n ... WHERE 1=0→ 1 set, no columnsSELECT 1 AS a; SELECT 2 AS b→ 2 sets,statement_index0 and 1
Relationship to other issues
This is upstream of #396, which describes OUT-param values being read from the wrong result set. That code cannot be reached today — executing any procedure with a SELECT in it crashes first. #396 should be re-examined once this is fixed.
Found while verifying #396's premise.
Activity
fix(query): stop assuming one result set per statement, which CALL br…