You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Mamta Satoor <ms...@gmail.com> on 2005/11/09 08:41:20 UTC

[PATCH](DERBY-573) Provide support for optimizer overrides in Derby

Hi Everyone,
 I have the patch for optimizer overrides support in Derby. Alongwith the
patch, I have attached the updated functional spec to the JIRA entry
Derby-573.
 Majority of the changes went into the sqlgrammar.jj because Derby engine
already has support for them internally. It is the parser that needs to
recognize these overrides and pass it on to through the query nodes. The
parser now looks for character sequence -- DERBY-PROPERTIES (case
insensitive and space between -- and D is optional) and once it finds that,
it looks for propertyName=value pairs on that same comment line in parser's
propertyList method. The parser does the basic check to make sure that the
same property is not used more than once for a given table. The remaining
checks on the properties like checking the existence of user specified index
etc are done in the bind phase.
 I also changed the metadata.properties file to use --DERBY-PROPERTIES
rather than old PROPERTIES clause to supply optimizer overrides. In
addition, added \n at the end of the optimier override comment lines to make
sure the comment line does not get concatenated with the next line of the
sql.
 Import.java had to be changed to user --DERBY-PROPERTIES rather than
PROPERTIES.
 Added a new test optimizerOverrides.sql which runs in both embedded and
network server mode.
 Rerunning all the tests after syncing the codeline to make sure nothing has
broken. An earlier run of the tests before the sync came out clean.
 I plan to next work on exposing these overrides through runtime statistics
so that user can verify that the optimizer overrides are getting used.
 I haven't researched into upgrade much but will the changes in
metadata.properties require some upgrade path for existing databases? Any
pointers here will be very useful.
 svn stat
M java\engine\org\apache\derby\impl\load\Import.java
M java\engine\org\apache\derby\impl\sql\compile\sqlgrammar.jj
M java\engine\org\apache\derby\impl\jdbc\metadata.properties
M java\engine\org\apache\derby\iapi\reference\SQLState.java
M java\engine\org\apache\derby\loc\messages_en.properties
M
java\testing\org\apache\derbyTesting\functionTests\tests\lang\db2Compatibility.sql
M
java\testing\org\apache\derbyTesting\functionTests\tests\lang\copyfiles.ant
A
java\testing\org\apache\derbyTesting\functionTests\tests\lang\optimizerOverrides.sql
M
java\testing\org\apache\derbyTesting\functionTests\tests\lang\checkConstraint.sql
M java\testing\org\apache\derbyTesting\functionTests\tests\store\access.sql
A
java\testing\org\apache\derbyTesting\functionTests\master\DerbyNet\optimizerOverrides.out
M
java\testing\org\apache\derbyTesting\functionTests\master\db2Compatibility.out
A
java\testing\org\apache\derbyTesting\functionTests\master\optimizerOverrides.out
M
java\testing\org\apache\derbyTesting\functionTests\master\checkConstraint.out
M java\testing\org\apache\derbyTesting\functionTests\master\access.out
M java\testing\org\apache\derbyTesting\functionTests\suites\derbylang.runall
M
java\testing\org\apache\derbyTesting\functionTests\suites\derbynetmats.runall
 Comments/questions on the patch?
thanks,
Mamta

Re: [PATCH](DERBY-573) Provide support for optimizer overrides in Derby

Posted by Kathey Marsden <km...@sbcglobal.net>.
Mamta Satoor wrote:

>Hi Satheesh,
>
>Thanks for reviewing the patch.
>
>I think your concern is well founded. A new column in a system table
>referenced by metadata.properties would cause a problem in soft upgrade
>mode. I am not sure if we have run into this in the past and how we handled
>it.
>
With an older version of Cloudscape a few years ago we had a similar
issue where a metadata query referenced a new stored procedure which
didn't exist on an older version and to this day we still struggle with
that unfortunate event because there are errors recompiling stored
prepared statements when reverting   to the previous version.  After
that we changed the Cloudscape code to drop the metadata stored prepared
statements whenever the version changed up or down and let them get
recreated with the new version.  That does not occur with Derby however.

My feeling is that it would be safest in the long run to always drop the
metadata statements whenever the version changes up or down and let them
be recreated  with the current version.   Too late for  existing
versions but a safe  long term strategy.

Just my 2 cents.

Kathey



Re: [PATCH](DERBY-573) Provide support for optimizer overrides in Derby

Posted by Daniel John Debrunner <dj...@debrunners.com>.
Mamta Satoor wrote:

> In order to test my upgrade changes, I have used derbyTesting/upgradeTests/phaseTester.java which was checked in by Dan sometime back. I have changed this test to be a subclass of metadata.java and then I run the existing metadata tests within phaseTester after various stages of upgrade on a 10.1 db.


I don't think that phaseTester should be a sub-class of metadata.java.
It's not a metadata test, it's a "harness" for upgrade tests. You don't
need to sub-class another class to use it.
It would be better to keep a clean spearation between phaseTester and
any sub-tests it calls. Can you create an instance of metadata.java and
execute it from phaseTester? This pattern would then work for other
future similar additions, where as you have set up a pattern that can
not be copied due to Java's single inheritance.

Dan.



Re: [PATCH](DERBY-573) Provide support for optimizer overrides in Derby

Posted by Mamta Satoor <ms...@gmail.com>.
Submitting another patch to JIRA after doing a sync on the client (The
Grant/Revoke checkin touched quite a bit of the files that I have modified).
I have run the tests and no new failures with the patch.

thanks,
Mamta


