Reputation: 62424
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
Upvotes: 2
Views: 458
Reputation: 181270
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.
Upvotes: 1
Reputation: 2438
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')
Upvotes: 1
Reputation: 120917
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.
Upvotes: 5