473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to use index

Ken
Dear all,

I have a beginner of oracle and recently I have a prob with using
indexes. I have a table with 5 columns, with no primary key set in the
table. An index has created for column 1. I have a sql which retrieve
rows based on the indexed column:

select *
from my_table
where
column_1 in ('A','B','C')

bcoz I select columns which are not indexed, the index created for
column 1 cannot used either. Pls suggest a way so that I can retrieve
all columns, at the same time db will make use of my index in column
1.

Many many thanks if anyone can kindly help me.
Jul 19 '05 #1
3 17761
> bcoz I select columns which are not indexed, the index created for
column 1 cannot used either not true. the columns in the select list do not affect which indexes the
optimizer uses

your IN clause is the equivalent of 3 equality predicates with OR -- the
optimizer may very well not use the index if it appears that it would be
faster to do a full table scan

do you have statistics on the table?

how many rows are in the table? the 'rule of thumb' is that oracle will use
an index if it determines that about 2% of the rows will be returned

--mcs

"Ken" <wi***********@hotmail.com> wrote in message
news:63**************************@posting.google.c om... Dear all,

I have a beginner of oracle and recently I have a prob with using
indexes. I have a table with 5 columns, with no primary key set in the
table. An index has created for column 1. I have a sql which retrieve
rows based on the indexed column:

select *
from my_table
where
column_1 in ('A','B','C')

bcoz I select columns which are not indexed, the index created for
column 1 cannot used either. Pls suggest a way so that I can retrieve
all columns, at the same time db will make use of my index in column
1.

Many many thanks if anyone can kindly help me.

Jul 19 '05 #2
Ken
Actually the whole sql is a join with 2 tables:

select
a.INDEXED_COLUMN1,
b.INDEXED_COLUMN2,
b.COLUMN2
b.COLUMN3
b.COLUMN4

from
tableA a, tableB b

where
a.INDEXED_COLUMN1 IN ('A','B','C','D') and
a.INDEXED_COLUMN2=b.INDEXED_COLUMN1 and
b.INDEXED_COLUMN2 > SYSDATE

TableA has a composite index for column2 and column1
(a.INDEXED_COLUMN2, a.INDEXED_COLUMN1). TableB has a composite index
for column1 and column2 (b.INDEXED_COLUMN1, b.INDEXED_COLUMN2)

The optimizer does not use the index in tableB when the 2 tables
joined together. Instead, it does a full scan. The trace is listed
below:

Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=4 Bytes=124)
1 0 HASH JOIN (Cost=5 Card=4 Bytes=124)
2 1 INDEX (FAST FULL SCAN) OF 'IX_TABLE_A_COL2_COL1' (NON
-UNIQUE) (Cost=1 Card=4 Bytes=24)

3 1 TABLE ACCESS (FULL) OF 'TABLE_B' (Cost=3 Card=16 Bytes=4
00)

Statistics
----------------------------------------------------------
0 recursive calls
8 db block gets
111 consistent gets
0 physical reads
0 redo size
854 bytes sent via SQL*Net to client
1039 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
7 sorts (memory)
0 sorts (disk)
4 rows processed

Thanks
Jul 19 '05 #3
wi***********@hotmail.com (Ken) wrote in message news:<63**************************@posting.google. com>...
Actually the whole sql is a join with 2 tables:

select
a.INDEXED_COLUMN1,
b.INDEXED_COLUMN2,
b.COLUMN2
b.COLUMN3
b.COLUMN4

from
tableA a, tableB b

where
a.INDEXED_COLUMN1 IN ('A','B','C','D') and
a.INDEXED_COLUMN2=b.INDEXED_COLUMN1 and
b.INDEXED_COLUMN2 > SYSDATE

TableA has a composite index for column2 and column1
(a.INDEXED_COLUMN2, a.INDEXED_COLUMN1). TableB has a composite index
for column1 and column2 (b.INDEXED_COLUMN1, b.INDEXED_COLUMN2)

The optimizer does not use the index in tableB when the 2 tables
joined together. Instead, it does a full scan.
Since the index on tableB is column1,column2 but your query has no
value for the beginning of that index (ie the where clause has no
values for tableB.column1). So the optimizer cannot compute a value or
even a range to use in the index.
... The trace is listed
below:

Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=4 Bytes=124)
1 0 HASH JOIN (Cost=5 Card=4 Bytes=124)
2 1 INDEX (FAST FULL SCAN) OF 'IX_TABLE_A_COL2_COL1' (NON
-UNIQUE) (Cost=1 Card=4 Bytes=24)

3 1 TABLE ACCESS (FULL) OF 'TABLE_B' (Cost=3 Card=16 Bytes=4
00)

Statistics
----------------------------------------------------------
0 recursive calls
8 db block gets
111 consistent gets
0 physical reads
0 redo size
854 bytes sent via SQL*Net to client
1039 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
7 sorts (memory)
0 sorts (disk)
4 rows processed

Thanks


Given the plan shown above, as long as tableB remains the smaller of
the two tables, the hash join will be plenty fast. (You're going to
need a LOT more rows than that to have any concern about performance.)

lastly, consider doing a more detailed design and make some primary
keys (you get the index automatically.

HTH,
ed
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jofio | last post by:
Hello, I am a newbie in PHP and I am enthusiastically trying out things. I've just replaced my index.html ( file with index.php
9
by: kosh | last post by:
I was wondering if there is or there could be some way to pass a generator an optional starting index so that if it supported that slicing could be made more efficient. Right now if you do use a...
2
by: skura | last post by:
I am trying to understand how the data in sql server is stored and also regarding fill factor and page splitting. 1) My first question what is the difference between Index pages and Data pages....
6
by: Anita | last post by:
I have just tested 3 queries using QA. The complete test information : ------ CREATE TABLE agls1 ( fyear char(4) NULL , fprefix char(3) NULL , fvcno char(20) NULL , fdate datetime NULL ,...
8
by: Andr? Queiroz | last post by:
Hi, I have a table with 10M records and col A has a index created on it. The data on that table has the same value for col A on all 10M records. After that I insert diferent values for that column...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
4
by: Steph. | last post by:
I have a List view displaying data in Detail mode with several columns. How I can get the column index the user clicked on ? (when user click on an item inside the ListView, not on a column...
2
by: bobby_b_ | last post by:
I have a table where fields 1 and 2 make up the primary key. Because of this, I have a unique composite index on fields 1 and 2 (as required by DB2). Now my question is: Fields 1 and 2 are also...
85
by: Russ | last post by:
Every Python programmer gets this message occasionally: IndexError: list index out of range The message tells you where the error occurred, but it doesn't tell you what the range and the...
8
by: shira | last post by:
I have done a fair bit of searching, but haven't yet been able to find an explanation as to why one would set "ignore nulls" to "yes" when creating an index. I understand what it does (I think),...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.