I'd like to verify that my assumptions are right. I have two tables, which only differ in index order.
They look like this:
CREATE TABLE `ipcountry` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`ipFROM` INT(10) UNSIGNED ZEROFILL NOT NULL DEFAULT '0000000000',
`ipTO` INT(10) UNSIGNED ZEROFILL NOT NULL DEFAULT '0000000000',
`countrySHORT` CHAR(2) NOT NULL DEFAULT '' COLLATE 'utf8_czech_ci',
`countryLONG` VARCHAR(255) NOT NULL DEFAULT ' ' COLLATE 'utf8_czech_ci',
PRIMARY KEY (`id`),
INDEX `ipINDEX` (`ipTO`, `ipFROM`)
)
COLLATE='utf8_czech_ci'
ENGINE=InnoDB
AUTO_INCREMENT=2490331
;
CREATE TABLE `ipcountry2` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`ipFROM` INT(10) UNSIGNED ZEROFILL NOT NULL DEFAULT '0000000000',
`ipTO` INT(10) UNSIGNED ZEROFILL NOT NULL DEFAULT '0000000000',
`countrySHORT` CHAR(2) NOT NULL DEFAULT '' COLLATE 'utf8_czech_ci',
`countryLONG` VARCHAR(255) NOT NULL DEFAULT ' ' COLLATE 'utf8_czech_ci',
PRIMARY KEY (`id`),
INDEX `ipINDEX` (`ipFROM`, `ipTO`)
)
COLLATE='utf8_czech_ci'
ENGINE=InnoDB
AUTO_INCREMENT=2490331
;
Both tables have the exact same amount of rows which is roughly 2,500,000.
When performing EXPLAIN SELECT * FROM `ipcountry` WHERE ipFROM<=3548978221 AND ipTO>=3548978221
I get
{
"table": "UnknownTable",
"rows":
[
{
"id": 1,
"select_type": "SIMPLE",
"table": "ipcountry",
"partitions": null,
"type": "range",
"possible_keys": "ipINDEX",
"key": "ipINDEX",
"key_len": "4",
"ref": null,
"rows": 83260,
"filtered": 33.33,
"Extra": "Using index condition"
}
]
}
When performing EXPLAIN SELECT * FROM `ipcountry2` WHERE ipFROM<=3548978221 AND ipTO>=3548978221
I get
{
"table": "UnknownTable",
"rows":
[
{
"id": 1,
"select_type": "SIMPLE",
"table": "ipcountry2",
"partitions": null,
"type": "ALL",
"possible_keys": "ipINDEX",
"key": null,
"key_len": null,
"ref": null,
"rows": 2515343,
"filtered": 16.66,
"Extra": "Using where"
}
]
}
Is it because of the precedence of operators?