Posted on 2011-09-09
Medium Priority
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 800 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.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


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 1200 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

762 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