Posted on 2011-09-09
Last Modified: 2012-05-12
I have an INVOICE table with INV_NO as primary key with index.

Table also has ITEM_NO for the line items.

I normally select from table/view as this

SELECT col1,col2,... from INVOICE where INV_NO=p_inv_no
ORDER BY item_no.

Would it help to have the index replace by (INV_NO, ITEM_NO) or not since it is only used for sorting result set and not in the WHERE clause
Question by:sam15
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36514397
Set up something in your test system and see.

My gut feeling is it won't make any difference since it is not in the where.

I would need to set up my own tests to verify.
LVL 23

Assisted Solution

OP_Zaharin earned 200 total points
ID: 36515039
- to add further, if you want to experiment the index you've created. use EXPLAIN PLAN to see if the query use the index or not.
LVL 15

Expert Comment

ID: 36516029
Index on any Table do´nt grants order clause.
Note that on a String Key you have a character set at server side. Table index uses server character set.
The order clause uses Client character set.

You code seems respond to a Master-Detail query. Each time you change Primary record you get Child Rows.

A convenient solution for Detail record is the IOT Tables (Organization Index).
This requires a Primary key for the index  (INV_NO, ITEM_NO).
Advantages: all records from any key are contiguous on Disk. This save time on data retrieval.
It saves memory on Server as you get data olny from Table Segment, do´nt need get data from index segment.
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.


Author Comment

ID: 36516313
I tested it both ways and it did not seem to make a big difference but also my table does not have much data too. Both queries use the same index whether it is one column or two columns.

Index organized tables will index the whol tables and used mostly for lookup tables. This is a transactional table and there are 12 columns in it.

I really doubt that the ORDEr BY is using client character set too. This is SQL on server and run on server. Data is sent to client sorted and client just changes character set there if it is different.
LVL 77

Accepted Solution

slightwv (䄆 Netminder) earned 300 total points
ID: 36529529
>>it did not seem to make a big difference but also my table does not have much data too

Like I mentioned, I didn't think it would.

>>Index organized tables will index the whol tables and used mostly for lookup tables.

Technically not.  IOTs store the non-indexed columns in the index blocks with the indexed columns.

For index lookups when you also return a large number of additional columns, it can reduce data block reads substantially.

It would probably be worth setting up tests for this as well.  Where it might cause problems is with other queries that also use the table.  They might slow way down.


Author Comment

ID: 36529695
IOT is similar to having a table with all columns indexed. I mainly use it for READ-ONLY lookup tables.
IOT table = One big index structure

This is TRANSACTION table that gets a lot of WRITES too and has MANY other columns.
 Since  all data is sorted before storage it might not be appropriate choice for this particular case.
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36530115
>>table that gets a lot of WRITES too and has MANY other columns

Probably not in this case.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This post first appeared at Oracleinaction  ( Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question