Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#11950·dolt

Stored procedure that CALLs another procedure inside an explicit transaction silently discards the caller's earlier writes

Author: ckumar1Created Sep 27, 2026Updated Sep 30, 2026
Labelsbugsqlgood reprocustomer issuecorrectness

Summary

Inside an explicit transaction, when a stored procedure writes a row and then CALLs another stored procedure, the caller's write made before the nested CALL is silently discarded. It is already gone from the same session's view right after the CALL (before COMMIT), and it is absent after COMMIT. The nested procedure's own write commits normally. No error or warning is raised, so the transaction commits partially.

Controls:

  • the same procedure under autocommit keeps both rows;
  • a write the caller makes after the nested CALL is kept;
  • a flat procedure (both inserts inline, no nested CALL) keeps both rows.

Reproduced on dolt 2.2.4 and dolt 2.3.5 (current latest), macOS arm64. dolt sql-server with default config on a fresh data dir, root user, MySQL protocol (PyMySQL). The server reports version 8.0.31.

Reproduction

Setup (any session):

sql
CREATE DATABASE repro2; USE repro2;
CREATE TABLE t_outer (v INT);
CREATE TABLE t_inner (v INT);
CREATE PROCEDURE q(IN x INT) BEGIN INSERT INTO t_inner VALUES (x); END;
CREATE PROCEDURE p_nested(IN x INT) BEGIN INSERT INTO t_outer VALUES (x); CALL q(x); END;
CREATE PROCEDURE p_nested_after(IN x INT) BEGIN CALL q(x); INSERT INTO t_outer VALUES (x); END;

Case A, in one session with autocommit off:

sql
SET autocommit = 0;
START TRANSACTION;
CALL p_nested(10);
SELECT (SELECT COUNT(*) FROM t_outer WHERE v = 10) AS outer_rows,
       (SELECT COUNT(*) FROM t_inner WHERE v = 10) AS inner_rows;
-- expected 1, 1   actual 0, 1
COMMIT;
Case What runs Expected (outer, inner) Actual on 2.2.4 and 2.3.5
A explicit txn, CALL p_nested(10), read in the same session before COMMIT (1, 1) (0, 1)
A same, fresh read after COMMIT (1, 1) (0, 1)
B autocommit on, CALL p_nested(20) (1, 1) (1, 1)
C explicit txn, CALL p_nested_after(30) (outer write after the nested CALL), then COMMIT (1, 1) (1, 1)
Script used (Python + PyMySQL; pass a file containing the server port)
python
import pymysql, sys
port = int(open(sys.argv[1]).read())
def conn(ac, db='repro2'):
    return pymysql.connect(host='127.0.0.1', port=port, user='root', database=db, autocommit=ac)
r = pymysql.connect(host='127.0.0.1', port=port, user='root', autocommit=True).cursor()
r.execute("drop database if exists repro2"); r.execute("create database repro2"); r.execute("use repro2")
r.execute("create table t_outer(v int)"); r.execute("create table t_inner(v int)")
r.execute("create procedure q(in x int) begin insert into t_inner values (x); end")
r.execute("create procedure p_nested(in x int) begin insert into t_outer values (x); call q(x); end")
def counts(cur, x):
    cur.execute(f"select (select count(*) from t_outer where v={x}),(select count(*) from t_inner where v={x})")
    return cur.fetchone()
c = conn(False); k = c.cursor(); k.execute("start transaction"); k.execute("call p_nested(10)")
print("A explicit txn, same session BEFORE commit (expect 1,1):", counts(k, 10))
c.commit(); c.close()
print("A explicit txn, fresh read AFTER commit    (expect 1,1):", counts(r, 10))
c = conn(True); k = c.cursor(); k.execute("call p_nested(20)"); c.close()
print("B autocommit                               (expect 1,1):", counts(r, 20))
r.execute("create procedure p_nested_after(in x int) begin call q(x); insert into t_outer values (x); end")
c = conn(False); k = c.cursor(); k.execute("start transaction"); k.execute("call p_nested_after(30)"); c.commit(); c.close()
print("C explicit txn, outer write after CALL     (expect 1,1):", counts(r, 30))

Output, identical on 2.2.4 and 2.3.5:

A explicit txn, same session BEFORE commit (expect 1,1): (0, 1)
A explicit txn, fresh read AFTER commit    (expect 1,1): (0, 1)
B autocommit                               (expect 1,1): (1, 1)
C explicit txn, outer write after CALL     (expect 1,1): (1, 1)

Impact

This is a silent loss of atomicity for any procedure that composes other procedures inside a transaction. We hit it while building an append-only event log in which a procedure records an event and then calls a helper that updates a projection: the events never landed, while the projection rows did.

Because the loss is visible inside the session before COMMIT, the nested CALL appears to reset the transaction's pending changes rather than the commit dropping them.

Workaround

Keep procedures flat (no nested CALL) when they run inside an explicit transaction, or run the call under autocommit.

Source: dolthub/dolt

View original on GitHubView discussion on GitHub