MySQL Forums
Forum List  »  Optimizer & Parser

Re: Query needs to be optimized
Posted by: ponvictor abraham
Date: July 01, 2010 12:28AM

Hi James,

Below are the information req. for you.

And i changed the query. The query which i am using now is also noted below
Please give me you email id so that i can send you the details in a right format as attachment

Thanks
Victor

CREATE TABLE `job` (
`id` int(11) NOT NULL default '0',
`batch_id` int(11) default '0',
`customer` varchar(255) NOT NULL default '0',
`timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
`active` char(1) NOT NULL default 'N',
`requisition_number` varchar(255) NOT NULL default '0',
`io_number` varchar(255) default NULL,
`reply_to` varchar(255) default NULL,
`company_name` varchar(255) NOT NULL default '',
`company_description_en` text,
`company_division` varchar(255) default NULL,
`company_department` varchar(255) default NULL,
`recruiter_org` varchar(255) default NULL,
`recruiter_name` varchar(255) default NULL,
`recruiter_email` varchar(255) default NULL,
`company_streetaddress` varchar(255) default NULL,
`company_city` varchar(255) default NULL,
`company_stateprovince` varchar(6) default NULL,
`company_postalcode` varchar(255) default NULL,
`company_country` char(2) default NULL,
`company_phone` varchar(255) default NULL,
`company_fax` varchar(255) default NULL,
`location_country` char(2) default NULL,
`location_city` varchar(255) default NULL,
`location_stateprovince` varchar(6) default NULL,
`location_postalcode` varchar(255) default NULL,
`location_us_areacode` smallint(6) default NULL,
`title_en` text,
`classification_type` enum('PERMANENT','CONTRACT','CONTRACTPERMANENT','INTERN') NOT NULL,
`classification_time` enum('FULLTIME','PARTTIME') NOT NULL,
`start_date` char(10) default NULL,
`end_date` char(10) default NULL,
`compensation_type` enum('SALARY','HOURLY') NOT NULL,
`compensation_currency` char(3) default NULL,
`compensation_amount` bigint(20) default NULL,
`compensation_range_min` bigint(20) default NULL,
`compensation_range_max` bigint(20) default NULL,
`travel_percentage` int(11) default NULL,
`telecommute_percentage` int(11) default NULL,
`function` char(8) default NULL,
`industry` char(2) default NULL,
`education` enum('HIGHSCHOOL','SOMECOLLEGE','CERTIFICATION','ASSOCIATEDEGREE','BACHELORSDEGREE','MASTERSDEGREE','EQUIVALENTEXPERIENCE','DOCTORATE') NOT NULL,
`description_en` text,
`contact_name` varchar(255) default NULL,
`contact_email` varchar(255) default NULL,
`company_id` int(11) NOT NULL default '0',
UNIQUE KEY `job_id_index` (`id`),
KEY `job_customer_index` (`customer`),
KEY `job_active_index` (`active`),
KEY `job_requisition_number_index` (`requisition_number`),
KEY `job_timestamp_index` (`timestamp`),
KEY `job_company_name_index` (`company_name`),
KEY `job_company_id_timestamp_index` (`company_id`,`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

CREATE TABLE `posting` (
`id` int(11) NOT NULL default '0',
`job_id` int(11) NOT NULL default '0',
`board_id` int(11) NOT NULL default '0',
`auth_id` varchar(255) NOT NULL default '',
`auth_pw` varchar(255) default NULL,
`action` varchar(6) default NULL,
`candidate_response_url` text,
`candidate_response_email` varchar(255) default NULL,
`in_process` varchar(10) default NULL,
`expires_timestamp` datetime default NULL,
`last_action_timestamp` datetime default NULL,
`timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
`active` char(1) NOT NULL default 'N',
`export_every_time` char(1) default NULL,
`tracking_id` varchar(255) default NULL,
`deferred` char(1) NOT NULL default 'N',
`deferred_reason` varchar(255) default NULL,
`live_url` text,
UNIQUE KEY `posting_id_index` (`id`),
KEY `posting_deferred_index` (`deferred`),
KEY `posting_auth_id_index` (`auth_id`),
KEY `posting_timestamp__index` (`timestamp`),
KEY `posting_board_id_active_deferred_index` (`board_id`,`active`,`deferred`),
KEY `posting_active_timestamp_index` (`active`,`timestamp`),
KEY `posting_job_id_timestamp_index` (`job_id`,`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

CREATE TABLE `board` (
`id` int(11) NOT NULL default '0',
`board_name` varchar(255) NOT NULL default '',
`url` varchar(255) default NULL,
`posting_expire_days` int(11) default NULL,
`type` int(11) NOT NULL default '0',
`board_additional_data` char(1) default NULL,
`avg_first_hit_time` int(11) NOT NULL default '0',
`post_url` text,
`html_allowed` char(1) NOT NULL default 'N',
`contact_name` varchar(255) NOT NULL default '',
`contact_email` varchar(255) NOT NULL default '',
`notes` text NOT NULL,
UNIQUE KEY `board_name_index` (`board_name`),
UNIQUE KEY `board_id_index` (`id`),
KEY `board_type_index` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1


CREATE TABLE `ars_hits` (
`posting_id` int(11) NOT NULL default '0',
`timestamp` datetime default NULL,
`ip_address` int(10) unsigned default NULL,
KEY `ars_hits_posting_id_index` (`posting_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

CREATE TABLE `ars_views` (
`posting_id` int(11) NOT NULL default '0',
`timestamp` datetime default NULL,
`ip_address` int(10) unsigned default NULL,
KEY `ars_views_posting_id_index` (`posting_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1


ame Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
_schema_info InnoDB 10 Compact 1 16384 16384 0 0 0 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 0 kB
_sequence_action_id_seq InnoDB 10 Compact 11239 29 327680 0 0 0 12313681 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 0 kB
_sequence_board_id_seq InnoDB 10 Compact 1 16384 16384 0 0 0 843 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 0 kB
_sequence_job_id_seq InnoDB 10 Compact 1879 34 65536 0 0 0 2125779 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 0 kB
_sequence_posting_id_seq InnoDB 10 Compact 5698 31 180224 0 0 0 5574474 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 0 kB
action InnoDB 10 Compact 12282727 40 496975872 0 627376128 0 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 7168 kB
additional_data InnoDB 10 Compact 13842484 60 840957952 0 487587840 0 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 6144 kB
ars InnoDB 10 Compact 1 16384 16384 0 16384 0 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 0 kB
ars_hits InnoDB 10 Compact 12441371 44 558891008 0 352321536 0 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 5120 kB
ars_views InnoDB 10 Compact 40709992 44 1821376512 0 1216348160 0 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 4096 kB
board InnoDB 10 Compact 804 224 180224 0 98304 0 6/30/2010 05:57:22 latin1_swedish_ci InnoDB free: 0 kB
board_additional_data InnoDB 10 Compact 1179 1347 1589248 0 16384 0 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 4096 kB
job InnoDB 10 Compact 2582097 3332 8603566080 0 361578496 0 7/1/2010 00:49:21 latin1_swedish_ci InnoDB free: 5120 kB
job_de_fr InnoDB 10 Compact 3971469 91 363593728 0 0 0 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 6144 kB
job_details InnoDB 10 Compact 2280127 1545 3524263936 0 0 0 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 5120 kB
posting InnoDB 10 Compact 5616544 214 1202716672 0 835305472 0 6/30/2010 05:49:01 latin1_swedish_ci InnoDB free: 4096 kB
usps InnoDB 10 Compact 80220 98 7880704 0 16842752 0 6/24/2010 02:02:38 latin1_swedish_ci InnoDB free: 4096 kB

explain SELECT p.id,
p.timestamp,
j.requisition_number,
j.title_en,
j.customer,
b.board_name,
(SELECT COUNT(v.posting_id) FROM annwn.ars_views v WHERE v.posting_id=p.id) AS 'views',
(SELECT COUNT(h.posting_id) FROM annwn.ars_hits h WHERE h.posting_id=p.id) AS 'clicks',
j.company_division,
j.recruiter_name,
j.location_stateprovince,
j.location_city,
j.location_postalcode,
j.function,
j.company_id
FROM annwn_sivakumar.job j
JOIN annwn_sivakumar.posting p ON j.company_id = 139
AND j.timestamp >='2008-01-01'
AND j.timestamp <='2010-06-01' AND j.id=p.job_id
AND p.timestamp >='2008-01-01'
AND p.timestamp<='2010-06-01'
JOIN annwn_sivakumar.board b ON b.id=p.board_id


1 PRIMARY j range job_id_index,job_timestamp_index,job_company_id_timestamp_index job_company_id_timestamp_index 12 42800 Using where
1 PRIMARY p ref posting_timestamp__index,posting_board_id_active_deferred_index,posting_job_id_timestamp_index posting_job_id_timestamp_index 4 annwn_sivakumar.j.id 1 Using where
1 PRIMARY b eq_ref board_id_index board_id_index 4 annwn_sivakumar.p.board_id 1 Using index
3 DEPENDENT SUBQUERY h ref ars_hits_posting_id_index ars_hits_posting_id_index 4 annwn_sivakumar.p.id 15 Using index
2 DEPENDENT SUBQUERY v ref ars_views_posting_id_index ars_views_posting_id_index 4 annwn_sivakumar.p.id 175 Using index

o/p of show variables

auto_increment_increment 1
auto_increment_offset 1
automatic_sp_privileges ON
back_log 50
basedir /usr/
binlog_cache_size 32768
bulk_insert_buffer_size 64
character_set_client utf8
character_set_connection utf8
character_set_database latin1
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
character_sets_dir /usr/share/mysql/charsets/
collation_connection utf8_general_ci
collation_database latin1_swedish_ci
collation_server latin1_swedish_ci
completion_type 0
concurrent_insert 1
connect_timeout 5
datadir /var/lib/mysql/
date_format %Y-%m-%d
datetime_format %Y-%m-%d %H:%i:%s
default_week_format 0
delay_key_write ON
delayed_insert_limit 100
delayed_insert_timeout 300
delayed_queue_size 1000
div_precision_increment 4
keep_files_on_create OFF
engine_condition_pushdown OFF
expire_logs_days 10
flush OFF
flush_time 0
ft_boolean_syntax + -><()~*:""&|
ft_max_word_len 84
ft_min_word_len 4
ft_query_expansion_limit 20
ft_stopword_file (built-in)
group_concat_max_len 1024
have_archive YES
have_bdb NO
have_blackhole_engine YES
have_compress YES
have_crypt YES
have_csv YES
have_dynamic_loading YES
have_example_engine NO
have_federated_engine YES
have_geometry YES
have_innodb YES
have_isam NO
have_merge_engine YES
have_ndbcluster DISABLED
have_openssl DISABLED
have_ssl DISABLED
have_query_cache YES
have_raid NO
have_rtree_keys YES
have_symlink YES
hostname onix.equest.com
init_connect
init_file
init_slave
innodb_additional_mem_pool_size 1048576
innodb_autoextend_increment 8
innodb_buffer_pool_awe_mem_mb 0
innodb_buffer_pool_size 1887436800
innodb_checksums ON
innodb_commit_concurrency 0
innodb_concurrency_tickets 500
innodb_data_file_path ibdata1:10M:autoextend
innodb_data_home_dir
innodb_doublewrite ON
innodb_fast_shutdown 1
innodb_file_io_threads 4
innodb_file_per_table ON
innodb_flush_log_at_trx_commit 0
innodb_flush_method
innodb_force_recovery 0
innodb_lock_wait_timeout 50
innodb_locks_unsafe_for_binlog OFF
innodb_log_arch_dir
innodb_log_archive OFF
innodb_log_buffer_size 4194304
innodb_log_file_size 134217728
innodb_log_files_in_group 2
innodb_log_group_home_dir ./
innodb_max_dirty_pages_pct 90
innodb_max_purge_lag 0
innodb_mirrored_log_groups 1
innodb_open_files 300
innodb_rollback_on_timeout OFF
innodb_support_xa ON
innodb_sync_spin_loops 20
innodb_table_locks ON
innodb_thread_concurrency 8
innodb_thread_sleep_delay 10000
interactive_timeout 28800
join_buffer_size 131072
key_buffer_size 16777216
key_cache_age_threshold 300
key_cache_block_size 1024
key_cache_division_limit 100
language /usr/share/mysql/english/
large_files_support ON
large_page_size 0
large_pages OFF
lc_time_names en_US
license GPL
local_infile ON
locked_in_memory OFF
log OFF
log_bin ON
log_bin_trust_function_creators OFF
log_error
log_queries_not_using_indexes OFF
log_slave_updates OFF
log_slow_queries OFF
log_warnings 1
long_query_time 10
low_priority_updates OFF
lower_case_file_system OFF
lower_case_table_names 0
max_allowed_packet 16776192
max_binlog_cache_size 4294967295
max_binlog_size 104857600
max_connect_errors 10
max_connections 100
max_delayed_threads 20
max_error_count 64
max_heap_table_size 16777216
max_insert_delayed_threads 20
max_join_size 18446744073709551615
max_length_for_sort_data 1024
max_prepared_stmt_count 16382
max_relay_log_size 0
max_seeks_for_key 4294967295
max_sort_length 1024
max_sp_recursion_depth 0
max_tmp_tables 32
max_user_connections 0
max_write_lock_count 4294967295
multi_range_count 256
myisam_data_pointer_size 6
myisam_max_sort_file_size 2147483647
myisam_recover_options BACKUP
myisam_repair_threads 1
myisam_sort_buffer_size 8388608
myisam_stats_method nulls_unequal
ndb_autoincrement_prefetch_sz 32
ndb_force_send ON
ndb_use_exact_count ON
ndb_use_transactions ON
ndb_cache_check_time 0
ndb_connectstring
net_buffer_length 16384
net_read_timeout 30
net_retry_count 10
net_write_timeout 60
new OFF
old_passwords OFF
open_files_limit 2158
optimizer_prune_level 1
optimizer_search_depth 62
pid_file /var/run/mysqld/mysqld.pid
port 3306
preload_buffer_size 32768
profiling ON
profiling_history_size 15
protocol_version 10
query_alloc_block_size 8192
query_cache_limit 1048576
query_cache_min_res_unit 4096
query_cache_size 16777216
query_cache_type ON
query_cache_wlock_invalidate OFF
query_prealloc_size 8192
range_alloc_block_size 2048
read_buffer_size 131072
read_only OFF
read_rnd_buffer_size 262144
relay_log_purge ON
relay_log_space_limit 0
rpl_recovery_rank 0
secure_auth OFF
secure_file_priv
server_id 4
skip_external_locking ON
skip_networking OFF
skip_show_database OFF
slave_compressed_protocol OFF
slave_load_tmpdir /tmp/
slave_net_timeout 3600
slave_skip_errors OFF
slave_transaction_retries 10
slow_launch_time 2
socket /var/run/mysqld/mysqld.sock
sort_buffer_size 2097144
sql_big_selects ON
sql_mode
sql_notes ON
sql_warnings OFF
ssl_ca
ssl_capath
ssl_cert
ssl_cipher
ssl_key
storage_engine InnoDB
sync_binlog 0
sync_frm ON
system_time_zone CDT
table_cache 1024
table_lock_wait_timeout 50
table_type InnoDB
thread_cache_size 8
thread_stack 131072
time_format %H:%i:%s
time_zone SYSTEM
timed_mutexes OFF
tmp_table_size 33554432
tmpdir /tmp
transaction_alloc_block_size 8192
transaction_prealloc_size 4096
tx_isolation REPEATABLE-READ
updatable_views_with_limit YES
version 5.0.51a-24+lenny4-log
version_comment (Debian)
version_compile_machine i486
version_compile_os debian-linux-gnu
wait_timeout 28800

Options: ReplyQuote


Subject
Views
Written By
Posted
3123
June 29, 2010 03:39AM
1478
June 30, 2010 08:50AM
Re: Query needs to be optimized
1805
July 01, 2010 12:28AM
1404
July 01, 2010 09:43PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.