NHibernate 对非键的查询比对单列主键的查询需要更长的时间来水合对象
我注意到 NHibernate 的一个特殊行为。
语境: 我有一个带有复合键(数字、字符串和日期)和其他一些列的表。我注意到对该表(hibernate 类)的查询比对其他表的查询要慢得多。即使只返回一条记录(hibernate 对象)。
观察:
- 引入了代理键并将其映射为主键,再次运行查询会得到与对象水合之前相同的性能。
- 如果通过代理键查询,对象的水合作用速度会快 6-7 倍。 2.
在所有上述查询运行中,数据库性能是一致的。
该表的 hibernate 映射中没有定义关联或关系。
我无法解释对象水合(用数据填充 .Net 对象)的性能差异。
当我必须在条件中使用另一列时,我可以做什么来调整代码,使其与使用 PK 的查询一样高效。
感谢提前
基兰
编辑:表结构..我已放入创建表脚本本身..因为我无法正确格式化它..
创建表“测试” ( “参考”VARCHAR2(5字节)不为空, “优先级”编号(6,0)不为空, “EFF_FROM_DATE”日期不为空, “EFF_TO_DATE”日期不为空, “值”VARCHAR2(100字节)不为空, "LAST_UPDATE_USERNAME" VARCHAR2(30 BYTE) NOT NULL, “LAST_UPDATE_DATE_TIME”日期不为空, “NOTE_1”VARCHAR2(20 字节), “NOTE_2”VARCHAR2(20 字节) )
I noticed a peculiar behavior with NHibernate.
Context:
I have a table with a composite key (a number, a string and a date) and a few other columns. I noticed that a query on this table (hibernate class) was significantly slower than queries on other tables. even though there is only one record (hibernate object) returned.
Observation:
- A surrogate key was introduced and mapped it as the primary key, running the query again resulted in the same performance as before for Object Hydration.
- Hydration of the object was 6-7 times faster if Queried on the surrogate key. 2.
In all the above query runs, database performance was consistent.
There are no Associations or relationships defined in the hibernate mapping of this table.
I am not able to explain the difference in performance of object hydration (populating the .Net Objects with data).
What can I do to tweak the code to be as performant as the query using the PK when I have to use another column in the criteria.
Thanks in Advance
Kiran
EDIT: Table structure.. I have put in the create table script itself.. as I was not able to format it properly..
CREATE TABLE "TEST"
(
"REFERENCE" VARCHAR2(5 BYTE) NOT NULL,
"PRIORITY" NUMBER(6,0) NOT NULL,
"EFF_FROM_DATE" DATE NOT NULL,
"EFF_TO_DATE" DATE NOT NULL,
"VALUE" VARCHAR2(100 BYTE) NOT NULL,
"LAST_UPDATE_USERNAME" VARCHAR2(30 BYTE) NOT NULL,
"LAST_UPDATE_DATE_TIME" DATE NOT NULL,
"NOTE_1" VARCHAR2(20 BYTE),
"NOTE_2" VARCHAR2(20 BYTE)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过强制 nhibernate 使用 Oracle 驱动程序而不是 Microsoft for oracle 驱动程序解决了此差异。
我按照此博客中的步骤操作
http://www.timvasil.com/blog14/category/Oracle.aspx
This discrepancy was solved by forcing nhibernate to use the Oracle driver instead of the Microsoft driver for oracle.
I followed steps from this blog
http://www.timvasil.com/blog14/category/Oracle.aspx