Ich habe mir folgende View gebastelt:
Quellcode
- CREATE VIEW `MarktStatistik`.`view_Item_Markt` AS
- SELECT iditems,itemName,itemUnique,itemVG ,
- (SELECT COUNT(*) FROM forakesh WHERE items_iditems = i.iditems ) AS anzMarkt,
- (SELECT itemMarktDatum FROM forakesh WHERE items_iditems = i.iditems ORDER BY itemMarktDatum ASC LIMIT 0,1) AS altMarkt,
- (SELECT itemMarktDatum FROM forakesh WHERE items_iditems = i.iditems ORDER BY itemMarktDatum DESC LIMIT 0,1) AS neuMarkt,
- (SELECT SUM(itemGold) / count(*) FROM forakesh WHERE items_iditems = i.iditems) AS dsGOLD,
- (SELECT itemGold FROM forakesh WHERE items_iditems = i.iditems ORDER BY itemMarktDatum ASC LIMIT 0,1) AS hGold,
- (SELECT itemGold FROM forakesh WHERE items_iditems = i.iditems ORDER BY itemMarktDatum DESC LIMIT 0,1) AS nGold,
- (SELECT SUM(itemZustand) / COUNT(*) FROM forakesh WHERE items_iditems = i.iditems) AS dsZustand,
- round (
- (
- UNIX_TIMESTAMP( NOW() ) -
- UNIX_TIMESTAMP((SELECT itemMarktDatum FROM forakesh WHERE items_iditems = i.iditems ORDER BY itemMarktDatum ASC LIMIT 0,1))
- ) / (SELECT COUNT(*) FROM forakesh WHERE items_iditems = i.iditems ) / 3600
- ) AS dsStd
- FROM items AS i
- WHERE
- i.iditems IN (SELECT items_iditems FROM forakesh)
Diese funktioniert recht gut, aber ist von der Performance her recht anspruchsvoll. Bei der Itemtabelle befinden sich ca. 5500 und der Forakeshtabelle 17500 Einträge. Die Anzahl ist steigend. Zur Zeit benötigt die Abfrage ca. 2,5 bis 3,5 Sekunden.
Könnt Ihr mir bei der Optimierung helfen? Wenn ja, wie?
Ref-Links sind verboten!