Hi,
Im getting very confused with indexes in MySQL.
I have two tables: TableA1 and TableA2.
I created indexes on these for the joins between them and queries run really fast.
I have another 2 tables with an identical setup e.g. TableB1 and TableB2. The only difference is that these tables have a few null values.
For some reason the same query on TableA is about 5 times faster and doesn't require a full-table scan. TableB however seems to use a full table scan and I can't work out why. Could it be the Null values that are causing this?
I notice using EXPLAIN that on the TableA setup, I get possible keys: myindex
and also ref: func
; however on the TableB setup I get just possible keys: NULL
and ref: NULL
.
I have searched around for quite a while on this, and cannot seem to find a relevant answer. Would appreciate if someone can point me in the right direction.
(Sorry, now added to the original question.)
Here is TableAOne:
CREATE TABLE `TableAOne` (
`field1` varchar(255) DEFAULT NULL,
`field2` varchar(255) DEFAULT NULL,
KEY `myindex` (`field1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
And TableATwo:
CREATE TABLE `TableATwo` (
`Field3` varchar(255) ,
`Field4` varchar(255) ,
`Field5` varchar(255) ,
`id` int(20) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=15522 DEFAULT CHARSET=utf8;
I am joining Field3 with Field1.
The tables that get the full-table scan are identical to the above tables. The only difference is they are called TableB instead of TableA.
Cheers,
Ke