Hello
I'm so tired and i don't know what can i do. I did everything to improve this query but no way!!!
This query will "stopping" my server!! The load will be up to 250% for MySQL!!
The server will be "DOWN"!! I will be crazy too :sick:
Query is:
SELECT
jobs.id AS job_id,
jobs.job_title,
jobs.added_time +10800 AS added_time,
jobs.about_job,
users.full_name,
jobs.user_id,
jobs.host,
jobs.is_firm,
cities.city_name,
jobs.country_id
FROM
`employer_jobs` AS jobs,
`users_employers` AS users,
`cities` AS cities
WHERE
jobs.is_accept = 1
AND jobs.host = "localhost"
AND jobs.city_id = cities.city_id
AND jobs.user_id = users.user_id
ORDER BY jobs.is_firm DESC, jobs.added_time DESC LIMIT 0,10
When i remove this line the server health will be up! :eek:
`users_employers` AS users,
I uses this query in the index page to get the jobs.
You can see the Explain Select as an image in this topic.
Employers Accounts Tables Strucutes
Table Information:
Total Records: 21,211
Total Space: 8.1 MiB
Purpose: I use this table to get the "full_name" field.
CREATE TABLE IF NOT EXISTS `users_employers` (
`user_id` bigint(20) NOT NULL auto_increment,
`user_name` varchar(50) default NULL,
`user_pass` varchar(50) default NULL,
`user_email` varchar(100) default NULL,
`full_name` varchar(250) default NULL,
`manager_name` varchar(120) default NULL,
`about_me` mediumtext,
`country_id` tinyint(3) default '0',
`city_id` smallint(6) default '-1',
`employed_number` smallint(6) NOT NULL,
`mobile_no` varchar(20) default '0',
`tel_no` varchar(20) default '0',
`fax_no` varchar(20) default '0',
`address` varchar(150) default '0',
`user_photo` varchar(100) NOT NULL,
`user_photo_is_accept` tinyint(1) NOT NULL default '0',
`user_type` enum('EMPLOYER','COMPANY','OFFICE') NOT NULL default 'EMPLOYER',
`user_expire` int(11) default NULL,
`registration_date` int(11) default NULL,
`how_many_login` int(11) NOT NULL default '0',
`opt_hidden_mode` tinyint(1) NOT NULL default '0',
`opt_enable_sms` tinyint(1) NOT NULL,
`opt_email_notify` tinyint(3) default '1',
`opt_view_employer_contact_info` tinyint(1) NOT NULL,
`opt_user_style` varchar(100) default NULL,
`opt_time_diff_h` enum('+','-') NOT NULL default '+',
`opt_time_diff` tinyint(2) default NULL,
`opt_time_format` varchar(50) default NULL,
`opt_user_lang` varchar(100) default NULL,
`sms_verify_code` smallint(5) default NULL,
`sms_balance` mediumint(5) default NULL,
`last_login` int(11) default NULL,
`is_opened` tinyint(3) default '0',
`last_ip` varchar(16) NOT NULL,
`how_many_viewd` int(11) NOT NULL,
`last_viewd` int(11) NOT NULL,
`host` varchar(100) NOT NULL,
PRIMARY KEY (`user_id`),
KEY `user_name` (`user_name`),
KEY `user_email` (`user_email`),
KEY `country_id` (`country_id`),
KEY `city_id` (`city_id`),
KEY `user_photo_is_accept` (`user_photo_is_accept`),
KEY `user_type` (`user_type`),
KEY `opt_enable_sms` (`opt_enable_sms`),
KEY `opt_email_notify` (`opt_email_notify`),
KEY `opt_view_employer_contact_info` (`opt_view_employer_contact_info`),
KEY `is_opened` (`is_opened`),
KEY `host` (`host`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=23248 ;
--------------------------------------------------------------------------
Employers Accounts Tables Strucutes
Table Information:
Total Records: 10,839
Total Space: 4.1 MiB
Purpose: I use this table to get the "employers" jobs.
CREATE TABLE IF NOT EXISTS `employer_jobs` (
`id` int(11) NOT NULL auto_increment,
`user_id` bigint(20) default NULL,
`job_title` varchar(200) default NULL,
`job_type` enum('FULL','PARTIAL','ALL') NOT NULL default 'ALL',
`salary_from` bigint(20) NOT NULL,
`salary_to` bigint(20) NOT NULL default '0',
`currency` tinyint(3) NOT NULL,
`job_cat_id` tinyint(10) default NULL,
`country_id` tinyint(3) default '0',
`city_id` smallint(6) default '-1',
`about_job` mediumtext,
`other_requirements` mediumtext,
`comments` mediumtext,
`age_from` tinyint(2) NOT NULL default '0',
`age_to` tinyint(2) NOT NULL default '0',
`degree_id` tinyint(3) default '0',
`gender` enum('M','F','L') NOT NULL default 'L',
`nationality_id` smallint(6) NOT NULL default '-1',
`experience_years` tinyint(2) default NULL,
`is_filter` tinyint(1) NOT NULL default '0',
`view_email` tinyint(1) default '1',
`view_mobile` tinyint(1) default '1',
`view_tel` tinyint(1) default '1',
`view_fax` tinyint(1) default '1',
`added_time` int(11) default NULL,
`is_accept` tinyint(3) default '1',
`is_firm` tinyint(1) default '0',
`host` varchar(255) default NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `country_id` (`country_id`),
KEY `city_id` (`city_id`),
KEY `nationality_id` (`nationality_id`),
KEY `job_type` (`job_type`),
KEY `job_cat_id` (`job_cat_id`),
KEY `gender` (`gender`),
KEY `experience_years` (`experience_years`),
KEY `view_email` (`view_email`),
KEY `view_mobile` (`view_mobile`),
KEY `view_tel` (`view_tel`),
KEY `view_fax` (`view_fax`),
KEY `is_accept` (`is_accept`),
KEY `added_time` (`added_time`),
KEY `is_firm` (`is_firm`),
KEY `host` (`host`),
KEY `added_time_2` (`added_time`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=21673 ;
My Solution for this
I just have one solution is: Storing the "full_name" field in the "employer_jobs" But what if the user changed the full name? I need to update the table again. I see is not a good solution for the problem.
I WILL BE SO HAPPY IF YOU CAN HELP ME TO IMPROVE THIS "IMPOSSIBLE QUERY"
Thanks,