Trivadis / plsql-cop-validators

db* CODECOP Validators
Other
9 stars 5 forks source link

G-9603 - false positive for hints referring table/alias in using clause of merge statement #44

Closed PhilippSalvisberg closed 2 years ago

PhilippSalvisberg commented 2 years ago

The following statement

merge /*+ use_hash (d s) */ into bonuses d
using (select employee_id, salary, department_id
         from employees
        where department_id = 80) s
   on (d.employee_id = s.employee_id)
 when matched then
      update
         set d.bonus = d.bonus + s.salary *.01
      delete
       where (s.salary > 8000)
 when not matched then
      insert (d.employee_id, d.bonus)
      values (s.employee_id, s.salary *.01)
       where (s.salary <= 8000);

reports this violation on line 1:

G-9603: Never reference an unknown table/alias. (s in use_hash hint).

This is a false positive. The alias s on line 4 is not recognized.

PhilippSalvisberg commented 2 years ago

Furthermore marking this false positive with a NOSONAR comment does not suppress the guideline violation.

PhilippSalvisberg commented 2 years ago

culprit is probably https://github.com/Trivadis/plsql-cop-validators/blob/main/src/main/java/com/trivadis/tvdcc/validators/Hint.xtend#L256-L260 . Only the into clause is considered. using clause is missing here.