Hi

I am attaching a patch that adds SYNONYM support to Derby.  Synonym provides an alternate name for a table or a view that is present in the same schema or another schema. A synonym can also be created for another synonym, causing nesting of synonyms. A synonym can be used in SELECT, INSERT, UPDATE, DELETE or LOCK TABLE statements instead of the original qualified table or view name. Note that a synonym can be created for a table or a view that doesn't yet exists. But the target table/view must be present before the synonym can be used.

Synonyms are supported by all major database vendors, including Oracle, DB2 and mySQL. DB2 also allows CREATE ALIAS statement, which does exactly same as CREATE SYNONYM. Creating aliases instead of synonyms is not supported by Oracle or mySQL, so I propose that Derby not support creating aliases. Synonyms are not part of SQL-2003 spec, but is a common-SQL statement among major database vendors. SQL standard doesn't pay attention to DDLs as much, so I suspect they skipped synonyms. We all know and love CREATE INDEX statement, which is also not part of the standard.

This current patch leaves out some changes that are needed. I will submit these in another patch:
  1. dblook changes. This schema generating tool needs to be modified to emit synonym information in the catalog.
  2. Registering and enforcing dependencies. Droping a synonym, for example, should invalidate all cached plans that use them. This is achieved by registering and enforcing dependencies using DependencyManager.
Let me know if you have any comments or suggestions. My vote is +1, to accept this patch.

Satheesh

[bandaram:satheesh] svn stat
M      java\engine\org\apache\derby\impl\sql\compile\NodeFactoryImpl.java
M      java\engine\org\apache\derby\impl\sql\compile\DropAliasNode.java
M      java\engine\org\apache\derby\impl\sql\compile\QueryTreeNode.java
M      java\engine\org\apache\derby\impl\sql\compile\CreateTableNode.java
M      java\engine\org\apache\derby\impl\sql\compile\LockTableNode.java
M      java\engine\org\apache\derby\impl\sql\compile\FromBaseTable.java
M      java\engine\org\apache\derby\impl\sql\compile\DMLModStatementNode.java
M      java\engine\org\apache\derby\impl\sql\compile\CreateAliasNode.java
M      java\engine\org\apache\derby\impl\sql\compile\sqlgrammar.jj
M      java\engine\org\apache\derby\impl\sql\compile\CreateViewNode.java
M      java\engine\org\apache\derby\impl\sql\execute\DropAliasConstantAction.java
M      java\engine\org\apache\derby\impl\sql\execute\CreateAliasConstantAction.java
M      java\engine\org\apache\derby\impl\sql\catalog\SYSALIASESRowFactory.java
M      java\engine\org\apache\derby\iapi\sql\compile\NodeFactory.java
M      java\engine\org\apache\derby\iapi\sql\dictionary\AliasDescriptor.java
M      java\engine\org\apache\derby\iapi\services\io\RegisteredFormatIds.java
M      java\engine\org\apache\derby\iapi\services\io\StoredFormatIds.java
M      java\engine\org\apache\derby\iapi\reference\SQLState.java
M      java\engine\org\apache\derby\catalog\AliasInfo.java
A      java\engine\org\apache\derby\catalog\types\SynonymAliasInfo.java
M      java\engine\org\apache\derby\loc\messages_en.properties
M      java\testing\org\apache\derbyTesting\functionTests\tests\lang\copyfiles.ant
A      java\testing\org\apache\derbyTesting\functionTests\tests\lang\synonym.sql
A      java\testing\org\apache\derbyTesting\functionTests\master\synonym.out
[bandaram:satheesh]

Reply via email to