Reputation: 262
In DB2 UDB I can create an index using the following syntax
create unique index I_0004 on TABLENAME (a) INCLUDE (b, c, d);
where a, b, c and d are field of the table TABLENAME
.
In DB2 for os390 this syntax (the INCLUDE
keyword) is not allowed, so I am creating the indexes as follows
create unique index I_0004 on TABLENAME (a);
create index I_0005 on TABLENAME (a, b, c, d);
Are the two statements above equivalent to the solution with the INCLUDE
keyword?
And, if I slightly modify the first statement
create index I_0005 on TABLENAME (a, b, c, d) ALLOW REVERSE SCANS;
is this ALLOW REVERSE SCANS
equivalent to creating indexes
create index I_0005 on TABLENAME (a, b, c, d);
create index I_0005 on TABLENAME (d, c, b, a);
or does it consider also any combination of the given columns (I mean, a,b,c,d; b,c,d,a; c,d,a,b; and so on...)?
Upvotes: 1
Views: 4279
Reputation: 881547
Regarding the UNIQUE INDEX
: roughly, yes, a unique index on (a)
including (b, c, d)
is equivalent to a unique index just on (a)
plus a non-unique one on (a, b, c, d)
-- except of course that, internally, the database engine may be able to use less space &c.
Regarding ALLOW REVERSE SCANS
: no, an index on (a, b)
that can be reverse-scanned is not equivalent to one that can't plus one on (b, a)
-- rather, an index that can be reverse scanned is equivalent to one that can't plus another on the same columns where each ASC
becomes a DESC
and vice versa (and ASC
is the default when you don't specify).
Note that since DB2 9.1 reverse scans are allowed by default, see http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.rn.doc/doc/c0023548.htm (and, I believe DB2 V8 is now out of support, see http://www-01.ibm.com/support/docview.wss?rs=71&uid=swg21370360 -- I think V9.5 is the current version).
Upvotes: 1