Hallo Thomas,
die Spalte PhysicalStock ist jetzt INT ...
key_buffer_size sind auf 20% gesetzt -> das sind in dem Fall 1,6 GB
Query DISTINCT ist auf die benötigten Spalten reduziert.
>> SELECT MAX(LENGTH(brand)), MAX(LENGTH(attr_gender)) FROM items;
+--------------------+--------------------------+
| MAX(LENGTH(brand)) | MAX(LENGTH(attr_gender)) |
+--------------------+--------------------------+
| 57 | 1 |
+--------------------+--------------------------+
Und nun der neue Explain vom Select
EXPLAIN SELECT items.Brand,
SUM(
(SELECT SUM(its.PhysicalStock)
FROM items_stock AS its
WHERE its.ItemNrInt = items.ItemNrInt
)
) AS stockValue
FROM items
LEFT JOIN ( SELECT DISTINCT ItemNrInt,OrderQty,FullPrice,OrderDate,ItemPriceNoVAT,Status FROM invoicelines) invoicelines
ON (invoicelines.ItemNrInt = items.ItemNrInt)
WHERE items.attr_gender = '8'
GROUP BY items.Brand;
+----+--------------------+--------------+------+---------------+-----------+---------+---------------------------------+--------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+--------------+------+---------------+-----------+---------+---------------------------------+--------+----------------------------------------------+
| 1 | PRIMARY | items | ALL | NULL | NULL | NULL | NULL | 69093 | Using where; Using temporary; Using filesort |
| 1 | PRIMARY | <derived3> | ALL | NULL | NULL | NULL | NULL | 498768 | |
| 3 | DERIVED | invoicelines | ALL | NULL | NULL | NULL | NULL | 499560 | Using temporary |
| 2 | DEPENDENT SUBQUERY | its | ref | ItemNrInt | ItemNrInt | 4 | pixi_imperial_2.items.ItemNrInt | 8 | |
+----+--------------------+--------------+------+---------------+-----------+---------+---------------------------------+--------+----------------------------------------------+
Die Abfrage so dauert ca. 260 sec :)
Es ist wirklich der JOIN auf die Invoicelines ... ohne den ist die Abfrage schnell.
Möglicherweise muss ich den in ein SubSelect auslagern - das würde mir aber nicht so sehr gefallen
Danke schonmal