1

I use informix DB, I hope I can query table index column
Now ,I just can query table index
I dont know how to query index column....
this is my query

SELECT indexname,f.tabid  FROM sysfragments f, sysindexes i, systables t WHERE  f.indexname = i.idxname AND i.tabid = t.tabid  and t.tabname ='mytable'

it just can show indexname can not show indexname's column...
how can I do? thanks

1 Answer 1

2

The part1 to part16 columns of the sysindexes table records the column number for each part of the index. This can then be matched against the syscolumns table as shown in this example:

SELECT indexname, f.tabid, sc1.colname, sc2.colname, sc3.colname
  FROM sysfragments f, sysindexes i, systables t,
   syscolumns sc1, OUTER syscolumns sc2, OUTER syscolumns sc3
  WHERE  f.indexname = i.idxname AND i.tabid = t.tabid
    AND sc1.tabid = t.tabid AND sc1.colno = i.part1
    AND sc2.tabid = t.tabid AND sc2.colno = i.part2
    AND sc3.tabid = t.tabid AND sc3.colno = i.part3
    AND t.tabname = 'table';

For composite indexes having more than 3 parts the SQL would have to be extended with outer joins on additional syscolumns tables.

Sign up to request clarification or add additional context in comments.

1 Comment

Note that if the index is descending, the column numbers in sysindexes (partN) will be negative. Using ABS(part) works for those columns too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.