Hi i've got database for site which has a data of many companies (1 milion rows in main table):
In field Firmy_Szukaj i put data from other tables in which i keep telephonme numbers, fax numbers, emails (there are more then one phone per company) - this field is update onec per hour by cron script.
I retrieve data from it by 2 queries , fiorst with count (wiothout joining tabes and without grouping) and second:
Firmy_Status is a number in which i'd like sort (some companies can have a higher priority)
This query is fast for some phrases and very slow (even 15 sec) for others which is unacceptable
In this query i special use group to retrieve onmly one field of Telefony_Numer, Fax_Numer etc
Do you know how can i accelerate query ? How rebuild indexes to achieve faster searches?
Via-Net - web directory
Code:
CREATE TABLE `firmy_Firmy` (
`Firmy_Id` int(11) unsigned NOT NULL auto_increment,
`Firmy_Nazwa` varchar(255) collate utf8_polish_ci NOT NULL default '',
`Firmy_Opis` text collate utf8_polish_ci,
`Firmy_Ulica` varchar(255) collate utf8_polish_ci NOT NULL default '',
`Firmy_KodPocztowy` varchar(6) collate utf8_polish_ci NOT NULL default '',
`Miejscowosci_Id` int(10) unsigned NOT NULL default '0',
`Powiaty_Id` int(10) unsigned NOT NULL default '0',
`Wojewodztwa_Id` int(10) unsigned NOT NULL default '0',
`Firmy_Status` tinyint(3) unsigned NOT NULL default '10',
`Firmy_DataDodania` datetime NOT NULL default '2006-08-01 10:00:00',
`Firmy_DataModyfikacji` datetime default NULL,
`Firmy_Link` varchar(150) collate utf8_polish_ci NOT NULL default '',
`Firmy_Szukaj` text collate utf8_polish_ci,
PRIMARY KEY (`Firmy_Id`),
UNIQUE KEY `IX_Duplikaty` USING BTREE (`Firmy_Nazwa`,`Firmy_KodPocztowy`,`Miejscowosci_Id`),
UNIQUE KEY `IX_Link` USING BTREE (`Firmy_Link`),
FULLTEXT KEY `IX_Szukaj` (`Firmy_Nazwa`,`Firmy_Opis`,`Firmy_Ulica`,`Firmy_KodPocztowy`,`Firmy_Szukaj`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
In field Firmy_Szukaj i put data from other tables in which i keep telephonme numbers, fax numbers, emails (there are more then one phone per company) - this field is update onec per hour by cron script.
I retrieve data from it by 2 queries , fiorst with count (wiothout joining tabes and without grouping) and second:
Code:
SELECT MATCH(a.Firmy_Nazwa,a.Firmy_Opis,a.Firmy_Ulica,a.Firmy_KodPocztowy,a.Firmy_Szukaj) AGAINST ('+search +phrases' IN BOOLEAN MODE) AS Punkty,a.Firmy_Id, a.Firmy_Link,a.Firmy_Nazwa, a.Firmy_Ulica,a.Firmy_KodPocztowy, b.Miejscowosci_Nazwa,c.Powiaty_Nazwa, d.Wojewodztwa_Nazwa,e.Loga_Logo, e.Loga_LogoX,e.Loga_LogoY, a.Firmy_Status,f.Telefony_Numer, g.Faxy_Numer,h.Emaile_Adres,i.Strony[URL unfurl="true"]WWW_Adres[/URL] FROM firmy_Firmy AS a INNER JOIN firmy_Miejscowosci AS b ON b.Miejscowosci_Id=a.Miejscowosci_Id INNER JOIN firmy_Powiaty AS c ON c.Powiaty_Id=a.Powiaty_Id INNER JOIN firmy_Wojewodztwa AS d ON d.Wojewodztwa_Id=a.Wojewodztwa_Id LEFT JOIN firmy_Loga AS e ON e.Firmy_Id=a.Firmy_Id LEFT JOIN firmy_Telefony AS f ON f.Firmy_Id=a.Firmy_Id LEFT JOIN firmy_Faxy AS g ON g.Firmy_Id=a.Firmy_Id LEFT JOIN firmy_Emaile AS h ON h.Firmy_Id=a.Firmy_Id LEFT JOIN firmy_Strony[URL unfurl="true"]WWW AS[/URL] i ON i.Firmy_Id=a.Firmy_Id WHERE MATCH (a.Firmy_Nazwa,a.Firmy_Opis,a.Firmy_Ulica,a.Firmy_KodPocztowy,a.Firmy_Szukaj) AGAINST ('+search +phrases' IN BOOLEAN MODE) AND a.Firmy_Status >= 10 GROUP BY a.Firmy_Id ORDER BY a.Firmy_Status DESC, Punkty DESC LIMIT 0, 10
Firmy_Status is a number in which i'd like sort (some companies can have a higher priority)
This query is fast for some phrases and very slow (even 15 sec) for others which is unacceptable
In this query i special use group to retrieve onmly one field of Telefony_Numer, Fax_Numer etc
Do you know how can i accelerate query ? How rebuild indexes to achieve faster searches?
Via-Net - web directory