"With
the InnoDB storage
engine, the table data is physically organized to do ultra-fast
lookups and sorts based on the primary key column or columns."
Therefore I think in many situations having an autogenerated index (whereby the data would be organized physically in chronological (insert) order) could lead to poor performance (even if you have indexes for your queries). Imagine you have your own version of google finance; one way to implement this would be to have a table asset_price that references an asset (apple share for example) and that has a price for a specific date. Something of the sort:
create table asset_price (
asset_id bigint,
date datetime,
price_in_cents integer);
If you have as id an autogenerated incremented value for this table and you have many different assets in your application when you execute the following query: select * from asset_price where asset_id=1 and datetime>'2012-10-11 00:9:00' (this query could be used to paint a chart of the evolution of the asset price during the day) you will probably have many i/o disk operations (since the distance in the disk between an asset_price and the previous one for a specific asset will be very big). On the other hand if you have as primary key (asset_id, date) you will just have a few i/o disk operations, as data will be "physically organized to do ultra-fast lookups and sorts based on the primary key column or columns". Since the bottleneck to scale most applications is the database I think it would be extremely valuable to know how to do this.
Thanks in advance for your help.
Hi!Did anyone resolve this problem? I'm in the same boat :(Thanks,Pavel.
On Wednesday, November 14, 2012 8:17:55 AM UTC-5, Stan wrote:Eduard,
I'm in the same case than you.
I tried to modify my classes with the Vikram's information but I get the following error message during the save/insert operation:
PersistenceException: Matches for the concatinated key columns where not found? I expect that the concatinated key was null, and this bean does not have ManyToOne assoc beans matching the primary key columns?
Here the code source:
@Entitypublic class Follower extends Model {
private static final long serialVersionUID = 1L;
@EmbeddedIdpublic FollowerPK pk;
@ManyToOne(fetch = FetchType.LAZY)@JoinColumn(name = "user_id", insertable = false, updatable = false)public User user;@ManyToOne(fetch = FetchType.LAZY)@JoinColumn(name = "user_id", insertable = false, updatable = false)
public User follower;}
@Embeddablepublic class FollowerPK implements Serializable{
private static final long serialVersionUID = 1L;
public Long userId;public Long followerId;
public FollowerPK(Long userID, Long followerId) {
this.userId = userId;
this.followerId = followerId;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final FollowerPK other = (FollowerPK) obj;
if ((this.userId == null) ? (other.userId != null) : !this.userId.equals(other.userId)) {
return false;
}
if ((this.followerId == null) ? (other.followerId != null) : !this.followerId.equals(other.followerId)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 3;
hash = 89 * hash + (this.userId != null ? this.userId.hashCode() : 0);
hash = 89 * hash + (this.followerId != null ? this.followerId.hashCode() : 0);
return hash;
}}
There is something wrong ... but I can't see it :-( Any idea ?
Thanks a lot.
--