Het uivoeren van een bepaalde query (zie hieronder) duurt ongeveer 30 sec. Is het mogelijk om deze query te optimaliseren zodat hij nog maar enkele seconden in beslag neemt?
Overzicht van de tabellen:
De waarde AUTO_INCREMENT geeft aan hoeveel rijen de tabel ongeveer bevat.
De query die ik uitvoer is als volgt:
Ik heb het tevens ook met de volgende query geprobeerd, deze duurt echter langer dan 1 minuut.
Wie kan mij een hiermee helpen? Is mijn database structuur verkeerd? Of ligt het aan de query?
Overzicht van de tabellen:
SQL:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
| -- -- Tabel structuur voor tabel city -- CREATE TABLE `city` ( `id` int(11) NOT NULL auto_increment, `id_region` int(11) NOT NULL default '0', `idname` varchar(50) NOT NULL default '', `name` varchar(50) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=112109 DEFAULT CHARSET=latin1 PACK_KEYS=0; -- -- Tabel structuur voor tabel `country` -- CREATE TABLE `country` ( `id` int(11) NOT NULL auto_increment, `code` char(2) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=29 DEFAULT CHARSET=latin1; -- -- Tabel structuur voor tabel `country_text` -- CREATE TABLE `country_text` ( `id` int(11) NOT NULL auto_increment, `id_language` int(11) NOT NULL default '0', `id_country` int(11) NOT NULL default '0', `idname` varchar(50) NOT NULL default '', `name` varchar(50) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=267 DEFAULT CHARSET=latin1; -- -- Tabel structuur voor tabel `realestate` -- CREATE TABLE `realestate` ( `id` int(11) NOT NULL auto_increment, `id_broker` int(11) NOT NULL default '0', `id_city` int(11) NOT NULL default '0', `active` enum('Y','N') NOT NULL default 'Y', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=306821 DEFAULT CHARSET=latin1; -- -- Tabel structuur voor tabel `region` -- CREATE TABLE `region` ( `id` int(11) NOT NULL auto_increment, `id_country` int(11) NOT NULL default '0', `code` varchar(10) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=422 DEFAULT CHARSET=latin1; -- -- Tabel structuur voor tabel `region_text` -- CREATE TABLE `region_text` ( `id` int(11) NOT NULL auto_increment, `id_language` int(11) NOT NULL default '0', `id_region` int(11) NOT NULL default '0', `idname` varchar(50) NOT NULL default '', `name` varchar(50) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=512 DEFAULT CHARSET=latin1; |
De waarde AUTO_INCREMENT geeft aan hoeveel rijen de tabel ongeveer bevat.
De query die ik uitvoer is als volgt:
SQL:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| SELECT r.*, ci.id AS idcity, ci.idname AS idnamecity, ci.name AS namecity, re.id AS idregion, ret.idname AS idnameregion, ret.name AS nameregion, co.id AS idcountry, cot.idname AS idnamecountry, cot.name AS namecountry FROM realestate AS r LEFT JOIN city AS ci ON (r.id_city = ci.id) LEFT JOIN region AS re ON (ci.id_region = re.id) LEFT JOIN region_text AS ret ON (ret.id_region = re.id) LEFT JOIN country AS co ON (re.id_country = co.id) LEFT JOIN country_text AS cot ON (co.id = cot.id_country) WHERE r.active = 'Y' AND ret.id_language = '1' AND cot.id_language = '1' ORDER BY r.id DESC |
Ik heb het tevens ook met de volgende query geprobeerd, deze duurt echter langer dan 1 minuut.
SQL:
1
2
3
4
5
6
7
8
9
10
| SELECT r.*, ci.id AS idcity, ci.idname AS idnamecity, ci.name AS namecity, re.id AS idregion, ret.idname AS idnameregion, ret.name AS nameregion, co.id AS idcountry, cot.idname AS idnamecountry, cot.name AS namecountry FROM realestate AS r, city AS ci, region AS re, region_text AS ret, country AS co, country_text AS cot WHERE r.active = 'Y' AND r.id_city = ci.id AND ci.id_region = re.id AND re.id_country = co.id AND ret.id_region = re.id AND cot.id_country = co.id AND ret.id_language = '1' AND cot.id_language = '1' |
Wie kan mij een hiermee helpen? Is mijn database structuur verkeerd? Of ligt het aan de query?
[ Voor 0% gewijzigd door GewoonNico op 07-02-2007 19:36 . Reden: kleine nags ]