关于oracle 11g问题的索引

发布于 2024-10-01 12:47:11 字数 528 浏览 5 评论 0原文

我有一个包含 900,000 条记录的表 (MEN)。

在此表中,我有字段 IPTdate

当我运行查询时:

select * from MEN where IP = '1.1.1.1' and Tdate = TO_DATE('07/04/2010', 'DD/MM/YYYY')

需要很长时间才能得到结果。

我尝试像这样创建索引:

create index
    my_in
on
   MEN (IP,Tdate );

但是如何运行查询以获得快速结果?

我尝试这个:

select My_in from MEN where IP = '1.1.1.1' and Tdate = TO_DATE('07/04/2010', 'DD/MM/YYYY')

并收到错误:ORA-00904

i have table (MEN) with 900,000 records.

in this table i have field IP and Tdate.

when i run query:

select * from MEN where IP = '1.1.1.1' and Tdate = TO_DATE('07/04/2010', 'DD/MM/YYYY')

it takes long time until i get Result.

i try to make index like this:

create index
    my_in
on
   MEN (IP,Tdate );

but how to run the query to get fast Result?

i try this:

select My_in from MEN where IP = '1.1.1.1' and Tdate = TO_DATE('07/04/2010', 'DD/MM/YYYY')

and get error: ORA-00904

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

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

发布评论

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

评论(3

謌踐踏愛綪 2024-10-08 12:47:11

您不在选择中使用索引名称 (My_in)。数据库本身会决定使用索引。因此,您应该执行与第一个示例中相同的选择。

You do not use the index name (My_in) in the select. The database itself will figure out to use the index. So you should just do the same select as in your first example.

东风软 2024-10-08 12:47:11

在您的查询中,

select My_in from MEN where IP = '1.1.1.1' and Tdate = TO_DATE('07/04/2010', 'DD/MM/YYYY')

my_in 是索引名称。如果你想强制使用索引,那么你可以提示你的查询

  select /*+INDEX(My_in MEN) */  * from MEN where IP = '1.1.1.1' and Tdate = TO_DATE('07/04/2010', 'DD/MM/YYYY')

in your query

select My_in from MEN where IP = '1.1.1.1' and Tdate = TO_DATE('07/04/2010', 'DD/MM/YYYY')

the my_in is the index name. If you want to force the index usage, then you can hint your query

  select /*+INDEX(My_in MEN) */  * from MEN where IP = '1.1.1.1' and Tdate = TO_DATE('07/04/2010', 'DD/MM/YYYY')
樱花坊 2024-10-08 12:47:11

这不是有效的 SQL。 My_in 是您的索引的名称。

重试:

select * 
  from MEN
 where IP = '1.1.1.1' 
   and Tdate = TO_DATE('07/04/2010', 'DD/MM/YYYY');

或者,如果您想知道服务器是否将使用使用您新创建的索引的计划,您可以检查 explain 命令的输出:

explain plan for
select * 
  from MEN
 where IP = '1.1.1.1' 
   and Tdate = TO_DATE('07/04/2010', 'DD/MM/YYYY');

查看 Oracle 关于 解释计划。它将帮助您进行此优化以及许多其他 SQL 优化。

That's not valid SQL. My_in is the name of your index.

Try again with:

select * 
  from MEN
 where IP = '1.1.1.1' 
   and Tdate = TO_DATE('07/04/2010', 'DD/MM/YYYY');

Alternatively, if you want to know if the server will use a plan using your newly created index, you can inspect the output of the explain command:

explain plan for
select * 
  from MEN
 where IP = '1.1.1.1' 
   and Tdate = TO_DATE('07/04/2010', 'DD/MM/YYYY');

Take a look at Oracle's documentation on EXPLAIN PLAN. It will help you with this and many other SQL optimizations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文