MySqli, Performance

siclesv

Grünschnabel
Hallo,

ich habe ein größeres Performance-Problem und erhoffe mir hier ein paar Ansätze zur Optimierung meiner SQL-Query zu erhalten.

Ich habe in einer DB 2 Tabellen, die in Beziehung zu einerander stehen und ca. 60.000 Datensätze haben.

Tabelle 1 enthält:
ID (int, primary) - pid (int) - title (var255)

Tabelle 2 enthält
ID(int, primary) - pid(int) - price(char10) - ...

Meine Query (mysqli prepare):

SQL:
SELECT
       product_meta.pid,
       product_meta.title,
       product_attribute.price,
       product_attribute.shop,
       product_attribute.url
FROM
       product_meta,
       product_attribute
WHERE
       product_meta.title LIKE ?
       AND
       product_meta.pid = product_attribute.pid
LIMIT 0,48

Möchte ich hier nun nach z.B: product_attribute.price sortieren:

SQL:
SELECT
       product_meta.pid,
       product_meta.title,
       product_attribute.price,
       product_attribute.shop,
       product_attribute.url
FROM
       product_meta,
       product_attribute
WHERE
       product_meta.title LIKE ?
       AND
       product_meta.pid = product_attribute.pid
ORDER BY product_attribute.price DESC
LIMIT 0,48

kriege ich nach geraumer Zeit einen 500er Fehler.

Wie kann ich hier die Performance steigern bzw. meine Query optimieren
 
Zuletzt bearbeitet von einem Moderator:
Indexe product_meta: ID (primary), pid (Unique), tilte (Fulltext)
Indexe product_attribute: ID (primary), pid (Unique), price (Index)
 
Mein Fehler. Ist ja im WHERE.

ggf. hilft das folgende. Ansonsten zeig uns mail den Explain-Plan
SQL:
SELECT
       m.pid,
       m.title,
       a.price,
       a.shop,
       a.url
FROM
       (
              SELECT
                     pid,
                     title
              FROM
                     product_meta
              WHERE
                     title LIKE ?
       ) m,
       product_attribute a
WHERE
       m.pid = a.pid
ORDER BY 
       a.price DESC
LIMIT 0,48
 
Zurück