Home » RDBMS Server » Performance Tuning » indexes
indexes [message #136667] Fri, 09 September 2005 08:12 Go to next message
adi_dba
Messages: 4
Registered: September 2005
Location: Delhi
Junior Member
Can we create an index on columns of two or more tables? Please answer as soon as possible. its vry urgent for me to know.....
Re: indexes [message #136673 is a reply to message #136667] Fri, 09 September 2005 08:34 Go to previous messageGo to next message
JSI2001
Messages: 1016
Registered: March 2005
Location: Scotland
Senior Member
No.
Re: indexes [message #136699 is a reply to message #136667] Fri, 09 September 2005 10:19 Go to previous messageGo to next message
smartin
Messages: 1803
Registered: March 2005
Location: Jacksonville, Florida
Senior Member
What does this question mean?
Re: indexes [message #136762 is a reply to message #136699] Fri, 09 September 2005 23:55 Go to previous messageGo to next message
adi_dba
Messages: 4
Registered: September 2005
Location: Delhi
Junior Member
we can create a index on a table's column for optimization of the query:
like if we have a table emp with columns:
emp_no,
emp_name,
emp_salary,
dept_no.
So, we can build index on any of the above columns.
lets have another table Dept having following columns:
dept_no,
dept_name,
location.
i can build index on any of the column of dept table.
right!!

i fired a query:
"select emp_no,e.dept_no,d.dept_name from emp e,dept d where e.dept_no=d.dept_no;"

Now my question is that can we build an index on "e.dept_no" and "d.dept_no" together.
Hopefully now you wud have understood my problem. If hav any related answer plz reply soon.
thanks.
Re: indexes [message #136766 is a reply to message #136762] Sat, 10 September 2005 00:21 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
You have to build two separate indexes, one index on emp.dept_no and another index on dept.dept_no.
Re: indexes [message #136774 is a reply to message #136766] Sat, 10 September 2005 01:31 Go to previous messageGo to next message
adi_dba
Messages: 4
Registered: September 2005
Location: Delhi
Junior Member
CANN'T I BUILD AN INDEX ON BOTH THE COLUMNS EMP.DEPT_NO AND DEPT.DEPT_NO SIMULTANEOUSLY????
ACTUALLY I HAD READ SOMETHING ABOUT THIS POOSSIBILTY LONG BACK BUT, DN'T REMEMBER NOW WHERE EXACTLY I READ THIS????
Re: indexes [message #136808 is a reply to message #136774] Sat, 10 September 2005 16:06 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
No, you cannot build one index on columns from more than one table. Either what you read was wrong or you misunderstood it. Perhaps you saw an example where a materialized view was created on two tables and one index was created on the materialized view. Or, perhaps you saw an example where a procedure was used to concatenate columns from different tables and that procedure was used in a text index. Given the example that you provided, there is no way to create one index on both tables, nor would it make any sense to do so. That is about all that can be explained unless you can come up with exactly what you read.
Re: indexes [message #136947 is a reply to message #136808] Mon, 12 September 2005 07:39 Go to previous messageGo to next message
SoporteDBA
Messages: 7
Registered: July 2005
Location: Écija, Sevilla
Junior Member
Hello,

There is a new feature on Oracle9i called "Bitmap Join Indexes" that could do what you are talking about:

From Oracle documentation:

create table emp1
as select * from scott.emp;

create table dept1
as select * from scott.dept;

alter table dept1
add constraint dept_constr1 unique (deptno);

create bitmap index empdept_idx
on emp1(dept1.deptno)
from emp1, dept1
where emp1.deptno = dept1.deptno;

select /*+ index(emp1 empdept_idx) */ count(*)
from emp1, dept1
where emp1.deptno = dept1.deptno;

COUNT(*)
-------------
14
Elapsed: 00:00:00.67

Execution Plan
---------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (AGGREGATE)
2 1 BITMAP CONVERSION (COUNT)
3 2 BITMAP INDEX (FULL SCAN) OF 'EMPDEPT_IDX'

Re: indexes [message #136961 is a reply to message #136667] Mon, 12 September 2005 08:30 Go to previous messageGo to next message
smartin
Messages: 1803
Registered: March 2005
Location: Jacksonville, Florida
Senior Member
I was thinking about the bitmap join index also, which is why I wanted to make sure the question was clear.

But it should be mentioned that this is a technique for use in DSS or warehouse type systems and is almost certainly going to be a bad idea if you are on a typical oltp system doing modifications to your emp and dept table. Bitmap indexes don't like modifications.

So, if you data changes, you may consider building 2 separate btree indexes, one each on deptid and empid. Although in this case, if you create typical constraints such that you had a PK constraint on both columns, then oracle would have already created a unique btree on each column for you.

Then oracle can (potentially if the CBO thinks its best) use both indexes to aid your query. For example, it might range or fast full scan each index individually, then hash join the results of those scans together.

If you are running oltp, I'd think this should be the goal you strive for.
Re: indexes [message #140078 is a reply to message #136961] Fri, 30 September 2005 14:08 Go to previous messageGo to next message
Hindustanweb
Messages: 2
Registered: September 2005
Location: Orlando
Junior Member
Yes. We did same thing for our DSS Healthcare database and works really good with bitmap join index.
Re: indexes [message #140245 is a reply to message #140078] Mon, 03 October 2005 03:03 Go to previous messageGo to next message
ziggy
Messages: 27
Registered: July 2005
Location: Moscow, Russia
Junior Member

May be you mean clustered table and cluster indexes?
Re: indexes [message #140419 is a reply to message #136667] Tue, 04 October 2005 03:10 Go to previous messageGo to next message
MauriceM
Messages: 7
Registered: June 2005
Junior Member
Depending for what you need it you may create an MV joining the two tables and then create an index over the MV. You could also try to create this MV based on an IOT table.

BUT this solution depends on how often your data get updated and for what you exactly need you index.

Also it would be good to know which Oracle version you are using.

[Updated on: Tue, 04 October 2005 03:12]

Report message to a moderator

Re: indexes [message #140725 is a reply to message #140419] Wed, 05 October 2005 07:03 Go to previous message
adi_dba
Messages: 4
Registered: September 2005
Location: Delhi
Junior Member
WHAT DO YOU MEAN BY "MV JOINING" AND "IOT TABLES" ?
PLZ TELL.
THANX IN ADVANCE.
Previous Topic: not using index from application
Next Topic: Increasing performance of queries
Goto Forum:
  


Current Time: Wed Apr 24 06:14:52 CDT 2024