tags:

views:

51

answers:

2

INFORMIX-SE 7.32:

I have a transaction table with about 5,000 nrows. The transaction.ticket_number[INT] is a column which gets updated with the next available sequential ticket number every time a specific row is updated. The column is unique indexed. I'm currently using the following SELECT statement to locate the max(transaction.ticket_num):

SELECT MAX(transaction.ticket_number) FROM transaction;

Since the row being updated is clustered acording to the transaction.fk_id[INT], where it is joined to customer.pk_id[SERIAL],the row is not physically located at the end of the transaction table, rather it resides within the group of transaction rows belonging to each particular customer. I chose to cluster the transactions belonging to each customer because response time is faster when I scroll through each customers transaction. Is there a faster way of locating the max(transaction.ticket_number) with the above query?.. Would a 'unique index on transaction(ticket_number) descending' improve access or is the indexed fully traversed from begining to end irrelevantly?

+1  A: 

Due to NULLABLE columns and other factors, use of indexes, etc, you can often find the following would be faster, but normally only negligably...

SELECT TOP 1 ticket_number FROM transaction ORDER BY ticket_number DESCENDING

I'm also uncertain as to whether you actually have an Index on [ticket_number]? Or do you just have a UNIQUE constraint? A constraint won't help determine a MAX, but an INDEX will.

In the event that an INDEX exists with ticket_number as the first indexable column:
- An index seek/lookup would likely be used, not needing to scan the other values at all

In the event that an INDEX exists with ticket_number Not as the first indexable column:
- An index scan would likely occur, checking every single unique entry in the index

In the event that no usable INDEX exists:
- The whole table would be scanned

Dems
+1  A: 

On a table of only 5000 rows on a modern machine, you are unlikely to be able to measure the difference in performance of the various techniques, especially in the single-user scenario which I believe you are facing. Even if the 5000 rows were all at the maximum permissible size (just under 32 KB), you would be dealing with 160 MB of data, which could easily fit into the machine's caches. In practice, I'm sure your rows are far smaller, and you'd never need all the data in the cache.

Unless you have a demonstrable performance problem, go with the index on the ticket number column and rely on the server (Informix SE) to do its job. If you have a demonstrable problem, show the query plans from SET EXPLAIN output. However, there are major limits on how much you can tweak SE performance - it is install-and-go technology with minimal demands on tuning.

I'm not sure whether Informix SE supports the 'FIRST n' (aka 'TOP n') notation that Informix Dynamic Server supports; I believe not.

Jonathan Leffler
Frank Computer
@Frank: yes, ISQL works fine with IDS, subject to the caveat that Perform will not work with fragmented tables unless they are created with the WITH ROWIDS clause. But, for the direct migration, you would not have fragmented tables and then you'd be fine.
Jonathan Leffler
@Jonathan- That's great!.. I was planning on 'FRAGMENT BY EXPRESSION customer.date_last_activity < TODAY - 365 IN dbsp_inactive_customers', so guess I will have to include 'WITH ROWIDS' in my 'CREATE TABLE customer' statement in my reorg proc.
Frank Computer