I'm a bit confused about indexes... let's say I have this table:
t1
id INT DEFAULT 1 NOT NULL,
col1 INT,
col2 INT,
col3 INT,
col4 INT,
PRIMARY KEY (id),
KEY (col2),
KEY (col4);
I search like this:
SELECT * FROM t1 WHERE col2=1 AND col4=1;
Does this mean that only the (col2) index is being used, and that the (col4) index is useless in this case? Should I have defined it like this instead?:
PRIMARY KEY (id),
KEY foo (col2,col4);
t1
id INT DEFAULT 1 NOT NULL,
col1 INT,
col2 INT,
col3 INT,
col4 INT,
PRIMARY KEY (id),
KEY (col2),
KEY (col4);
I search like this:
SELECT * FROM t1 WHERE col2=1 AND col4=1;
Does this mean that only the (col2) index is being used, and that the (col4) index is useless in this case? Should I have defined it like this instead?:
PRIMARY KEY (id),
KEY foo (col2,col4);