문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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')

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top