开发者

Please help optimize MYSQL table and/or query

I need to do something similar to this (see search filters on the left) http://www.indeed.com/job开发者_Go百科s?q=php&l=NY

I've already done everything I know and even though it became much faster than it used to, it's still not fast enough. I have many further optimization ideas but they are basically blind shots, I don't know whether that will work. So please check my current code and let me know if there are some serious mistake or some place that I overlooked. Below is the structure of the table, it has approximately 100k entries and is pretty huge - 640 MiB according to phpmyadmin. Also below is one of the queries I use to gather data for the filters, I won't copy other queries here because they are practically identical. The query time varies from 0.5 to 1 second which sum ups in approximately 5 seconds after I execute a query for each filter I need.

CREATE TABLE `jobs` (
 `id` int(11) NOT NULL auto_increment,
 `employer_id` int(11) NOT NULL default '0',
 `job_title` varchar(255) NOT NULL default '',
 `city` varchar(96) NOT NULL default '',
 `state` varchar(128) NOT NULL default '0',
 `country` varchar(48) NOT NULL default '0',
 `zip` varchar(10) NOT NULL default '0',
 `zlat` double NOT NULL default '0',
 `zlong` double NOT NULL default '0',
 `job_type` varchar(255) NOT NULL default '0',
 `position_type` varchar(255) NOT NULL default '0',
 `req_education` varchar(255) NOT NULL default '0',
 `req_experience` varchar(255) NOT NULL default '0',
 `salary_type` varchar(255) default '0',
 `approx_salary` decimal(10,2) NOT NULL default '0.00',
 `approx_salary_range` decimal(10,2) NOT NULL default '0.00',
 `short_description` varchar(255) NOT NULL default '',
 `long_description` text NOT NULL,
 `pay_low` decimal(10,2) NOT NULL default '0.00',
 `pay_high` decimal(10,2) NOT NULL default '0.00',
 `step_completed` tinyint(1) NOT NULL default '0',
 `num_viewed` int(11) NOT NULL default '0',
 `num_applicants` int(11) NOT NULL default '0',
 `time` int(11) NOT NULL default '0',
 `end_time` int(11) NOT NULL default '0',
 `status` varchar(15) NOT NULL default 'active',
 `service_type` int(11) NOT NULL default '0',
 `req_travel` varchar(255) NOT NULL default '',
 `tele_position` varchar(255) NOT NULL default '',
 `manage_app` varchar(255) NOT NULL default '',
 `apply_email_url` varchar(255) NOT NULL default '',
 `adcourier_email` text NOT NULL,
 `adcourier_url` text NOT NULL,
 `reference_number` varchar(255) NOT NULL,
 `feed_id` int(11) NOT NULL,
 `mods_feed_company_name` varchar(255) NOT NULL COMMENT 'A value in this column automaticaly means that users.is_bot=1 for this employer',
 `current_company_name` varchar(255) NOT NULL COMMENT 'this field lets us avoid JOINs in search queries',
 `salary_total_grouped` int(11) NOT NULL COMMENT 'a calculated field that is used to speed up search',
 `company_type_grouped` varchar(30) NOT NULL COMMENT 'a calculated field that is used to speed up search',
 `location_grouped` varchar(100) NOT NULL COMMENT 'a calculated field that is used to speed up search',
 PRIMARY KEY  (`id`),
 KEY `employer_id` (`employer_id`),
 KEY `status` (`status`),
 KEY `zip` (`zip`),
 KEY `zlat` (`zlat`),
 KEY `zlong` (`zlong`),
 KEY `feed_id` (`feed_id`),
 KEY `service_type` (`service_type`),
 KEY `time` (`time`),
 KEY `job_title` (`job_title`),
 KEY `short_description` (`short_description`),
 KEY `current_company_name` (`current_company_name`),
 KEY `salary_total_grouped` (`salary_total_grouped`),
 KEY `location_grouped` (`location_grouped`),
 KEY `company_type_grouped` (`company_type_grouped`),
 KEY `position_type` (`position_type`),
 KEY `job_type` (`job_type`),
 KEY `salary_type` (`salary_type`),
 KEY `approx_salary` (`approx_salary`),
 KEY `approx_salary_range` (`approx_salary_range`),
 KEY `country` (`country`),
 KEY `state` (`state`),
 KEY `city` (`city`),
 KEY `end_time` (`end_time`),
 FULLTEXT KEY `long_description` (`long_description`)
) ENGINE=MyISAM AUTO_INCREMENT=485825 DEFAULT CHARSET=latin1

SELECT count( jobs.job_title ) AS count, jobs.job_title
FROM jobs
WHERE jobs.status = 'active'
AND jobs.country = 'United States'
GROUP BY jobs.job_title
ORDER BY count DESC
LIMIT 14 


Try add an index on status, country, job_title, and do execution query plan to exam the performance


Think about the first, second, third and fourth database normal forms: http://en.wikipedia.org/wiki/Database_normalization

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