Hello Friends, I've some performance problem, when I do sum() functions on my tables it took 5-7 minutes to return the results.. here is my story: I've table with 2461566 rows here is my table structure: mysql> describe imp_log; +--------------+--------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------------------+----------------+ | sno | bigint(10) | | PRI | NULL | auto_increment | | advt_id | varchar(20) | | | | | | timestamp | datetime | | MUL | 0000-00-00 00:00:00 | | | hostname | varchar(120) | | | | | | remoteip | varchar(15) | | | | | | username | varchar(20) | | MUL | | | | camp_id | varchar(8) | | MUL | | | | browser_os | varchar(100) | | | | | | impressions | int(11) | | | 0 | | | cookiestring | varchar(128) | | MUL | | | | status | char(1) | | | N | | +--------------+--------------+------+-----+---------------------+----------------+ the problem is I want to sum the impressions from advt_id number 17 (this advt_id has 855517 records on imp_log table).. I want to sum the impressions..here is my query: select sum(impressions) impr from imp_log where camp_id='17'; but it took 5 minutes for me to do the query... but if I use count(impressions) it only tooks under 10 sec How to optimize the query ? the strange things is MySQL only uses a little of cpu time when I did sum() functions...Can I force MySQL to use all the cpu time ? I uses Linux Mandrake 7.0 with MySQL 4.0.0 alpha-max-log here is the MySQL variables... +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Variable_name | Value | +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | back_log | 50 | | basedir | / | | bdb_cache_size | 8388600 | | bdb_log_buffer_size | 32768 | | bdb_home | /var/lib/mysql/ | | bdb_max_lock | 10000 | | bdb_logdir | | | bdb_shared_data | OFF | | bdb_tmpdir | /data/ads/ | | bdb_version | Sleepycat Software: Berkeley DB 3.2.9a: (October 10, 2001) | | binlog_cache_size | 32768 | | character_set | latin1 | | character_sets | latin1 big5 czech euc_kr gb2312 gbk latin1_de sjis tis620 ujis dec8 dos german1 hp8 koi8_ru latin2 swe7 usa7 cp1251 danish hebrew win1251 estonia hungarian koi8_ukr win1251ukr greek win1250 croat cp1257 latin5 | | concurrent_insert | ON | | connect_timeout | 5 | | datadir | /var/lib/mysql/ | | delay_key_write | ON | | delayed_insert_limit | 100 | | delayed_insert_timeout | 300 | | delayed_queue_size | 1000 | | flush | OFF | | flush_time | 0 | | ft_min_word_len | 4 | | ft_max_word_len | 254 | | ft_max_word_len_for_sort | 20 | | have_bdb | YES | | have_innodb | YES | | have_isam | YES | | have_raid | NO | | have_symlink | YES | | have_openssl | NO | | init_file | | | innodb_data_file_path | ibdata1:64M | | innodb_data_home_dir | | | innodb_flush_log_at_trx_commit | OFF | | innodb_log_arch_dir | | | innodb_log_archive | OFF | | innodb_log_group_home_dir | /var/lib/mysql/ | | innodb_flush_method | | | interactive_timeout | 28800 | | join_buffer_size | 131072 | | key_buffer_size | 16773120 | | language | /usr/share/mysql/english/ | | large_files_support | ON | | locked_in_memory | OFF | | log | ON | | log_update | OFF | | log_bin | OFF | | log_slave_updates | OFF | | log_long_queries | OFF | | long_query_time | 10 | | low_priority_updates | OFF | | lower_case_table_names | 0 | | max_allowed_packet | 1047552 | | max_binlog_cache_size | 4294967295 | | max_binlog_size | 1073741824 | | max_connections | 100 | | max_connect_errors | 10 | | max_delayed_threads | 20 | | max_heap_table_size | 16777216 | | max_join_size | 4294967295 | | max_sort_length | 1024 | | max_user_connections | 0 | | max_tmp_tables | 32 | | max_write_lock_count | 4294967295 | | myisam_bulk_insert_tree_size | 8388608 | | myisam_max_extra_sort_file_size | 256 | | myisam_max_sort_file_size | 2047 | | myisam_recover_options | OFF | | myisam_sort_buffer_size | 8388608 | | net_buffer_length | 16384 | | net_read_timeout | 30 | | net_retry_count | 10 | | net_write_timeout | 60 | | open_files_limit | 0 | | pid_file | /var/lib/mysql/hercules.pid | | port | 3306 | | protocol_version | 10 | | record_buffer | 131072 | | record_rnd_buffer | 131072 | | rpl_recovery_rank | 0 | | query_buffer_size | 0 | | safe_show_database | OFF | | server_id | 0 | | slave_net_timeout | 3600 | | skip_locking | ON | | skip_networking | OFF | | skip_show_database | OFF | | slow_launch_time | 2 | | socket | /var/lib/mysql/mysql.sock | | sort_buffer | 2097144 | | sql_mode | 0 | | table_cache | 64 | | table_type | MYISAM | | thread_cache_size | 0 | | thread_stack | 131072 | | transaction_isolation | READ-COMMITTED | | timezone | JAVT | | tmp_table_size | 33554432 | | tmpdir | /data/ads/ | | version | 4.0.0-alpha-Max-log | | wait_timeout | 28800 | +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 102 rows in set (0.03 sec)
Can I more optimize the query ? I already try to use indexing..but the query still slow.. Any help, comments, critics would be very appreciated best regards, Bajingan _________________________________________________________________ Chat with friends online, try MSN Messenger: http://messenger.msn.com --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php