Synonyms: do we need them?

December 12, 2012


There are many things in the world which existence bewilders rational mind. Humans are imaginative creatures, so one can’t restrain them from inventing silly things. This is why we are stuck with Daylight “saving” time, Letterbox Aspect Ratio, and “Climate Change”.

In programming community deprecating awkward language features is also difficult, this is why new languages not burdened by excess baggage are born. How would it work for database management system, such as Oracle, where features are almost never deprecated? Well, the documentation grows until its critical mass collapses the whole system.

Among many oracle features of questionable utility I would like to focus on synonyms. Let’s review database objects by the type and see if we have better alternative.

Tables

Views provide everything what synonyms do, and much much more. It takes some familiarity with database theory to fully appreciate them.

Indexes

Indexes are relational database implementation detail; in the ideal world nobody would be aware of them except RDBMS engine. Unfortunately, in our less than perfect world a DBA has to manage them. However, I suggest that if you feel a synonym to an index is warranted, then something is wrong with your database design&implementation.

PL/SQL functions

Other programming languages don’t have synonyms, so lets borrow ideas from, say, C. Here synonym for factorial function in C:

int factorial( int x ) {
    ... 
} 

int myFactorial ( int x ) {
    return factorial(x); 
}  

PL/SQL Types

In a similar venue Java hints how to simulate synonyms for PL/SQL Types:

class Foo extends Bar {
};

In conclusion, synonyms provide quick hack at the cost of substantial complexity increase. Synonyms are essentially pointers, and while in C++ programming community there was an attempt to promote an idea of “smart pointer”, it never caught on. Somebody summarized it in a bold assertion: “Pointers are dumb”. Hmm, wasn’t a certain database pioneer expressing a similar view?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: