You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: SQL routine bodies: Oracle comma joins (FROM a x, b y) lose every table after the first, and @dblink suffixes are silently stripped #5169
I have checked the Troubleshooting section in the README
What happened?
Two related gaps in _routine_body_refs (graphify/extractors/sql.py):
Comma join (not Oracle-specific, no @ involved)._BODY_READ_RX (line 295) matches only FROM|JOIN <ident>. In FROM hr.emp a, hr.dept d the second table follows a comma, so it never matches and the edge to hr.dept is lost. This old implicit-join style is ubiquitous in Oracle code, but also valid in ANSI SQL.
Database links. For FROM hr.emp@remote_db and INSERT INTO hr.emp_copy@remote_db, the identifier atom stops before @ and _BODY_TAIL ((?![\w$]|\s*\.), line 294) does not reject it, so the edge goes to the local hr.emp / hr.emp_copy. A remote table is therefore indistinguishable from a local table of the same name, which can create a false link (or merge nodes) between two different databases. (Initially I suspected the table was dropped; it is actually kept with the link removed.)
Steps to reproduce
cat > t3c.sql <<'SQL'CREATE OR REPLACE PROCEDURE p3c ISBEGIN INSERT INTO hr.t_out SELECT a.id FROM hr.emp a, hr.dept d WHERE a.d = d.id;END;/SQL
cat > t3a.sql <<'SQL'CREATE OR REPLACE PROCEDURE p3a ISBEGIN INSERT INTO hr.emp_copy SELECT * FROM hr.emp@remote_db;END;/SQL
python -c "from pathlib import Pathfrom graphify.extractors.sql import extract_sqlfor f in ('t3c.sql','t3a.sql'): r = extract_sql(Path(f)); print(f, [n['label'] for n in r['nodes']], sorted({(e['relation'], e['target']) for e in r['edges'] if e['relation']!='contains'}))"
Error output or graph output
t3c.sql ['t3c.sql', 'p3c()', 'hr.t_out', 'hr.emp'] [('reads_from', 'hr_emp'), ('writes_to', 'hr_t_out')] # hr.dept missing
t3a.sql ['t3a.sql', 'p3a()', 'hr.emp_copy', 'hr.emp'] [('reads_from', 'hr_emp'), ('writes_to', 'hr_emp_copy')] # points at local hr.emp, link lost
Expected: p3c reads_from both hr.emp and hr.dept; p3a reads_from a node that records it is remote (e.g. label hr.emp@remote_db, or the existing node plus a remote=remote_db attribute).
Proposed fix
Comma join: after a matched FROM/JOIN identifier (and its optional alias), continue consuming ,\s*<ident>[\s+alias] while the next token is a comma, stopping at a keyword (WHERE, GROUP, ORDER, ...), reusing _BODY_NON_TABLES; guard against FROM t1, TABLE(...), (subquery), and function calls as the existing lstrip().startswith("(") check does.
Dblink: extend the identifier atom with an optional (?:@[\w$.]+)? suffix; key the stub id including the link (so it does not collide with a local table) and keep the Schema.table label with the @link suffix, or store the link as a node attribute. Alternative minimal behavior that fails closed (CONTRIBUTING item 5): skip references carrying @link rather than misattributing them to a local table.
Looked into this and confirmed the root cause locally in _routine_body_refs (graphify/extractors/sql.py):
Comma joins:_BODY_READ_RX only matches FROM|JOIN <ident>. It doesn't continue consuming subsequent , <ident> tables in FROM a, b, so every table after the first is lost.
@dblink truncation:_BODY_TAIL = r"(?![\w$]|\s*\.)" allows @ to follow the matched table name. The regex matches hr.emp and silently drops @remote_db, falsely linking to the local table.
Local reproduction:
fromgraphify.extractors.sqlimport_routine_body_refs# 1. Comma join loses hr.dept:_routine_body_refs("INSERT INTO hr.t_out SELECT a.id FROM hr.emp a, hr.dept d WHERE a.d = d.id;")
# Output: [('writes_to', 'hr.t_out', 9), ('reads_from', 'hr.emp', 42)] # hr.dept dropped# 2. Dblink stripped:_routine_body_refs("INSERT INTO hr.emp_copy SELECT * FROM hr.emp@remote_db;")
# Output: [('writes_to', 'hr.emp_copy', 0), ('reads_from', 'hr.emp', 33)] # @remote_db lost
I am working on a fix for this targeting v8 and will open a PR shortly.
Activity
github-actions commentedon Nov 12, 2026
Thanks for opening this issue, @a9385208438-dev. A maintainer will take a look soon.
If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.
To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.
mohitdixit02 commentedon Nov 12, 2026
Looked into this and confirmed the root cause locally in
_routine_body_refs(graphify/extractors/sql.py):_BODY_READ_RXonly matchesFROM|JOIN <ident>. It doesn't continue consuming subsequent, <ident>tables inFROM a, b, so every table after the first is lost.@dblinktruncation:_BODY_TAIL = r"(?![\w$]|\s*\.)"allows@to follow the matched table name. The regex matcheshr.empand silently drops@remote_db, falsely linking to the local table.Local reproduction:
I am working on a fix for this targeting v8 and will open a PR shortly.
fix(sql): preserve comma joins and dblink suffixes in routine bodies (#…
chore: combine the schema-45 comment and guard the SQL grammar-versio…
safishamsi commentedon Nov 12, 2026
Fixed by #5173 (e605f4a), released in graphify 0.9.108. Thanks @a9385208438-dev for the report and @mohitdixit02 for the fix.