views:

108

answers:

1

For DB2...

table1.a is varchar(30) and has an index on it. table2.b is varchar(45) and has an index on it.

Will table1.a = table2.b use the index on table1, table2, or both?

Although it would seem obvious that it should use both indexes, I'm asking because I believe on sybase, this would only use one of the indexes (I'm not sure which one).

I fully intend to test this out, but I am unable to presently.

A: 

It's been my experience on DB2 for Z that it won't, as data types must be identical -- the data type, precision, scale, and nullability of a column must match for joins to use them.

Adam Musch
See http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.perf/db2z_stage1and2predicates.htm for lots more details on this, but what you really want are stage 1 predicates, as those can be used to drive access (go to the right row) rather than filtering (find the right row of all possible rows).
Adam Musch