NHibernate +流畅的 NHibernate +甲骨文索引

发布于 2024-08-15 12:38:28 字数 753 浏览 7 评论 0原文

我有一个包含超过 10 000 000 行的表。 在 TOAD 中,此查询运行得很好:

select /*+ INDEX(x IDX_CASHFLOW_COMPLEX)*/ * 
from MYPR.CASHFLOW x 
where fk_debet in (21856, 21854, 21855)

IDX_CASHFLOW_COMPLEX 是由以下脚本创建的 5 列索引:

CREATE INDEX MYPR.IDX_CASHFLOW_COMPLEX ON MYPR.CASHFLOW
(FK_DEBIT, FK_CREDIT, FK_DOCUMENT, PAYMENTDATE, FK_PAYMENTCODE)
LOGGING
TABLESPACE INDX
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
NOPARALLEL;

类似的查询,但没有 Oracle 提示语法,运行速度明显慢!

您能否建议是否可以告诉 NHibernate 在查询中添加 Oracle 提示?

谢谢!

I have a table with more than 10 000 000 rows.
In TOAD this query works very well on it:

select /*+ INDEX(x IDX_CASHFLOW_COMPLEX)*/ * 
from MYPR.CASHFLOW x 
where fk_debet in (21856, 21854, 21855)

IDX_CASHFLOW_COMPLEX is index on 5 columns created by following script:

CREATE INDEX MYPR.IDX_CASHFLOW_COMPLEX ON MYPR.CASHFLOW
(FK_DEBIT, FK_CREDIT, FK_DOCUMENT, PAYMENTDATE, FK_PAYMENTCODE)
LOGGING
TABLESPACE INDX
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
NOPARALLEL;

Similar query but without Oracle hint syntax works significantly slower!

Would you please suggest is it possible to tell NHibernate to add Oracle hint in the query?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温柔戏命师 2024-08-22 12:38:28

您的优化器统计信息是最新的吗?如果没有,您可能会发现一旦生成它们,您根本不需要提示。

Are your optimizer statistics up to date? If not you may find that once they are generated you don't need the hint at all.

撑一把青伞 2024-08-22 12:38:28

据推测,没有提示的查询没有使用索引。

在任何 sql 工具中尝试此操作:

explain plan for
select /*+ INDEX(x IDX_CASHFLOW_COMPLEX)*/ * 
from MYPR.CASHFLOW x 
where fk_debet in (21856, 21854, 21855)
/

select * from table(dbms_xplan.display)
/

...并发布最后一个命令的输出。我们可以用它来查看 Oracle 对结果集的预期基数做出的估计。

Presumably the query without the hint is not using the index.

Try this in any sql tool:

explain plan for
select /*+ INDEX(x IDX_CASHFLOW_COMPLEX)*/ * 
from MYPR.CASHFLOW x 
where fk_debet in (21856, 21854, 21855)
/

select * from table(dbms_xplan.display)
/

... and post the output of the last command. We can use that to see what estimations oracle is making of the expected cardinality of the result set.

财迷小姐 2024-08-22 12:38:28

有提示 /* +INDEX(...) */ :

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 238 | 26 |
| 1 | INLIST ITERATOR | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| CASHFLOW | 1 | 238 | 26 |
|* 3 | INDEX RANGE SCAN | IDX_CASHFLOW_COMPLEX | 1 | | 2 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("X"."FK_DEBIT"=21854 OR "X"."FK_DEBIT"=21855 OR "X"."FK_DEBIT"=21856)
Note: cpu costing is off

无提示 /* +INDEX(...) */ :

-------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 238 | 2 |
|* 1 | TABLE ACCESS FULL | CASHFLOW | 1 | 238 | 2 |
--------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("X"."FK_DEBIT"=21854 OR "X"."FK_DEBIT"=21855 OR "X"
."FK_DEBIT"=21856)
Note: cpu costing is off

With hint /* +INDEX(...) */ :

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 238 | 26 |
| 1 | INLIST ITERATOR | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| CASHFLOW | 1 | 238 | 26 |
|* 3 | INDEX RANGE SCAN | IDX_CASHFLOW_COMPLEX | 1 | | 2 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("X"."FK_DEBIT"=21854 OR "X"."FK_DEBIT"=21855 OR "X"."FK_DEBIT"=21856)
Note: cpu costing is off

Without hint /* +INDEX(...) */ :

-------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 238 | 2 |
|* 1 | TABLE ACCESS FULL | CASHFLOW | 1 | 238 | 2 |
--------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("X"."FK_DEBIT"=21854 OR "X"."FK_DEBIT"=21855 OR "X"
."FK_DEBIT"=21856)
Note: cpu costing is off
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文