Seltsames MySQL Verhalten

mysql

Im genauen habe ich eine Tabelle city_products, welche den Marktbestand aller Produkte in allen Städten beinhaltet. Es gibt einen Index auf die Spalte “product_id”, welche aber laut explain nur manchmal genutzt wird.

Der Tabellenaufbau ist folgender:

CREATE TABLE IF NOT EXISTS `city_products` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `city_id` int(10) unsigned NOT NULL,
 `product_id` tinyint(4) unsigned NOT NULL,
 `amount` decimal(10,4) unsigned NOT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `city_product` (`city_id`,`product_id`),
 KEY `fk_city_products_cities1` (`city_id`),
 KEY `fk_city_products_products1` (`product_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

MySQL Abfrage und Ergebnisse

Die Abfrage ist relativ simpel, ich möchte den Bestand von bestimmten Waren in allen Städten haben:

MySQL Abfrage

Kontrolliere ich die Abfrageausführung mit Explain, erhalte ich ständig andere Angaben: 

Wenn mir dies jemand erklären könnte, wäre dies echt toll.


4 Kommentare zu “Seltsames MySQL Verhalten”

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>