On 12/12/05, Mamta Satoor <ms...@gmail.com> wrote:
>
> Hi Dan,
>
> I have addressed your comments with the latest patch attached to the JIRA
> entry.
>
> In addition, I have also added a master file for the phaseTester test in
> java\testing\org\apache\derbyTesting\functionTests\master
> Output of the manual run of this test can be diffed against the master
> that I am checking in. In future, if anyone changes this test such that it's
> output will change, then they should change the master file accordingly.
> This way, we can make sure that the test is still running correctly as it is
> evolving. Once this test is run as part of a suite like other tests, we will
> not have to run this test manually and any changes to master will be caught
> easily,
>
> Also, here is the svn stat output which I forgot to attach to my previous
> patch emails.
> M      java\engine\org\apache\derby\impl\load\Import.java
> M      java\engine\org\apache\derby\impl\sql\GenericStatement.java
> M      java\engine\org\apache\derby\impl\sql\compile\sqlgrammar.jj
> M
> java\engine\org\apache\derby\impl\sql\conn\GenericLanguageConnectionContext.java
>
> M
> java\engine\org\apache\derby\impl\sql\catalog\DataDictionaryImpl.java
> M      java\engine\org\apache\derby\impl\sql\catalog\DD_Version.java
> M      java\engine\org\apache\derby\impl\jdbc\metadata.properties
> M      java\engine\org\apache\derby\impl\jdbc\EmbedStatement.java
> M      java\engine\org\apache\derby\impl\jdbc\EmbedDatabaseMetaData.java
> M      java\engine\org\apache\derby\impl\jdbc\EmbedPreparedStatement.java
> M      java\engine\org\apache\derby\iapi\sql\Statement.java
> M
> java\engine\org\apache\derby\iapi\sql\conn\LanguageConnectionContext.java
> M
> java\engine\org\apache\derby\iapi\sql\dictionary\DataDictionary.java
> M      java\engine\org\apache\derby\iapi\reference\SQLState.java
> M      java\engine\org\apache\derby\loc\messages_en.properties
> M
> java\testing\org\apache\derbyTesting\functionTests\tests\lang\db2Compatibility.sql
>
> M
> java\testing\org\apache\derbyTesting\functionTests\tests\lang\copyfiles.ant
> A
> java\testing\org\apache\derbyTesting\functionTests\tests\lang\optimizerOverrides.sql
> M
> java\testing\org\apache\derbyTesting\functionTests\tests\lang\checkConstraint.sql
>
> D
> java\testing\org\apache\derbyTesting\functionTests\tests\jdbcapi\metadataJdbc20.java
> M
> java\testing\org\apache\derbyTesting\functionTests\tests\jdbcapi\metadata_test.java
> M
> java\testing\org\apache\derbyTesting\functionTests\tests\jdbcapi\metadata.java
>
> M
> java\testing\org\apache\derbyTesting\functionTests\tests\store\access.sql
> M
> java\testing\org\apache\derbyTesting\functionTests\master\DerbyNet\metadata.out
> D
> java\testing\org\apache\derbyTesting\functionTests\master\DerbyNet\metadataJdbc20.out
>
> M
> java\testing\org\apache\derbyTesting\functionTests\master\DerbyNet\odbc_metadata.out
> A
> java\testing\org\apache\derbyTesting\functionTests\master\DerbyNet\optimizerOverrides.out
> M
> java\testing\org\apache\derbyTesting\functionTests\master\db2Compatibility.out
>
> D
> java\testing\org\apache\derbyTesting\functionTests\master\metadataJdbc20.out
> M
> java\testing\org\apache\derbyTesting\functionTests\master\DerbyNetClient\metadata.out
> D
> java\testing\org\apache\derbyTesting\functionTests\master\DerbyNetClient\metadataJdbc20.out
>
> M
> java\testing\org\apache\derbyTesting\functionTests\master\DerbyNetClient\odbc_metadata.out
> A
> java\testing\org\apache\derbyTesting\functionTests\master\DerbyNetClient\optimizerOverrides.out
> D
> java\testing\org\apache\derbyTesting\functionTests\master\j9_foundation\metadataJdbc20.out
>
> A
> java\testing\org\apache\derbyTesting\functionTests\master\optimizerOverrides.out
> M
> java\testing\org\apache\derbyTesting\functionTests\master\checkConstraint.out
> M
> java\testing\org\apache\derbyTesting\functionTests\master\metadata.out
> M
> java\testing\org\apache\derbyTesting\functionTests\master\access.out
> M
> java\testing\org\apache\derbyTesting\functionTests\master\odbc_metadata.out
> A
> java\testing\org\apache\derbyTesting\functionTests\master\phaseTester.out
> M
> java\testing\org\apache\derbyTesting\functionTests\suites\jdbc20.runall
> M
> java\testing\org\apache\derbyTesting\functionTests\suites\derbylang.runall
> M
> java\testing\org\apache\derbyTesting\functionTests\suites\derbynetmats.runall
>
> M      java\testing\org\apache\derbyTesting\upgradeTests\phaseTester.java
> M      java\testing\org\apache\derbyTesting\upgradeTests\runphases.ksh
>
>
> thanks,
> Mamta
>
>
>  On 12/8/05, Daniel John Debrunner <dj...@debrunners.com> wrote:
> >
> > Mamta Satoor wrote:
> >
> > Thanks for the patch. I looked mainly at the soft/hard upgrade code.
> >
> > - Good to add comments to the upgrade code you added in
> > DD_Version.doFullUpgrade. I'd assumed it was incorrectly using
> > DD_VERSION_THIS_SOFTWARE_VERSION instead of DD_VERSION_DERBY_10_2, but I
> > think this is the generic upgrade code you mention in the jira comments.
> > Though why do you need to check the version at this point, the higher
> > code has decided that a full upgrade is required?
> >
> > - In EmbedDatabaseMetaData.notInSoftUpgradeMode the comments about 'not
> > changing the system tables' I think are misleading. I think you mean the
> >
> > stored versions of the JDBC database meta data queries. To me, changing
> > the system tables means things like adding a column to a system table.
> >
> > - DataDictionary.DD_VERSION_THIS_SOFTWARE_VERSION - there was already a
> > mechanism to check that the database had been upgraded to the current
> > verion, using checkVersion with DataDictionary.DD_VERSION_CURRENT. Thus
> > this new field can be removed. (I think).
> >
> > - The new method LanguageConnectionContext.prepareInternalStatement , is
> > the fourth parameter really 'forMetaData' or more generically
> > 'allowInternalSyntax'? I've spent time over the last two years trying to
> > decrease the number of prepare methods in the code, so I'm not thrilled
> > to see a new one. Especially as it's probably only used for meta-data,
> > so the last two parameters are fixed 'true, true', thus if you wanted a
> > prepared for meta-data only method, you could get away with a two
> > argument one, maybe even one as the schema descriptor should not be
> > required.
> >
> > This additional prepare method comes out of the soft upgrade code for
> > database meta data, I'd like to try and spend some time before Sat
> > seeing if there's an alternative. I thought there was some code to
> > already handle this type of case which would mean no changes to
> > EmbedDatabaseMetaData were required.
> >
> > I think this patch also addresses DERBY-727, add the upgrade framework.
> >
> >
> > Dan.
> >
> >
> >
>

