视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
MySQL中文件排序中单双路排序
2020-11-09 10:51:23 责编:小采
文档


在执行相关的SQL语句中,在mysql里进程容易出现一些file temp类似的字眼,该字眼告诉我们我们的宿主sql采用了文件排序等操作,这

在执行相关的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. */
error = row_merge_build_indexes(prebuilt->trx,
prebuilt->table, indexed_table,
index, num_of_idx, table); ----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);---row0merge.c文件中的,merge算法中排序的指定

下载本文
显示全文
专题