Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

TablleIndexColumns.

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
0
sam15
Asked:
sam15
2 Solutions
 
slightwv (䄆 Netminder) Commented:
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.
0
 
OP_ZaharinCommented:
- 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.
0
 
x77Commented:
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
sam15Author Commented:
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.
0
 
slightwv (䄆 Netminder) Commented:
>>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.

0
 
sam15Author Commented:
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

http://www.orafaq.com/wiki/Index-organized_table

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.
0
 
slightwv (䄆 Netminder) Commented:
>>table that gets a lot of WRITES too and has MANY other columns

Probably not in this case.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now