Re: [PATCH](DERBY-573) Provide support for optimizer overrides in Derby

Posted by Mamta Satoor <ms...@gmail.com>.
Hi Dan,

I have addressed your comments with the latest patch attached to the JIRA
entry.

In addition, I have also added a master file for the phaseTester test in
java\testing\org\apache\derbyTesting\functionTests\master
Output of the manual run of this test can be diffed against the master that
I am checking in. In future, if anyone changes this test such that it's
output will change, then they should change the master file accordingly.
This way, we can make sure that the test is still running correctly as it is
evolving. Once this test is run as part of a suite like other tests, we will
not have to run this test manually and any changes to master will be caught
easily,

Also, here is the svn stat output which I forgot to attach to my previous
patch emails.
M      java\engine\org\apache\derby\impl\load\Import.java
M      java\engine\org\apache\derby\impl\sql\GenericStatement.java
M      java\engine\org\apache\derby\impl\sql\compile\sqlgrammar.jj
M
java\engine\org\apache\derby\impl\sql\conn\GenericLanguageConnectionContext.java
M      java\engine\org\apache\derby\impl\sql\catalog\DataDictionaryImpl.java
M      java\engine\org\apache\derby\impl\sql\catalog\DD_Version.java
M      java\engine\org\apache\derby\impl\jdbc\metadata.properties
M      java\engine\org\apache\derby\impl\jdbc\EmbedStatement.java
M      java\engine\org\apache\derby\impl\jdbc\EmbedDatabaseMetaData.java
M      java\engine\org\apache\derby\impl\jdbc\EmbedPreparedStatement.java
M      java\engine\org\apache\derby\iapi\sql\Statement.java
M
java\engine\org\apache\derby\iapi\sql\conn\LanguageConnectionContext.java
M      java\engine\org\apache\derby\iapi\sql\dictionary\DataDictionary.java
M      java\engine\org\apache\derby\iapi\reference\SQLState.java
M      java\engine\org\apache\derby\loc\messages_en.properties
M
java\testing\org\apache\derbyTesting\functionTests\tests\lang\db2Compatibility.sql
M
java\testing\org\apache\derbyTesting\functionTests\tests\lang\copyfiles.ant
A
java\testing\org\apache\derbyTesting\functionTests\tests\lang\optimizerOverrides.sql
M
java\testing\org\apache\derbyTesting\functionTests\tests\lang\checkConstraint.sql
D
java\testing\org\apache\derbyTesting\functionTests\tests\jdbcapi\metadataJdbc20.java
M
java\testing\org\apache\derbyTesting\functionTests\tests\jdbcapi\metadata_test.java
M
java\testing\org\apache\derbyTesting\functionTests\tests\jdbcapi\metadata.java
M
java\testing\org\apache\derbyTesting\functionTests\tests\store\access.sql
M
java\testing\org\apache\derbyTesting\functionTests\master\DerbyNet\metadata.out
D
java\testing\org\apache\derbyTesting\functionTests\master\DerbyNet\metadataJdbc20.out
M
java\testing\org\apache\derbyTesting\functionTests\master\DerbyNet\odbc_metadata.out
A
java\testing\org\apache\derbyTesting\functionTests\master\DerbyNet\optimizerOverrides.out
M
java\testing\org\apache\derbyTesting\functionTests\master\db2Compatibility.out
D
java\testing\org\apache\derbyTesting\functionTests\master\metadataJdbc20.out
M
java\testing\org\apache\derbyTesting\functionTests\master\DerbyNetClient\metadata.out
D
java\testing\org\apache\derbyTesting\functionTests\master\DerbyNetClient\metadataJdbc20.out
M
java\testing\org\apache\derbyTesting\functionTests\master\DerbyNetClient\odbc_metadata.out
A
java\testing\org\apache\derbyTesting\functionTests\master\DerbyNetClient\optimizerOverrides.out
D
java\testing\org\apache\derbyTesting\functionTests\master\j9_foundation\metadataJdbc20.out
A
java\testing\org\apache\derbyTesting\functionTests\master\optimizerOverrides.out
M
java\testing\org\apache\derbyTesting\functionTests\master\checkConstraint.out
M
java\testing\org\apache\derbyTesting\functionTests\master\metadata.out
M      java\testing\org\apache\derbyTesting\functionTests\master\access.out
M
java\testing\org\apache\derbyTesting\functionTests\master\odbc_metadata.out
A
java\testing\org\apache\derbyTesting\functionTests\master\phaseTester.out
M
java\testing\org\apache\derbyTesting\functionTests\suites\jdbc20.runall
M
java\testing\org\apache\derbyTesting\functionTests\suites\derbylang.runall
M
java\testing\org\apache\derbyTesting\functionTests\suites\derbynetmats.runall
M      java\testing\org\apache\derbyTesting\upgradeTests\phaseTester.java
M      java\testing\org\apache\derbyTesting\upgradeTests\runphases.ksh


thanks,
Mamta


On 12/8/05, Daniel John Debrunner <dj...@debrunners.com> wrote:
>
> Mamta Satoor wrote:
>
> Thanks for the patch. I looked mainly at the soft/hard upgrade code.
>
> - Good to add comments to the upgrade code you added in
> DD_Version.doFullUpgrade. I'd assumed it was incorrectly using
> DD_VERSION_THIS_SOFTWARE_VERSION instead of DD_VERSION_DERBY_10_2, but I
> think this is the generic upgrade code you mention in the jira comments.
> Though why do you need to check the version at this point, the higher
> code has decided that a full upgrade is required?
>
> - In EmbedDatabaseMetaData.notInSoftUpgradeMode the comments about 'not
> changing the system tables' I think are misleading. I think you mean the
> stored versions of the JDBC database meta data queries. To me, changing
> the system tables means things like adding a column to a system table.
>
> - DataDictionary.DD_VERSION_THIS_SOFTWARE_VERSION - there was already a
> mechanism to check that the database had been upgraded to the current
> verion, using checkVersion with DataDictionary.DD_VERSION_CURRENT. Thus
> this new field can be removed. (I think).
>
> - The new method LanguageConnectionContext.prepareInternalStatement, is
> the fourth parameter really 'forMetaData' or more generically
> 'allowInternalSyntax'? I've spent time over the last two years trying to
> decrease the number of prepare methods in the code, so I'm not thrilled
> to see a new one. Especially as it's probably only used for meta-data,
> so the last two parameters are fixed 'true, true', thus if you wanted a
> prepared for meta-data only method, you could get away with a two
> argument one, maybe even one as the schema descriptor should not be
> required.
>
> This additional prepare method comes out of the soft upgrade code for
> database meta data, I'd like to try and spend some time before Sat
> seeing if there's an alternative. I thought there was some code to
> already handle this type of case which would mean no changes to
> EmbedDatabaseMetaData were required.
>
> I think this patch also addresses DERBY-727, add the upgrade framework.
>
>
> Dan.
>
>
>

Re: [PATCH](DERBY-573) Provide support for optimizer overrides in Derby

Posted by Daniel John Debrunner <dj...@debrunners.com>.
Mamta Satoor wrote:

Thanks for the patch. I looked mainly at the soft/hard upgrade code.

- Good to add comments to the upgrade code you added in
DD_Version.doFullUpgrade. I'd assumed it was incorrectly using
DD_VERSION_THIS_SOFTWARE_VERSION instead of DD_VERSION_DERBY_10_2, but I
think this is the generic upgrade code you mention in the jira comments.
Though why do you need to check the version at this point, the higher
code has decided that a full upgrade is required?

- In EmbedDatabaseMetaData.notInSoftUpgradeMode the comments about 'not
changing the system tables' I think are misleading. I think you mean the
stored versions of the JDBC database meta data queries. To me, changing
the system tables means things like adding a column to a system table.

- DataDictionary.DD_VERSION_THIS_SOFTWARE_VERSION - there was already a
mechanism to check that the database had been upgraded to the current
verion, using checkVersion with DataDictionary.DD_VERSION_CURRENT. Thus
this new field can be removed. (I think).

- The new method LanguageConnectionContext.prepareInternalStatement, is
the fourth parameter really 'forMetaData' or more generically
'allowInternalSyntax'? I've spent time over the last two years trying to
decrease the number of prepare methods in the code, so I'm not thrilled
to see a new one. Especially as it's probably only used for meta-data,
so the last two parameters are fixed 'true, true', thus if you wanted a
prepared for meta-data only method, you could get away with a two
argument one, maybe even one as the schema descriptor should not be
required.

This additional prepare method comes out of the soft upgrade code for
database meta data, I'd like to try and spend some time before Sat
seeing if there's an alternative. I thought there was some code to
already handle this type of case which would mean no changes to
EmbedDatabaseMetaData were required.

I think this patch also addresses DERBY-727, add the upgrade framework.


Dan.



Re: [PATCH](DERBY-573) Provide support for optimizer overrides in Derby

Posted by Mamta Satoor <ms...@gmail.com>.
Hi Satheesh,

Thanks for reviewing the patch.

I think your concern is well founded. A new column in a system table
referenced by metadata.properties would cause a problem in soft upgrade
mode. I am not sure if we have run into this in the past and how we handled
it. One way would be in soft upgrade mode, we should catch exceptions thrown
by metadata.properties queries and nest it inside a more generic exception
which will say that the metadata query may not be suitable to run in soft
upgrade mode. I realize this is not very graceful, just a thought from top
of my head. Any other suggestions from anyone?

Mamta


On 12/8/05, Satheesh Bandaram <sa...@sourcery.org> wrote:
>
> I will review this change and hope to commit it, if everything looks
> good. Let me know if anyone else is also planning on review or already
> have review comments. Thanks for the good write up too and researching
> soft/hard upgrades.
>
> I have one question about the following... What happens if 10.2
> metadata.properties change in a way that is not compatible with a 10.1
> database? For example, I may have to add a column to SYSALIAS system
> table. If I use this column (I may not actually need to) in 10.2
> metadata.properties, wouldn't that cause problem with soft upgrade and
> 10.1 database?
>
> Satheesh
>
> Mamta Satoor wrote:
>
> > Following is a brief description of upgrade code
> > 1)If a 10.1 db is getting run in soft upgrade mode with 10.2, the
> > system tables would still have the old 10.1 optimizer overrides syntax
> > which is not recognized by 10.2 The system tables of the 10.1 db can't
> > be modified in soft upgrade mode to store the new 10.2 optimizer
> > overrides syntax for metadata queries because in soft upgrade, system
> > tables can't be modified in a backward incompatible way. To get around
> > this, I have changed the code in EmbedDatabaseMetaData.java to see if
> > db is getting run in soft upgrade mode. If yes, then it should read
> > the metadata queries from metadata.properties rather than system
> > tables. This will work because metadata.properties for 10.2 release
> > has been modified to use the new optimizer overrides syntax.
> >
>
>

Re: [PATCH](DERBY-573) Provide support for optimizer overrides in Derby

Posted by Satheesh Bandaram <sa...@Sourcery.Org>.
I will review this change and hope to commit it, if everything looks
good. Let me know if anyone else is also planning on review or already
have review comments. Thanks for the good write up too and researching
soft/hard upgrades.

I have one question about the following... What happens if 10.2
metadata.properties change in a way that is not compatible with a 10.1
database? For example, I may have to add a column to SYSALIAS system
table. If I use this column (I may not actually need to) in 10.2
metadata.properties, wouldn't that cause problem with soft upgrade and
10.1 database?

Satheesh

Mamta Satoor wrote:

> Following is a brief description of upgrade code
> 1)If a 10.1 db is getting run in soft upgrade mode with 10.2, the
> system tables would still have the old 10.1 optimizer overrides syntax
> which is not recognized by 10.2 The system tables of the 10.1 db can't
> be modified in soft upgrade mode to store the new 10.2 optimizer
> overrides syntax for metadata queries because in soft upgrade, system
> tables can't be modified in a backward incompatible way. To get around
> this, I have changed the code in EmbedDatabaseMetaData.java to see if
> db is getting run in soft upgrade mode. If yes, then it should read
> the metadata queries from metadata.properties rather than system
> tables. This will work because metadata.properties for 10.2 release
> has been modified to use the new optimizer overrides syntax.
>


Re: [PATCH](DERBY-573) Provide support for optimizer overrides in Derby

Posted by Mamta Satoor <ms...@gmail.com>.
Hi Everyone,

Here is the updated patch information which includes optimizer overrides
support and database upgrade code. I have attached the patch to the Jira
entry.

The code for optimizer overrides support is same as for the earlier patch.
But since the metadata.properties has changed between 10.1 and 10.2 (because
of the new user visible optimizer overrides syntax), we need to have proper
upgrade code to support this change.

Following is a brief description of upgrade code
1)If a 10.1 db is getting run in soft upgrade mode with 10.2, the system
tables would still have the old 10.1 optimizer overrides syntax which is not
recognized by 10.2 The system tables of the 10.1 db can't be modified in
soft upgrade mode to store the new 10.2 optimizer overrides syntax for
metadata queries because in soft upgrade, system tables can't be modified in
a backward incompatible way. To get around this, I have changed the code in
EmbedDatabaseMetaData.java to see if db is getting run in soft upgrade mode.
If yes, then it should read the metadata queries from
metadata.propertiesrather than system tables. This will work because
metadata.properties for 10.2 release has been modified to use the new
optimizer overrides syntax.

2)If a 10.1 db is getting run in hard upgrade mode with 10.2, then we can
simply drop the stored queries for metadata calls from system tables and put
new queries from metadata.properties into the system table. This is
acceptable in hard upgrade, because 10.2 db is not expected to run in
10.1release. This code is in DD_version.java

3)I have implemented the above 2 upgrade modes in a generic mode such that
in future, with every new release, in soft upgrade mode, we will always read
the metadata queries from metadata.properties. And in hard uprgade mode, we
will drop and recreate the stored metadata queries in the system tables with
the latest metadata queries from metadata.properties. This will take care of
any future metadata.properties changes between the releases.

A little description on changes made to some of the java files for the
upgrade code
1)Added new methods in Statement.java and
LanguageConnectionContext.javawhich will allow us to recognize the
queries coming from metadata calls and
let such queries use internal SQL syntax. These internal SQL syntaxes are
not available to an end user but we have some queries in
metadata.propertieswhich rely on them and hence we need to be able to
run these queries with
their internal syntax. This was not required in the past because metadata
calls were always run from the system tables and hence the internal syntax
was available to metadata calls at that point. Now, that in soft upgrade
mode, we read the queries from metadata.properties file, we need to add
these special methods to recognize metadata queries as special internal
queries and let them use internal SQL syntax.
2)In DataDictionary.java, I have added 2 final static variables. One is
added to reflect the 10.2 db version, DD_VERSION_DERBY_10_2. The other one
is DD_VERSION_THIS_SOFTWARE_VERSION and with every release, it should be
updated to the latest DD version final static number. This variable will be
used by EmbeddedDatabaseMetaData to determine if we are in soft upgrade
mode. Rather than hardcoding 10.2 DD version in EmbeddedDatabaseMetaData, I
thought it would be better to use a generice variable
DD_VERSION_THIS_SOFTWARE_VERSION.

In order to test my upgrade changes, I have used
derbyTesting/upgradeTests/phaseTester.java which was checked in by Dan
sometime back. I have changed this test to be a subclass of
metadata.javaand then I run the existing metadata tests within
phaseTester after various
stages of upgrade on a 10.1 db. phaseTester takes 4 parameters, the old
derby major version, old derby minor version, old engine
derby.jarclasspath, new engine
derby.jar and derbyTesting.jar classpath. An eg run is as follows
$
C:/p4clients/main/opensource/java/testing/org/apache/derbyTesting/upgradeTests/runphases
10 1 c:/p4clients/code101/opensource/jars/sane
c:/p4clients/main/opensource/jars/sane
For the command above, phaseTester will
1)first create a 10.1 db and then will run metadata tests on it.
2)Then run the 10.1 db with 10.2 software in soft upgrade mode and run the
metadata tests on it (this is where the metadata sql will be picked from
metadata.properties rather than system table)
3)The run the soft upgraded 10.1 db back with 10.1 software and rerun the
metadata tests
4)Now run the 10.1 db in hard upgrade mode with 10.2 software. The db will
be upgraded to 10.2 version (which means that stored metadata sql from
system tables will be dropped and recreated with sql from
metadata.properties). Run the metadata tests on this hard upgraded db
5)Finally, try to use this upgraded 10.2 db with 10.1 software and that will
fail because we don't have backward compatibility.

This phaseTester test unfortunately is not part of derbyall and has to be
run manually. I think we have a beetle entry Derby-514 to make this test
available as part of a suite rather than requiring manual runs.

One another note on the tests, I have merged metadataJdbc20 and
metadata.java into one single test by moving all the tests from
metadataJdbc20 to metadata.java's super class metadata_test.java. In the
past when we had support from jdk18, we had to have a separate
test for jdbc20 but since jdk18 support has been phased out, these tests can
be merged.

Also, for reference, I have included the comments for the actual optimizer
overrides changes from the previous patch.
Majority of the changes went into the sqlgrammar.jj because Derby engine
already has support for them internally. It is the parser that needs to
recognize these overrides and pass it on to through the query nodes. The
parser now looks for character sequence -- DERBY-PROPERTIES (case
insensitive and space between -- and D is optional) and once it finds that,
it looks for propertyName=value pairs on that same comment line in parser's
propertyList method. The parser does the basic check to make sure that the
same property is not used more than once for a given table. The remaining
checks on the properties like checking the existence of user specified index
etc are done in the bind phase.

I also changed the metadata.properties file to use --DERBY-PROPERTIES rather
than old PROPERTIES clause to supply optimizer overrides. In addition, added
\n at the end of the optimier override comment lines to make sure the
comment line does not get concatenated with the next line of the sql.

Import.java had to be changed to user --DERBY-PROPERTIES rather than
PROPERTIES.

Added a new test optimizerOverrides.sql which runs in both embedded and
network server mode.

Finally, I have run the derbyall suite and these changes didn't cause any
new failures.

Please review and send in your comments.
Mamta
On 12/6/05, Satheesh Bandaram <sa...@sourcery.org> wrote:
>
> Great! It will be interesting to see how you are handling soft and hard
> upgrades. I will wait for the new patch to start the review.
>
> Satheesh
>
> Mamta Satoor wrote:
>
> Thanks, Satheesh, for the update. But I am very close to submitting a new
> patch for this functionality which will also include soft and hard upgrade
> to 10.2 So, give me a day or two to submit the new patch and then you
> (and anyone else who might be interested) can review that patch.
>
> thanks,
> Mamta
>
>
> On 12/6/05, Satheesh Bandaram <sa...@sourcery.org> wrote:
> >
> > Hi Mamta,
> >
> > I will review with the goal of committing this patch this week. THANKS
> > for being patient... I was held up trying to get my GrantRevoke Part I patch
> > out last few weeks.
> >
> > Satheesh
> >
> > Mamta Satoor wrote:
> >
> > Hi Everyone,
> >
> > I posted this patch about 20days back. Does anyone have any feedback on
> > the patch? Is it good to go?
> >
> > thanks,
> > Mamta
> >
> >
> > On 11/8/05, Mamta Satoor <ms...@gmail.com> wrote:
> > >
> > > Hi Everyone,
> > >
> > > I have the patch for optimizer overrides support in Derby. Alongwith
> > > the patch, I have attached the updated functional spec to the JIRA
> > > entry Derby-573.
> > >
> > > Majority of the changes went into the sqlgrammar.jj because Derby
> > > engine already has support for them internally. It is the parser that needs
> > > to recognize these overrides and pass it on to through the query nodes.
> > > The parser now looks for character sequence -- DERBY-PROPERTIES (case
> > > insensitive and space between -- and D is optional) and once it finds that,
> > > it looks for propertyName=value pairs on that same comment line in parser's
> > > propertyList method. The parser does the basic check to make sure that the
> > > same property is not used more than once for a given table. The remaining
> > > checks on the properties like checking the existence of user specified
> > > index etc are done in the bind phase.
> > >
> > > I also changed the metadata.properties file to use --DERBY-PROPERTIES
> > > rather than old PROPERTIES clause to supply optimizer overrides. In
> > > addition, added \n at the end of the optimier override comment lines
> > > to make sure the comment line does not get concatenated with the next line
> > > of the sql.
> > >
> > > Import.java had to be changed to user --DERBY-PROPERTIES rather than
> > > PROPERTIES.
> > >
> > > Added a new test optimizerOverrides.sql which runs in both embedded
> > > and network server mode.
> > >
> > > Rerunning all the tests after syncing the codeline to make sure
> > > nothing has broken. An earlier run of the tests before the sync came out
> > > clean.
> > >
> > > I plan to next work on exposing these overrides through runtime
> > > statistics so that user can verify that the optimizer overrides are
> > > getting used.
> > >
> > > I haven't researched into upgrade much but will the changes in
> > > metadata.properties require some upgrade path for existing databases?
> > > Any pointers here will be very useful.
> > >
> > > svn stat
> > > M      java\engine\org\apache\derby\impl\load\Import.java
> > > M      java\engine\org\apache\derby\impl\sql\compile\sqlgrammar.jj
> > > M      java\engine\org\apache\derby\impl\jdbc\metadata.properties
> > > M      java\engine\org\apache\derby\iapi\reference\SQLState.java
> > > M      java\engine\org\apache\derby\loc\messages_en.properties
> > > M
> > > java\testing\org\apache\derbyTesting\functionTests\tests\lang\db2Compatibility.sql
> > > M
> > > java\testing\org\apache\derbyTesting\functionTests\tests\lang\copyfiles.ant
> > > A
> > > java\testing\org\apache\derbyTesting\functionTests\tests\lang\optimizerOverrides.sql
> > > M
> > > java\testing\org\apache\derbyTesting\functionTests\tests\lang\checkConstraint.sql
> > > M
> > > java\testing\org\apache\derbyTesting\functionTests\tests\store\access.sql
> > > A
> > > java\testing\org\apache\derbyTesting\functionTests\master\DerbyNet\optimizerOverrides.out
> > > M
> > > java\testing\org\apache\derbyTesting\functionTests\master\db2Compatibility.out
> > > A
> > > java\testing\org\apache\derbyTesting\functionTests\master\optimizerOverrides.out
> > >
> > > M
> > > java\testing\org\apache\derbyTesting\functionTests\master\checkConstraint.out
> > > M
> > > java\testing\org\apache\derbyTesting\functionTests\master\access.out
> > > M
> > > java\testing\org\apache\derbyTesting\functionTests\suites\derbylang.runall
> > > M
> > > java\testing\org\apache\derbyTesting\functionTests\suites\derbynetmats.runall
> > >
> > > Comments/questions on the patch?
> > > thanks,
> > > Mamta
> > >
> >
> >
>

Re: [PATCH](DERBY-573) Provide support for optimizer overrides in Derby

Posted by Mamta Satoor <ms...@gmail.com>.
Thanks, Satheesh, for the update. But I am very close to submitting a new
patch for this functionality which will also include soft and hard upgrade
to 10.2 So, give me a day or two to submit the new patch and then you
(and anyone else who might be interested) can review that patch.

thanks,
Mamta


On 12/6/05, Satheesh Bandaram <sa...@sourcery.org> wrote:
>
> Hi Mamta,
>
> I will review with the goal of committing this patch this week. THANKS for
> being patient... I was held up trying to get my GrantRevoke Part I patch out
> last few weeks.
>
> Satheesh
>
> Mamta Satoor wrote:
>
> Hi Everyone,
>
> I posted this patch about 20days back. Does anyone have any feedback on
> the patch? Is it good to go?
>
> thanks,
> Mamta
>
>
> On 11/8/05, Mamta Satoor <ms...@gmail.com> wrote:
> >
> > Hi Everyone,
> >
> > I have the patch for optimizer overrides support in Derby. Alongwith the
> > patch, I have attached the updated functional spec to the JIRA entry
> > Derby-573.
> >
> > Majority of the changes went into the sqlgrammar.jj because Derby engine
> > already has support for them internally. It is the parser that needs to
> > recognize these overrides and pass it on to through the query nodes.
> > The parser now looks for character sequence -- DERBY-PROPERTIES (case
> > insensitive and space between -- and D is optional) and once it finds that,
> > it looks for propertyName=value pairs on that same comment line in parser's
> > propertyList method. The parser does the basic check to make sure that the
> > same property is not used more than once for a given table. The remaining
> > checks on the properties like checking the existence of user specified
> > index etc are done in the bind phase.
> >
> > I also changed the metadata.properties file to use --DERBY-PROPERTIES
> > rather than old PROPERTIES clause to supply optimizer overrides. In
> > addition, added \n at the end of the optimier override comment lines to
> > make sure the comment line does not get concatenated with the next line of
> > the sql.
> >
> > Import.java had to be changed to user --DERBY-PROPERTIES rather than
> > PROPERTIES.
> >
> > Added a new test optimizerOverrides.sql which runs in both embedded and
> > network server mode.
> >
> > Rerunning all the tests after syncing the codeline to make sure nothing
> > has broken. An earlier run of the tests before the sync came out clean.
> >
> > I plan to next work on exposing these overrides through runtime
> > statistics so that user can verify that the optimizer overrides are
> > getting used.
> >
> > I haven't researched into upgrade much but will the changes in
> > metadata.properties require some upgrade path for existing databases?
> > Any pointers here will be very useful.
> >
> > svn stat
> > M      java\engine\org\apache\derby\impl\load\Import.java
> > M      java\engine\org\apache\derby\impl\sql\compile\sqlgrammar.jj
> > M      java\engine\org\apache\derby\impl\jdbc\metadata.properties
> > M      java\engine\org\apache\derby\iapi\reference\SQLState.java
> > M      java\engine\org\apache\derby\loc\messages_en.properties
> > M
> > java\testing\org\apache\derbyTesting\functionTests\tests\lang\db2Compatibility.sql
> > M
> > java\testing\org\apache\derbyTesting\functionTests\tests\lang\copyfiles.ant
> > A
> > java\testing\org\apache\derbyTesting\functionTests\tests\lang\optimizerOverrides.sql
> > M
> > java\testing\org\apache\derbyTesting\functionTests\tests\lang\checkConstraint.sql
> > M
> > java\testing\org\apache\derbyTesting\functionTests\tests\store\access.sql
> > A
> > java\testing\org\apache\derbyTesting\functionTests\master\DerbyNet\optimizerOverrides.out
> > M
> > java\testing\org\apache\derbyTesting\functionTests\master\db2Compatibility.out
> > A
> > java\testing\org\apache\derbyTesting\functionTests\master\optimizerOverrides.out
> >
> > M
> > java\testing\org\apache\derbyTesting\functionTests\master\checkConstraint.out
> > M
> > java\testing\org\apache\derbyTesting\functionTests\master\access.out
> > M
> > java\testing\org\apache\derbyTesting\functionTests\suites\derbylang.runall
> > M
> > java\testing\org\apache\derbyTesting\functionTests\suites\derbynetmats.runall
> >
> > Comments/questions on the patch?
> > thanks,
> > Mamta
> >
>
>

Re: [PATCH](DERBY-573) Provide support for optimizer overrides in Derby

Posted by Mamta Satoor <ms...@gmail.com>.
Hi Everyone,

I posted this patch about 20days back. Does anyone have any feedback on the
patch? Is it good to go?

thanks,
Mamta


On 11/8/05, Mamta Satoor <ms...@gmail.com> wrote:
>
> Hi Everyone,
>
> I have the patch for optimizer overrides support in Derby. Alongwith the
> patch, I have attached the updated functional spec to the JIRA entry
> Derby-573.
>
> Majority of the changes went into the sqlgrammar.jj because Derby engine
> already has support for them internally. It is the parser that needs to
> recognize these overrides and pass it on to through the query nodes.
> The parser now looks for character sequence -- DERBY-PROPERTIES (case
> insensitive and space between -- and D is optional) and once it finds that,
> it looks for propertyName=value pairs on that same comment line in parser's
> propertyList method. The parser does the basic check to make sure that the
> same property is not used more than once for a given table. The remaining
> checks on the properties like checking the existence of user specified
> index etc are done in the bind phase.
>
> I also changed the metadata.properties file to use --DERBY-PROPERTIES
> rather than old PROPERTIES clause to supply optimizer overrides. In
> addition, added \n at the end of the optimier override comment lines to
> make sure the comment line does not get concatenated with the next line of
> the sql.
>
> Import.java had to be changed to user --DERBY-PROPERTIES rather than
> PROPERTIES.
>
> Added a new test optimizerOverrides.sql which runs in both embedded and
> network server mode.
>
> Rerunning all the tests after syncing the codeline to make sure nothing
> has broken. An earlier run of the tests before the sync came out clean.
>
> I plan to next work on exposing these overrides through runtime statistics
> so that user can verify that the optimizer overrides are getting used.
>
> I haven't researched into upgrade much but will the changes in
> metadata.properties require some upgrade path for existing databases? Any
> pointers here will be very useful.
>
> svn stat
> M      java\engine\org\apache\derby\impl\load\Import.java
> M      java\engine\org\apache\derby\impl\sql\compile\sqlgrammar.jj
> M      java\engine\org\apache\derby\impl\jdbc\metadata.properties
> M      java\engine\org\apache\derby\iapi\reference\SQLState.java
> M      java\engine\org\apache\derby\loc\messages_en.properties
> M
> java\testing\org\apache\derbyTesting\functionTests\tests\lang\db2Compatibility.sql
> M
> java\testing\org\apache\derbyTesting\functionTests\tests\lang\copyfiles.ant
> A
> java\testing\org\apache\derbyTesting\functionTests\tests\lang\optimizerOverrides.sql
> M
> java\testing\org\apache\derbyTesting\functionTests\tests\lang\checkConstraint.sql
> M
> java\testing\org\apache\derbyTesting\functionTests\tests\store\access.sql
> A
> java\testing\org\apache\derbyTesting\functionTests\master\DerbyNet\optimizerOverrides.out
> M
> java\testing\org\apache\derbyTesting\functionTests\master\db2Compatibility.out
> A
> java\testing\org\apache\derbyTesting\functionTests\master\optimizerOverrides.out
>
> M
> java\testing\org\apache\derbyTesting\functionTests\master\checkConstraint.out
> M
> java\testing\org\apache\derbyTesting\functionTests\master\access.out
> M
> java\testing\org\apache\derbyTesting\functionTests\suites\derbylang.runall
> M
> java\testing\org\apache\derbyTesting\functionTests\suites\derbynetmats.runall
>
> Comments/questions on the patch?
> thanks,
> Mamta
>