Archive for May 12th, 2009
Indexing a link table
Comments enabled. I *really* need your comment
From Stack Overflow:
A relation table is the common solution to representing a many-to-many (
m:n
) relationship.In the simplest form, it combines foreign keys referencing the two relating tables to a new composite primary key:
CREATE TABLE t_a ( id INT NOT NULL PRIMARY KEY, value VARCHAR(50) NOT NULL ) CREATE TABLE t_b ( id INT NOT NULL PRIMARY KEY, value VARCHAR(50) NOT NULL ) CREATE TABLE t_ab ( a INT NOT NULL, b INT NOT NULL )How should it be indexed to provide optimal performance in every JOIN situation?
I'll consider SQL Server as the target platform this time.
We need all WHERE
, ORDER BY
and GROUP BY
conditions to be covered by the indexes.
On a first thought, we need to have indexes for all columns in all orders:
Read the rest of this entry »