-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Preventing the creation of an index on a foreign key
PostPosted: Fri Apr 21, 2006 2:18 am 
Newbie

Joined: Thu Apr 20, 2006 11:52 am
Posts: 1
I am using SchemaExport to automatically create our database, which has
a fairly simple structure (about 10 entities in total). The schema thus
created is perfect for our purposes, with one little nagging detail.

I have a many-to-one association from entity SDR to entity C. This forces
the creation of an index on a foreign key in SDR. This index is never used
(needed, actually) for the queries we have. Removing it manually even
speeds up the query a bit. Response time requirements are fullfilled
with or without the index, anyway.

SDR may have upto 64E6 rows, and C never has more than about 500.

The main problem, though, is that the index is very large - upto 10% of
total database size. And our space constraints are a bit more severe. For
that reason alone I would like to get rid of the index from the beginning.

I would prefer to be able, through the mappings, to tell SchemaExport
to not create the index - is there a way to do this?

(The various attributes on the many-to-one mapping do not seem to have
effect).

(The alternative is of course to export the DDL, modify it, and then
create the schemas with a script).

Thanks in advance for any help or hints,
Mike

Hibernate version: 3.0.5

Mapping documents:

I have shortened the names and removed extranous properties
for readability purposes.

For SDR:

Code:
<hibernate-mapping>
   <class name="SDR" table="SDR" lazy="true">
      <id name="id" type="long" column="id">
         <generator class="native" />
      </id>

      <property name="numberOfDataRecords" />
      <property name="numberOfUnplausibleData" />

      <property name="minValue" type="float" />
      <property name="maxValue" type="float" />
      <property name="meanValue" type="float" />
      <property name="rmsValue" type="float" />
      <property name="standardDeviation" type="float" />

      
      <many-to-one name="c" class="C"
                   column="C_ID" lazy="proxy" not-null="true"/>

      <many-to-one name="ts" class="TS"
                   column="TS_ID" lazy="proxy" not-null="true" />
      </class>

</hibernate-mapping>


For C:
Code:
<hibernate-mapping>
   <class name="C" table="C" lazy="true">
      <id name="id" type="long" column="id">
         <generator class="native" />
      </id>

      <property name="name" not-null="true" />
      <property name="unit" />
      
      <many-to-one name="p" class="P"
            column="p_id" lazy="false" not-null="true" />
      </class>
</hibernate-mapping>


Name and version of the database you are using:

MySQL, version 4.1


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 10:30 am 
Newbie

Joined: Thu Feb 02, 2006 9:39 am
Posts: 19
I do have the same problem, but it looks like it's the default behaviour many databases to automatically create index on foreign key.

You may want to look at this thread FYI: http://forum.hibernate.org/viewtopic.php?t=924910

So which database and which dialect are you currently using ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.