在執行相關的SQL語句中,在mysql裡進程容易出現一些file temp類似的字眼,該字眼告訴我們我們的宿主sql採用了檔案排序等操作,這可能會極大的影響我們的需要擷取結果集的效率問題。
mysql中有2中檔案排序演算法:單路排序和雙路排序;他們的區別於MYSQL中的max_length_for_sort_date具有相關性;單路演算法的排序可以為排序中的每一行建立固定的緩衝區;如果庫中出現超大字串的時候,比如;BLOB,TEXT等可以採用首碼排序的演算法,但是其值不能超過參數規定的值大小,在生產環境下,建議採用更多的是單路的排序演算法,他可以使磁碟的讀寫效率更高,sort_merge_passes的值會加大等!以下是相關innodb中給出的提示;
ut_ad(error == DB_SUCCESS);
/* Commit the data dictionary transaction in order to release
the table locks on the system tables. This means that if
MySQL crashes while creating a new primary key inside
row_merge_build_indexes(), indexed_table will not be dropped
by trx_rollback_active(). It will have to be recovered or
dropped by the database administrator. */
trx_commit_for_mysql(trx);
row_mysql_unlock_data_dictionary(trx);
dict_locked = FALSE;
ut_a(trx->n_active_thrs == 0);
ut_a(UT_LIST_GET_LEN(trx->signals) == 0);
if (UNIV_UNLIKELY(new_primary)) {
/* A primary key is to be built. Acquire an exclusive
table lock also on the table that is being created. */
ut_ad(indexed_table != prebuilt->table);
error = row_merge_lock_table(prebuilt->trx, indexed_table,
LOCK_X);
if (UNIV_UNLIKELY(error != DB_SUCCESS)) {
goto error_handling;
}
}
/* Read the clustered index of the table and build indexes
based on this information using temporary files and merge sort</span>. */
error = row_merge_build_indexes(prebuilt->trx,
prebuilt->table, indexed_table,
index, num_of_idx, table); <span style="color: rgb(51, 102, 255);">----handler0alter.cc指定控制代碼操作過程中檔案排序帶來的merge的操作
for (i = 0; i < n_index; i++) {
row_merge_buf_t* buf = merge_buf[i];
merge_file_t* file = &files[i];
const dict_index_t* index = buf->index;
if (UNIV_LIKELY
(row && row_merge_buf_add(buf, row, ext))) {
file->n_rec++;
continue;
}
/* The buffer must be sufficiently large
to hold at least one record. */
ut_ad(buf->n_tuples || !has_next);
/* We have enough data tuples to form a block.
Sort them and write to disk. */
if (buf->n_tuples) {
if (dict_index_is_unique(index)) {
row_merge_dup_t dup;
dup.index = buf->index;
dup.table = table;
dup.n_dup = 0;
row_merge_buf_sort(buf, &dup);<span style="color: rgb(51, 102, 255);">---row0merge.c檔案中的,merge演算法中排序的指定