ここで何か間違ったことをしているのか、何が問題なのかわかりません
しかし、私がこのクエリを実行すると
EXPLAIN SELECT *
FROM reservation AS rs
INNER JOIN vehicles AS ve ON rs.vehicle_id = ve.vehicles_id
INNER JOIN customers AS cu ON rs.customerid = cu.customerid
LEFT JOIN checks AS ck ON rs.reservation_id = ck.reservation_id
LEFT JOIN credits AS cr ON rs.reservation_id = cr.reservation_id
私はこれを手に入れます
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE rs ALL NULL NULL NULL NULL 22
1 SIMPLE ve eq_ref PRIMARY PRIMARY 4 crm.rs.Vehicle_id 1
1 SIMPLE ck ALL NULL NULL NULL NULL 2
1 SIMPLE cr ALL NULL NULL NULL NULL 5
1 SIMPLE cu eq_ref PRIMARY PRIMARY 4 crm.rs.CustomerID 1 Using where
ここでの問題は、結合で使用するすべてのフィールドがインデックスまたは主キーのいずれかであるということです。すべてのプライマリがあります
ve.vehicles_id
cu.customerid
ck.reservation_id
cr.reservation_id
and these are all indexes
rs.vehicle_id
rs.customerid
ここに情報のチェックがあります
CREATE TABLE `checks` (
`Checks_id` int(11) unsigned NOT NULL auto_increment,
`customerID` int(11) unsigned NOT NULL,
`firstActivity` datetime NOT NULL,
`lastActivity` datetime NOT NULL,
`checkValue` varchar(7) NOT NULL,
`dueDate` datetime NOT NULL,
`Reservation_id` int(11) unsigned NOT NULL,
`date` datetime NOT NULL,
`isCashed` int(11) NOT NULL default '0',
`cashingResult` int(2) NOT NULL default '0',
PRIMARY KEY (`Checks_id`),
KEY `customerID` (`customerID`),
KEY `Reservation_id` (`Reservation_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
CREATE TABLE `vehicles` (
`Vehicles_id` int(11) unsigned NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
`size` varchar(20) NOT NULL,
`maker` varchar(20) NOT NULL,
`model` varchar(40) NOT NULL,
`year` year(4) NOT NULL,
`color` varchar(20) NOT NULL,
`oilChange` varchar(10) NOT NULL,
`currentMillage` varchar(10) NOT NULL,
`oilChangeMillage` varchar(10) NOT NULL,
`registrationExp` datetime NOT NULL,
`insuranceExp` datetime NOT NULL,
`dailyRate` double NOT NULL default '0',
`weekleyRate` double NOT NULL default '0',
`monthleyRate` double NOT NULL default '0',
`addDate` datetime NOT NULL,
`Active` int(1) NOT NULL default '1',
`VINnum` varchar(17) NOT NULL,
`licensePlate` varchar(10) NOT NULL,
`vehicleCost` double NOT NULL,
PRIMARY KEY (`Vehicles_id`),
UNIQUE KEY `VINnum` (`VINnum`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8
CREATE TABLE `credits` (
`Credits_id` int(11) unsigned NOT NULL auto_increment,
`customerID` int(11) unsigned NOT NULL,
`creditValue` varchar(6) NOT NULL,
`dueDate` datetime NOT NULL,
`Reservation_id` int(11) unsigned NOT NULL,
`date` datetime NOT NULL,
`firstActivity` datetime NOT NULL,
`lastActivity` datetime NOT NULL,
`paymentHistory` text NOT NULL,
`paymentHistoryDate` text NOT NULL,
PRIMARY KEY (`Credits_id`),
KEY `customerID` (`customerID`),
KEY `Reservation_id` (`Reservation_id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
CREATE TABLE `reservation` (
`Reservation_id` int(11) unsigned NOT NULL auto_increment,
`Vehicle_id` int(11) unsigned NOT NULL,
`CustomerID` int(11) unsigned NOT NULL,
`additionalDrivers` char(54) NOT NULL,
`dateFrom` datetime NOT NULL,
`dateTo` datetime NOT NULL,
`pickupDate` datetime NOT NULL,
`dropoffDate` datetime NOT NULL,
`addDate` datetime NOT NULL,
`reservationStatus` tinyint(1) NOT NULL default '1' COMMENT '0 canceled, 1 Reserved, 2 In Progress, 3 Completed',
`totalDays` int(4) NOT NULL,
`totalDiscount` char(6) NOT NULL,
`totalFees` char(6) NOT NULL,
`totalRent` double NOT NULL,
`totalTax` double NOT NULL,
`totalChecks` double NOT NULL,
`totalOwe` double NOT NULL default '0',
`totalPaidCash` double NOT NULL default '0',
`totalPaidBankCard` double NOT NULL default '0',
PRIMARY KEY (`Reservation_id`),
KEY `CustomerID` (`CustomerID`),
KEY `Vehicle_id` (`Vehicle_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1033 DEFAULT CHARSET=utf8
だから私はなぜpossible_keyとkeyに対してまだNULLを取得するのかわかりませんか?
私は何が間違っているのですか?私のすべての主キーは、同じ値INT(11)unsigedを持っています。
あなたの助けてくれてありがとう