Skip to content

Commit 73a39d3

Browse files
craig[bot]michae2
andcommitted
Merge #159321
159321: builtins: call Parse instead of ParseOne in crdb_internal.inject_hint r=mgartner a=michae2 This changes an internal error to a regular error with a pgcode. Fixes: #158658 Fixes: #159232 Release note: None Co-authored-by: Michael Erickson <[email protected]>
2 parents 837998e + adb73c3 commit 73a39d3

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

pkg/sql/logictest/testdata/logic_test/statement_hint_builtins

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,3 +943,11 @@ statement hints count: 1
943943
missing stats
944944
table: xy@xy_pkey
945945
spans: FULL SCAN
946+
947+
# Test error handling for crdb_internal.inject_hint.
948+
949+
statement error pq: could not parse statement fingerprint as a single SQL statement
950+
SELECT crdb_internal.inject_hint('', '')
951+
952+
statement error pq: could not parse hint donor statement as a single SQL statement
953+
SELECT crdb_internal.inject_hint('SELECT 1', 'SELECT 2; SELECT 3')

pkg/sql/sem/builtins/builtins.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9677,18 +9677,32 @@ WHERE object_id = table_descriptor_id
96779677
fingerprintFlags := tree.FmtFlags(tree.QueryFormattingForFingerprintsMask.Get(
96789678
&evalCtx.Settings.SV,
96799679
))
9680-
targetStmt, err := parserutils.ParseOne(stmtFingerprint)
9680+
stmts, err := parserutils.Parse(stmtFingerprint)
96819681
if err != nil {
96829682
return nil, pgerror.Wrap(
96839683
err, pgcode.InvalidParameterValue, "could not parse statement fingerprint",
96849684
)
96859685
}
9686-
donorStmt, err := parserutils.ParseOne(donorSQL)
9686+
if len(stmts) != 1 {
9687+
return nil, pgerror.New(
9688+
pgcode.InvalidParameterValue,
9689+
"could not parse statement fingerprint as a single SQL statement",
9690+
)
9691+
}
9692+
targetStmt := stmts[0]
9693+
stmts, err = parserutils.Parse(donorSQL)
96879694
if err != nil {
96889695
return nil, pgerror.Wrap(
96899696
err, pgcode.InvalidParameterValue, "could not parse hint donor statement",
96909697
)
96919698
}
9699+
if len(stmts) != 1 {
9700+
return nil, pgerror.New(
9701+
pgcode.InvalidParameterValue,
9702+
"could not parse hint donor statement as a single SQL statement",
9703+
)
9704+
}
9705+
donorStmt := stmts[0]
96929706
donor, err := tree.NewHintInjectionDonor(donorStmt.AST, fingerprintFlags)
96939707
if err != nil {
96949708
return nil, errors.NewAssertionErrorWithWrappedErrf(err, "error while creating donor")

0 commit comments

Comments
 (0)