確定mysql中索引的狀態

[英]Determine status of an index in mysql


I created a new index on a table with 35million records and its been running for nearly 1 day now. Previously when I created indexes it took 20 minutes, there columns were however floats. The new idnex is on a varchar(45)

我在一張有3500萬條記錄的桌子上創建了一個新索引,現在已經運行了將近1天。以前當我創建索引需要花費20分鍾時,然而有些列是浮動的。新的idnex在varchar(45)上

I used the processlist command which shows the index creation is still in progress with the following output

我使用了processlist命令,該命令顯示索引創建仍在使用以下輸出

65417 | Repair with keycache | CREATE INDEX insert_index on checkins(dateinserted)

I was wondering if anyone could give me advice on finding out if the query is actually dead and is just sitting in the process list. Maybe something has gone wrong at some stage and I'm not aware.

我想知道是否有人可以給我建議,以查明查詢是否真的死了,只是坐在進程列表中。也許某些事情在某個階段出了問題,我不知道。

Thanks

2 个解决方案

#1


6  

Your index is building, but very slowly.

你的索引正在構建,但速度很慢。

MySQL has two methods available for building indexes:

MySQL有兩種可用於構建索引的方法:

  1. by sorting. This is the fastest method, but uses up a lot of memory.
  2. 通過排序。這是最快的方法,但占用了大量內存。

  3. by keycache. Slow, slow, slow - but uses up little memory.
  4. 通過keycache。緩慢,緩慢,緩慢 - 但耗盡了很少的記憶。

The keycache method is a bit like insertion sort: values are inserted into the index one at a time. This is the same method used by the server when the INSERT statement is used to add rows to the table.

keycache方法有點像插入排序:一次將值插入索引中。這與使用INSERT語句向表中添加行時服務器使用的方法相同。

The sorting method sorts all the values using quicksort, and then builds the index from that. It is very fast, but requires a lot of memory and temporary disk space.

排序方法使用quicksort對所有值進行排序,然后從中構建索引。它非常快,但需要大量內存和臨時磁盤空間。

Some server variables can increase the space available to the sorting method, and so allow it to work with larger tables. See myisam_max_sort_file_size

某些服務器變量可以增加排序方法的可用空間,因此允許它使用更大的表。請參閱myisam_max_sort_file_size

http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_myisam_max_sort_file_size

On Linux, you can track the progress of the index repair by checking the size of the temporary files that are used to build the index. The following command will list all the files held open by the MySQL process:

在Linux上,您可以通過檢查用於構建索引的臨時文件的大小來跟蹤索引修復的進度。以下命令將列出MySQL進程保持打開的所有文件:

sudo ls -l /proc/[mysql-pid]/fd  

Then check out the size of ones with hashes in their name - these are the temporary files.

然后查看名稱中帶有哈希值的大小 - 這些是臨時文件。

#2


2  

Keep in mind the index size will be 35M*45 at least. If it's a utf8 column then it will be 35M*45*3. That's over 4 gigs! If you don't have tons of RAM to support that it's going to have to do a lot of disk access and really kill performance.

請記住,索引大小至少為35M * 45。如果它是一個utf8列,那么它將是35M * 45 * 3。那是超過4場演出!如果你沒有大量的RAM來支持它,它將不得不進行大量的磁盤訪問並且真的會破壞性能。

Can you normalize this column out into another table?

你可以將這個列標准化為另一個表嗎?

If not do the values tend to vary sufficiently in say the first 8 characters? You might be able to get away with just indexing the first 8 then.

如果沒有,那么這些值往往會在前8個字符中變化很大?你可能可以通過索引前8個而逃脫。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/10/03/4f508c4e754459884f50b9aa41d01a27.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com