-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[BugFix] Qualified backup/restore function names are validated against defaultDb instead of the qualifier's DB #70949
Description
Bug Description
Severity: CRITICAL
Component: SQL Analyzer
Source file: fe/fe-core/src/main/java/com/starrocks/sql/analyzer/FunctionNameAnalyzer.java (line 70)
Root cause: FunctionNameAnalyzer.java:70 calls defaultDb.getFunctionsByName(functionName) where defaultDb is the BACKUP target DB, completely ignoring the qualifier's DB prefix. This causes two distinct failures: false rejections (function exists in qualifier's DB but not in default DB) and false acceptances (function validated against the wrong DB, silently backing up the wrong object).
Concrete failure scenario:
BACKUP fn_db2.test_fnwhile connected tofn_db1fails with "Invalid backup function(s)" even thoughfn_db2.test_fnexists.BACKUP fn_db1.test_fnwhile connected tofn_db2succeeds but backs upfn_db2.test_fninstead offn_db1.test_fn.
Steps to Reproduce
CREATE DATABASE IF NOT EXISTS fn_db1;
CREATE DATABASE IF NOT EXISTS fn_db2;
-- Create UDF only in fn_db2
CREATE FUNCTION fn_db2.test_fn(x STRING) RETURNS STRING
PROPERTIES ('symbol'='...', 'type'='StarrocksJar', 'file'='...');
-- BUG CASE 1: false rejection
-- Connected to fn_db1, BACKUP fn_db2.test_fn
USE fn_db1;
BACKUP SNAPSHOT fn_db1.test_snap TO test_repo ON (FUNCTION fn_db2.test_fn);
-- Expected: success (fn_db2.test_fn exists)
-- Actual: ERROR 5064: Invalid backup function(s), function name: test_fn
-- BUG CASE 2: false acceptance / wrong object selected
CREATE FUNCTION fn_db1.test_fn(x STRING) RETURNS STRING ...;
USE fn_db2;
BACKUP SNAPSHOT fn_db2.test_snap2 TO test_repo ON (FUNCTION fn_db1.test_fn);
-- Expected: backs up fn_db1's test_fn
-- Actual: no error; backs up fn_db2's test_fn (validated against defaultDb=fn_db2)Actual Behavior
Case 1 (false rejection): ERROR 5064 (42000): Getting analyzing error. Detail message: Invalid backup function(s), function name: test_fn
(Function exists in fn_db2 but fn_db1 (defaultDb) is searched instead.)
Case 2 (false acceptance): No error; BACKUP job entered SNAPSHOTING state (JobId: 14030). The qualifier fn_db1.test_fn was not validated against fn_db1; instead fn_db2 (defaultDb) was checked, silently selecting the wrong function object for backup.
Expected Behavior
Case 1: BACKUP should succeed — the qualified DB prefix fn_db2 should be used for the lookup.
Case 2: BACKUP should validate test_fn against fn_db1 (the qualifier's DB) and select the fn_db1 copy.
Verification
Both cases confirmed at runtime. FunctionNameAnalyzer.java:70 calls defaultDb.getFunctionsByName(functionName) where defaultDb is always the BACKUP target DB, ignoring the DB qualifier prefix entirely.
This bug was identified and reproduced by AI-assisted code review.
What type of issue is this:
- BugFix
Does this entail a change in behavior?
- Yes, this issue will result in a change in behavior.
Type of change:
- Miscellaneous: correctness bug fix
Checklist
- Fix needs a regression test
- Fix may need user documentation update
Test Environment
| Tested Version | main-4d6435b (MySQL protocol 8.0.33) |
| Cluster | 3 BE nodes alive (172.26.95.230, .231, .232), FE at 172.26.95.233:9030 |