Creating column indexes with Hibernate
One of the best ways to speed up your application's performance is to create or optimize indexes in your database. On my current project, when we created our database on the AS/400 last week, the DBA noticed that there weren't any indexed created. I expected this and said I'd do some research on creating indexes with Hibernate. Thanks to Gavin, it turns out to be quite simple. Let's say you have an XDoclet tag on a column you want to index. Currently it is:
@hibernate.property column="username" not-null="true"
If you're using Hibernate's <schemaexport> task, you can add an index on this column to your mapping file and it'll create the index when creating the database. To add an index, it's as simple as changing the above XDoclet tag to:
@hibernate.property @hibernate.column name="username" not-null="true" index="index_name"
Now the hard part comes. Which columns should you put indexes on? From what I've heard, it's the ones that you use in where clauses of your queries. I expect one or two per table is sufficient (??). One thing I'm not sure of is: should id columns contain an index?
Posted by Jason Carreira on May 03, 2004 at 06:11 PM MDT #
Posted by Ted on May 03, 2004 at 06:54 PM MDT #
Posted by dsuspense on May 03, 2004 at 08:13 PM MDT #
Posted by Mark on May 03, 2004 at 08:31 PM MDT #
Posted by dsuspense on May 03, 2004 at 08:39 PM MDT #
Posted by Raymond Phillips on May 04, 2004 at 09:09 PM MDT #
Posted by Harun on January 24, 2005 at 07:59 AM MST #
Posted by James Shepherd on October 26, 2005 at 09:56 PM MDT #
Posted by 202.56.245.58 on November 29, 2007 at 10:24 AM MST #
Posted by Lego Programmer on April 23, 2008 at 10:26 AM MDT #
Posted by 59.177.70.74 on March 24, 2009 at 01:46 PM MDT #