Alternative to ALL_SYNONYMS view
The SYS.ALL_SYNONYMS view is used to get all the details of existing synonyms accessible to the current user.
However, SYS.ALL_SYNONYMS has some known performance issues — and at the time I'm writing this blog, hey still haven’t been resolved.
This becomes an issue if your database has a huge number of synonyms. (Yeah, sounds like a long shot, but believe me, speaking from experience — it can definitely happen.)
So, if your application has a PL/SQL block that's querying this view, you might want to consider updating your code to avoid referencing it altogether.
So the question is What's the alternative? I had the same question! And then a smart teammate of mine suggested using DBMS_UTILITY.NAME_RESOLVE. (s/o to Gerardo!)
What is DBMS_UTILITY.NAME_RESOLVE?
This is a built-in Oracle procedure that helps you resolve the components of a name in the database — things like the object name, schema, dblink, and type behind a reference.
So if you pass in something like a synonym name, it tells you what object it points to. Very handy when you want to bypass the heavier views like ALL_SYNONYMS.
Official doc: DBMS_UTILITY.NAME_RESOLVE DOCS
Quick Note: What’s a synonym?
A synonym is basically an alias for a database object — a table, a procedure, a function and so on…
You are now thinking that synonyms are only about simplifying access to objects — But they're also super useful as a form of abstraction. You can think of a synonym as a stable/constant thing that’s less likely to change, even if the underlying object (its name, schema, etc.) does. That stability can make a big difference when you want to write resilient PL/SQL code.
Comments
Post a Comment