fix(sql): preserve ampersand tenant routing hints

Closes #5488
This commit is contained in:
t8y2 2026-08-06 17:57:03 +08:00
parent 6f1bf65726
commit 7bb5767bf7
No known key found for this signature in database
2 changed files with 10 additions and 1 deletions

View File

@ -1104,6 +1104,15 @@ describe("buildExecutionCandidates", () => {
expect(splitSqlStatementRanges("/*@global:true*/", "mysql")).toEqual([]);
});
it("preserves leading ampersand tenant routing hints in current statement candidates", () => {
const hintedSql = "/*&tenant:mctest*/\nSELECT count(*) FROM tenant_table";
const sql = `SELECT 1;\n${hintedSql};`;
const candidates = buildExecutionCandidates(sql, indexOf(sql, "tenant_table"), "mysql");
expect(candidates[0].sql).toBe(hintedSql);
expect(splitSqlStatementRanges("/*&tenant:mctest*/", "mysql")).toEqual([]);
});
it("uses the cursor statement for the first candidate when there is no selection", () => {
const sql = "SELECT *\nFROM users\nWHERE active = 1";
const candidates = buildExecutionCandidates(sql, indexOf(sql, "users"));

View File

@ -445,7 +445,7 @@ export function splitSqlStatementRanges(sql: string, databaseType?: DatabaseType
// Block comments consume until the closing */.
if (ch === "/" && next === "*") {
const hintMarker = sql[i + 2];
if (statementStart === -1 && pendingHintStart === -1 && (hintMarker === "+" || hintMarker === "@")) pendingHintStart = i;
if (statementStart === -1 && pendingHintStart === -1 && (hintMarker === "+" || hintMarker === "@" || hintMarker === "&")) pendingHintStart = i;
const close = sql.indexOf("*/", i + 2);
i = close === -1 ? len : close + 2;
continue;