bd sql: a UNION ... INTO OUTFILE classifies as Read and skips the --readonly check (#6932)
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:
case *sqlparser.Select:
if s.Into != nil {
return Write
}
return Read
case *sqlparser.SetOp, *sqlparser.Show, *sqlparser.OtherRead:
return ReadSetOp carries an Into too, and only *Select is checked. So
(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_setdoes not pin that Mixed statements commit: routing Mixed throughRunTxReadleaves all four subtests green, becauseDOLT_BRANCHis not rolled back with the transaction.- The
RETURNINGbranch of INSERT/UPDATE/DELETE is unpinned: forcing it to always return Write leavesTestClassifygreen.
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
Source: gastownhall/beads