sql - MySQL: Modifying a query based on EXPLAIN plan -


i have long running query i'd speed up. result of query new table.

the tables myisam , running on large ec2 instance (m2.4xlarge, 64gb ram).

system usage looks this:

pid user      pr  ni  virt  res  shr s %cpu %mem    time+  command                                                                                                             17438 mysql     20   0 32.7g 7.1g 7420 s    2 10.6   1:35.82 mysqld  

relevant portion of cnf:

key_buffer      = 32768m max_allowed_packet  = 96m thread_stack    = 192k thread_cache_size   = 8 sort_buffer_size    = 2m read_buffer_size    = 2m read_rnd_buffer_size = 8m   table_cache             = 512 thread_concurrency      = 8 bulk_insert_buffer_size = 2048m max_write_lock_count    = 1  # ~1/4 of memory of machine max_heap_table_size = 16384m  tmp_table_size      = 16384m  # ~1/4 of memory myisam_sort_buffer_size = 17179869184 

when run simple query, takes longer think should , memory , cpu usage on machine low.

the query explain plan looks this:

mysql> explain select encounter_id -> encounters e, sampled_patients sp -> e.patient_id = sp.patient_id; +----+-------------+-------+-------+---------------+------------+---------+--------------------+---------+-------------+ | id | select_type | table | type  | possible_keys | key        | key_len | ref                | rows    |       | +----+-------------+-------+-------+---------------+------------+---------+--------------------+---------+-------------+ |  1 | simple      | sp    | index | patient_id    | patient_id | 4       | null               | 1537954 | using index | |  1 | simple      | e     | ref   | patient_id    | patient_id | 5       | noah.sp.patient_id |       1 | using | +----+-------------+-------+-------+---------------+------------+---------+--------------------+---------+-------------+ 2 rows in set (0.00 sec) 

it has through ~1.5m rows, it's indexed. how can speed up?


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -