Generate index for foreign keys in oracle [message #820806] |
Wed, 14 March 2012 11:35  |
Eclipse User |
|
|
|
Hi All,
in our application we found that indexing foreign key fields in the database result in highly increased performance. Therefor I tried to find some eclipselink or JPA setting that enables the automatic generation of indices for foreign key columns.
Unfortunately I found nothing about the topic so I started reading the eclipselink code.
While searching for the proper setting, I found that overriding the org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in my case is quite easy. My class should be added to persistence.xml in the databasePlatform property.
However I found no documentation on overriding the org.eclipse.persistence.tools.schemaframework.TableDefinition class which handles table creation. I would like to add the foreign key creation code to the method just like the createIndexOnPrimaryKeyOnDatabase() and createIndicesOnUniqueKeysOnDatabase() methods.
How can I override TableDefinition with my custom class?
Thanks in advance!
Gábor
|
|
|
|
|
|
Re: Generate index for foreign keys in oracle [message #849837 is a reply to message #848445] |
Thu, 19 April 2012 09:47   |
Eclipse User |
|
|
|
Looks good, except for,
> if (!primKeyList.contains(foreignKey.getName())) {
The name of the foreign key is not the column name, but the constraint name. To do what you want you would need to check if any (or all) of the foreign key fields are in the primary key list.
Also, I would make the shouldCreateIndicesForForeignKeys a variable, as I don't think this is database specific, but application specific. Databases don't create indexes on foreign keys automatically as you do not normally query on foreign keys, foreign keys are use to query primary keys, which are indexed. Foreign keys however are still commonly queried in most applications, both for OneToMany as well as ManyToMany, which is why you see the performance boost. It might even be a good idea to make your new option true by default, and allow a persistence unit property "eclipselink.ddl-generation.index-foreign-keys" to disable it.
|
|
|
|
Powered by
FUDForum. Page generated in 0.07455 seconds