#7033·beads

bd sql: a UNION ... INTO OUTFILE classifies as Read and skips the --readonly check (#6932)

Author: bee-ghosttrackCreated Sep 30, 2026Updated Sep 30, 2026
Labelskind/bugpriority/p1

Post-merge audit of #6932 at main 448c4b862. The same code is on hotfix/1.3.1 (batch 3, #6945, patch-identical), so this is in v1.3.1-rc.2.

1. A set operation with INTO OUTFILE / INTO DUMPFILE classifies as Read (minor, regression)

internal/storage/sqlclass/sqlclass.go:52-56:

go
case *sqlparser.Select:
	if s.Into != nil {
		return Write
	}
	return Read
case *sqlparser.SetOp, *sqlparser.Show, *sqlparser.OtherRead:
	return Read

SetOp carries an Into too, and only *Select is checked. So

sql
(SELECT id FROM issues) UNION ALL (SELECT id FROM issues) INTO OUTFILE '/p'

classifies as Read (a probe prints read *sqlparser.SetOp); a WITH ... prefix gives the same result.

Effect: in cmd/bd/sql.go:79-84 only Mixed calls CheckReadonly, so on the direct path bd --readonly sql runs this statement, and Dolt writes the file (confirmed with dolt sql for this exact query, inside secure_file_priv). On the proxied path it runs inside a read transaction.

Before #6932 the leading ( failed the prefix check and the statement took the write path through CheckReadonly, so this is a regression for that input.

Fix: ask the interface, which covers both node types: stmt.(sqlparser.SelectStatement).GetInto().

Not done: bd --readonly sql was not driven end to end. The classification and Dolt's file write are each confirmed; the skipped readonly check is from reading sql.go.

2. Test gaps

  • TestProxiedServerSQLStatementRouting/call_renders_result_set does not pin that Mixed statements commit: routing Mixed through RunTxRead leaves all four subtests green, because DOLT_BRANCH is not rolled back with the transaction.
  • The RETURNING branch of INSERT/UPDATE/DELETE is unpinned: forcing it to always return Write leaves TestClassify green.

Checked and found sound

Multi-statement input (parse failure → Mixed, which goes through CheckReadonly); CALL DOLT_COMMIT/DOLT_RESET/DOLT_CHECKOUT → Mixed; SET/USE → Write; PREPARE, EXECUTE, LOCK, LOAD, GRANT, FLUSH, KILL → Mixed; /*! */ and # comments; trailing ;; a later-statement error in Mixed multi-statement input does surface. Removing the SELECT ... INTO check turns the unit test red.

bee, beads-lane steward