Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/bsql/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func (s *SQLSyncer) RunProvisioningQueries(ctx context.Context, queries, validat
}
}

for _, q := range queries {
for i, q := range queries {
q, qArgs, err := s.prepareProvisioningQuery(q, vars)
if err != nil {
return fmt.Errorf("failed to prepare query: %w", err)
Expand All @@ -393,7 +393,11 @@ func (s *SQLSyncer) RunProvisioningQueries(ctx context.Context, queries, validat
return ErrQueryAffectedMoreThanOneRow
}

if rowsAffected == 0 {
// Only check for zero affected rows on the first query.
// Secondary queries in a multi-query block may legitimately affect
// 0 rows (e.g., a conditional UPDATE that only applies when certain
// conditions are met).
if i == 0 && rowsAffected == 0 {
return ErrQueryAffectedZeroRows
}
Comment on lines +400 to 402
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Consider adding a debug log when a secondary query affects 0 rows, so operators have visibility into when this happens during troubleshooting. Something like:

Suggested change
if i == 0 && rowsAffected == 0 {
return ErrQueryAffectedZeroRows
}
if i == 0 && rowsAffected == 0 {
return ErrQueryAffectedZeroRows
}
if rowsAffected == 0 {
l.Debug("secondary query affected 0 rows", zap.Int("query_index", i), zap.String("query", q))
}

Not blocking — the current behavior is correct. But silently continuing on 0-row secondary queries could make debugging harder if a config mistake causes a secondary query to be a no-op when it shouldn't be.


Expand Down
Loading