MySQL Forums
Forum List  »  German

Re: Performance bei SELECT
Posted by: Thomas Wiedmann
Date: January 20, 2012 12:11PM

Hallo Mark,
diese zwei Spalten sind meiner Meinung nach vollkommen überdimensioniert.

CREATE TABLE `items` (
[...]
`Brand` varchar(255) NOT NULL, 
[...]
`attr_gender` varchar(100) NOT NULL, 
[...]
KEY `Brand` (`Brand`), 
[...]

wirklich benötigt wird nur dieser Größe:

SELECT MAX(LENGTH(brand)), MAX(LENGTH(attr_gender)) FROM items;

+--------------------+--------------------------+
| MAX(LENGTH(brand)) | MAX(LENGTH(attr_gender)) |
+--------------------+--------------------------+
|                 57 |                        1 |
+--------------------+--------------------------+

deshalb würde ich diese zwei Spalten in etwa so kürzen und einen combined index darüber legen:

ALTER TABLE items
 MODIFY brand VARCHAR(80) NOT NULL,
 MODIFY attr_gender VARCHAR(10) NOT NULL;
 
ALTER TABLE items
 DROP KEY brand,
 ADD KEY idx_brand_gender (brand, attr_gender);

Jetzt bitte nochmal den Query mit EXPLAIN ausführen.
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 ItemNrInt,MAX(OrderQty),MAX(FullPrice),MAX(OrderDate),MAX(ItemPriceNoVAT),MAX(Status)
              FROM invoicelines
             GROUP BY ItemNrInt
             ORDER BY NULL ) invoicelines
ON (invoicelines.ItemNrInt = items.ItemNrInt)
WHERE items.attr_gender = '8'
GROUP BY items.Brand;

Grüße
Thomas

Options: ReplyQuote


Subject
Views
Written By
Posted
2021
January 19, 2012 07:17AM
1164
January 19, 2012 12:59PM
1276
January 20, 2012 05:33AM
1419
January 20, 2012 06:10AM
1144
January 20, 2012 07:06AM
Re: Performance bei SELECT
1209
January 20, 2012 12:11PM
1122
January 25, 2012 04:11AM
1040
January 25, 2012 04:24AM
1054
January 25, 2012 04:30AM
969
January 25, 2012 04:49AM
921
January 25, 2012 06:05AM
1123
January 25, 2012 06:37AM
1050
January 25, 2012 07:46AM
1203
January 26, 2012 12:57AM
1036
January 25, 2012 11:11PM
980
January 25, 2012 11:50PM
922
January 27, 2012 08:27AM
1260
January 27, 2012 06:21AM
1080
February 02, 2012 10:06PM
888
February 03, 2012 05:34AM
1050
February 03, 2012 02:04PM
975
February 08, 2012 09:52PM
1033
February 09, 2012 08:41AM
1010
February 10, 2012 02:03AM
1203
February 10, 2012 02:52AM
1167
February 10, 2012 04:51AM
1088
February 09, 2012 11:58PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.