I run a small to medium car website and we are trying to log how many times a visit goes to vehicles detail page. We do this by hashing, md5, the make, model, and zip of the current vehicle. We then keep a vehicle_count total and increment this if the hashes match.
After running the numbers there appears to be about 50 makes, each make has about 50 models, and our locations db has about 44,000 unique zip codes. Roughly 100 million+ potential of unique hashes
This is the create table:
CREATE TABLE `vehicle_detail_page` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`vehicle_hash` char(32) NOT NULL,
`make` varchar(100) NOT NULL,
`model` varchar(100) NOT NULL,
`zip_code` char(7) DEFAULT NULL,
`vehicle_count` int(6) unsigned DEFAULT '1',
PRIMARY KEY (`id`),
UNIQUE KEY `vehicle_hash` (`vehicle_hash`),
KEY `make` (`make`),
KEY `model` (`model`),
KEY `zip_code` (`zip_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
This is the PHP code to insert/update the table:
public function insertUpdate($make, $model, $zip)
{
// set table
$table = self::TABLE;
// create hash
$hash = md5($make.$model.$zip);
// insert or update count
try
{
$stmt = $this->db->conn->prepare("INSERT INTO $table
(vehicle_hash,
make,
model,
zip_code)
VALUES
(:vehicle_hash,
:make,
:model,
:zip_code)
ON DUPLICATE KEY UPDATE
vehicle_count = vehicle_count + 1;");
$stmt->bindParam(':vehicle_hash', $hash, PDO::PARAM_STR);
$stmt->bindParam(':make', $make, PDO::PARAM_STR);
$stmt->bindParam(':model', $model, PDO::PARAM_STR);
$stmt->bindParam(':zip_code', $zip, PDO::PARAM_STR);
$stmt->execute();
} catch (Exception $e)
{
return FALSE;
}
return TRUE;
}
Questions:
- Can MySQL handle this many rows?
- Does anyone see anything wrong with this code, and is there a better way to do this?
- What will querying this data be like?
The Big question is, once this table grows how will that php function above perform. If/when that table has a few million+ rows, how will that table perform. Can anyone give some insight?