How can I efficiently create a unique index on two fields in a table like this: create table t (a integer, b integer);
where any unique combination of two different
In Oracle you could use a function-based index like this:
create unique index mytab_idx on mytab (least(a,b), greatest(a,b));
I don't know mySQL, but maybe something similar is possible? For example, you could add 2 new columns leastab and greatestab to the table, with a trigger to maintain them with the values of least(a,b) and greatest(a,b) respectively, and then create a unique index on (leastab, greatestab).