Identifier generator optimization
For identifier generators which store values in the database, it is inefficient for
them to hit the database on each and every call to generate a new identifier
value. Instead, you'd ideally want to group a bunch of them in memory and
only hit the database when you have exhausted your in-memory value group.
This is the role of the pluggable optimizers. Currently only the two enhanced
generators (Section 5.1.5, “Enhanced identifier generators” support this
notion.
• none (generally this is the default if no optimizer was specified): This says
to not perform any optimizations, and hit the database each and every
request.
• hilo: applies a hi/lo algorithm around the database retrieved values. The
values from the database for this optimizer are expected to be sequential.
The values retrieved from the database structure for this optimizer
indicates the "group number"; the increment_size is multiplied by that value
in memory to define a group "hi value".
• pooled: like was discussed for hilo, this optimizers attempts to minimize
the number of hits to the database. Here, however, we simply store the
starting value for the "next group" into the database structure rather than
a sequential value in combination with an in-memory grouping algorithm.
increment_size here refers to the values coming from the database.
对于主键生成器的优化的主要策略是不要每次需要主键的时候都去访问一次数据库。hilo和pooled可以实现。
上文中所说的两种“only the two enhanced generators”是指在hibernate3.3.2中新引入的两个价钱的主键生成策略org.hibernate.id.enhanced.SequenceStyleGenerator和org.hibernate.id.enhanced.TableGenerator
本文讨论了在数据库应用中如何优化主键生成器的效率,特别是通过使用hilo和pooled策略来减少对数据库的访问次数。介绍了hibernate3.3.2中新增的两种主键生成策略SequenceStyleGenerator和TableGenerator。

2343

被折叠的 条评论
为什么被折叠?



