I have a view, based on table 'items' in my database:
v_items_search:
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost`
SQL SECURITY DEFINER VIEW `v_items_search` AS
select
`items`.`id` AS `id`,
`items`.`res_id` AS `res_id`,
`items`.`nd_date` AS `nd_date`,
`items`.`not_date` AS `not_date`,
`items`.`title` AS `title`,
`items`.`content` AS `content`,
concat(`items`.`title`, ' ', `items`.`content`) AS `text`
from `items`;
items:
CREATE TABLE IF NOT EXISTS `items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`log_id` int(11) NOT NULL,
`res_id` int(11) NOT NULL,
`link` varchar(255) NOT NULL,
`title` text NOT NULL,
`content` text NOT NULL,
`n_date` varchar(255) NOT NULL,
`nd_date` int(11) NOT NULL,
`s_date` int(11) NOT NULL,
`not_date` date NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `link_2` (`link`),
KEY `log_id` (`log_id`),
KEY `res_id` (`res_id`),
KEY `now_date` (`not_date`),
KEY `sql_index` (`res_id`,`id`,`not_date`)
) ENGINE=Aria DEFAULT CHARSET=utf8 PAGE_CHECKSUM=0 AUTO_INCREMENT=18382133 ;
And I have php script analyzer.php
, which realize serching in this view. For example, it receives some tags and period(not_date) and search it in view like this:
SELECT R.RESOURCE_NAME, R.RESOURCE_LOGO, I.*
FROM v_items_search I, resource R, countries C
where I.not_date>='".$s_date."'
and I.not_date<='".$f_date."'
and (I.text like '%hellow% or I.text like '%world%')
AND R.RESOURCE_ID = I.res_id
AND R.COUNTRY_ID = I.res_id
AND R.COUNTRY_ID = C.id
order by not_date asc, nd_date asc.
if period more than 2 month, analyzer divide the period on 10 parts. Then it run 10 queries with delay 1 min. When the last part done it collect all data. In this way, annual query can take from 40 to over 100 minutes. It's too long for me. Considering, that old analyzer don't divide long period queries and could not completed at all.
How I can do this process make faster? thank you in advance...