MySQL: Warum 8.76 Sekunden?
Schorsch
- datenbank
Guten Tag
Warum braucht folgende Abfrage bei gesundem System
8.76 Sekunden?
SELECT DISTINCT t.title_id, t.title_title
FROM title AS t, author AS a
LEFT JOIN keyw_junc AS kj ON kj.title_id=t.title_id
LEFT JOIN author AS a1 ON a1.author_id=t.author_id
LEFT JOIN author AS a2 ON a2.author_id=t.coauthor_id
LEFT JOIN author AS a3 ON a3.author_id=t.editor_id
LEFT JOIN author AS a4 ON a4.author_id=t.coeditor_id
WHERE a1.author_first='edgar'
So dauert es 0.0047 Sekunden:
SELECT t.title_id, t.title_title
FROM biblio_title AS t, biblio_author AS a
LEFT JOIN biblio_keyw_junc AS kj ON kj.title_id=t.title_id
Und so dauert es 0.0455 Sekunden:
SELECT DISTINCT t.title_id, t.title_title
FROM biblio_title AS t, biblio_author AS a
LEFT JOIN biblio_author AS a1 ON a1.author_id=t.author_id
LEFT JOIN biblio_author AS a2 ON a2.author_id=t.coauthor_id
LEFT JOIN biblio_author AS a3 ON a3.author_id=t.editor_id
LEFT JOIN biblio_author AS a4 ON a4.author_id=t.coeditor_id
WHERE a1.author_first='edgar'
Es sind rund 400 Datensätze.
Kann mir jemand erklären, wie ich meine Abfrage gestalten muss, damit diese in vernünftiger Zeit zustande kommt?
Gruss
Schorsch
ge'jointe' tabellen brauche natürlich mehr zeit.
aber: sind auf den verknüpfungen indizees drauf?
Salut
aber: sind auf den verknüpfungen indizees drauf?
Wow, das wirkte ja Wunder!
Tatsächlich waren noch nicht alle relevanten Spalten indexiert.
Gell, die Primary-Key Spalte wird bei MySQL automatisch indexiert man muss dort drauf nicht noch extra einen Index anlegen. Oder?
Merci!
Schorsch
Hallo,
aber: sind auf den verknüpfungen indizees drauf?
Wow, das wirkte ja Wunder!
*g* Ja, nicht? Das ist genau das, wofür ein Index da ist ;-)).
Gell, die Primary-Key Spalte wird bei MySQL automatisch indexiert man muss dort drauf nicht noch extra einen Index anlegen. Oder?
Ja, PRIMARY-KEY ist einfach eine Kombination von UNIQUE und NOT NULL.
http://dev.mysql.com/doc/mysql/en/create-table.html
...
KEY is normally a synonym for INDEX. From MySQL 4.1, the key attribute PRIMARY KEY can also be specified as just KEY when given in a column definition. This was implemented for compatibility with other database systems.
In MySQL, a UNIQUE index is one in which all values in the index must be distinct. An error occurs if you try to add a new row with a key that matches an existing row. The exception to this is that if a column in the index is allowed to contain NULL values, it can contain multiple NULL values. This exception does not apply to BDB tables, for which an indexed column allows only a single NULL.
A PRIMARY KEY is a unique KEY where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL declares them so implicitly (and silently). A table can have only one PRIMARY KEY. If you don't have a PRIMARY KEY and an application asks for the PRIMARY KEY in your tables, MySQL returns the first UNIQUE index that has no NULL columns as the PRIMARY KEY.
...
viele Grüße
Axel