mirror of
https://github.com/MariaDB/server.git
synced 2025-02-01 03:21:53 +01:00
branches/zip: Initial clean up of the merge sort subsystem.
Define the merge_rec_ structures in row0merge.c instead of row0merge.h. They are not used in the interface defined in row0merge.h. row_merge_create_file_structure(): Rename to row_merge_file_create(). Input a pointer to a pre-allocated block of memory. row_merge_read_clustered_index(): Replace merge_file_t** with merge_file_t*. row_merge_sort_and_insert_thread(): Remove the declaration. This function was never defined or called. row_merge_is_index_usable(): Correct the formatting. row_build_index_for_mysql(): Allocate an array of merge_file_t instead of an array of pointers to merge_file_t.
This commit is contained in:
parent
7e9e884fe9
commit
fcfed19818
3 changed files with 58 additions and 95 deletions
|
@ -52,35 +52,6 @@ struct merge_block_struct {
|
|||
|
||||
typedef struct merge_block_struct merge_block_t;
|
||||
|
||||
/* Records are stored in the memory for main memory linked list
|
||||
to this structure */
|
||||
|
||||
struct merge_rec_struct {
|
||||
struct merge_rec_struct *next; /* Pointer to next record
|
||||
in the list */
|
||||
rec_t* rec; /* Record */
|
||||
};
|
||||
|
||||
typedef struct merge_rec_struct merge_rec_t;
|
||||
|
||||
/* This structure is head element for main memory linked list
|
||||
used for main memory linked list merge sort */
|
||||
|
||||
struct merge_rec_list_struct {
|
||||
merge_rec_t* head; /* Pointer to head of the
|
||||
list */
|
||||
merge_rec_t* tail; /* Pointer to tail of the
|
||||
list */
|
||||
ulint n_records; /* Number of records in
|
||||
the list */
|
||||
ulint total_size; /* Total size of all records in
|
||||
the list */
|
||||
mem_heap_t* heap; /* Heap where memory for this
|
||||
list is allocated */
|
||||
};
|
||||
|
||||
typedef struct merge_rec_list_struct merge_rec_list_t;
|
||||
|
||||
/* Information about temporary files used in merge sort are stored
|
||||
to this structure */
|
||||
|
||||
|
@ -138,7 +109,7 @@ row_merge_read_clustered_index(
|
|||
trx_t* trx, /* in: transaction */
|
||||
dict_table_t* table, /* in: table where index is created */
|
||||
dict_index_t** index, /* in: indexes to be created */
|
||||
merge_file_t** files, /* in: Files where to write index
|
||||
merge_file_t* files, /* in: Files where to write index
|
||||
entries */
|
||||
ulint num_of_idx); /* in: number of indexes to be
|
||||
created */
|
||||
|
@ -170,30 +141,12 @@ row_merge_sort_linked_list_in_disk(
|
|||
int* error); /* out: 0 or error */
|
||||
|
||||
/*************************************************************************
|
||||
Allocate and initialize memory for a merge file structure */
|
||||
|
||||
merge_file_t*
|
||||
row_merge_create_file_structure(
|
||||
/*============================*/
|
||||
/* out: pointer to merge file
|
||||
structure */
|
||||
mem_heap_t* heap); /* in: heap where merge file structure
|
||||
is allocated */
|
||||
/*************************************************************************
|
||||
A thread which merge sorts given file and inserts sorted records to
|
||||
the index. */
|
||||
|
||||
#ifndef __WIN__
|
||||
void *
|
||||
#else
|
||||
ulint
|
||||
#endif
|
||||
row_merge_sort_and_insert_thread(
|
||||
/*=============================*/
|
||||
/* out: a dummy parameter */
|
||||
void* arg); /* in: parameters */
|
||||
|
||||
Initialize memory for a merge file structure */
|
||||
|
||||
void
|
||||
row_merge_file_create(
|
||||
/*==================*/
|
||||
merge_file_t* merge_file); /* out: merge file structure */
|
||||
/*************************************************************************
|
||||
Remove a index from system tables */
|
||||
|
||||
|
@ -287,9 +240,8 @@ row_merge_is_index_usable(
|
|||
/*======================*/
|
||||
/* out: TRUE if index can be used by
|
||||
the transaction else FALSE*/
|
||||
const trx_t* trx, /* in: transaction */
|
||||
const dict_index_t* /* in: index to check */
|
||||
index);
|
||||
const trx_t* trx, /* in: transaction */
|
||||
const dict_index_t* index); /* in: index to check */
|
||||
/*************************************************************************
|
||||
If there are views that refer to the old table name then we "attach" to
|
||||
the new instance of the table else we drop it immediately.*/
|
||||
|
@ -302,4 +254,3 @@ row_merge_drop_table(
|
|||
trx_t* trx, /* in: transaction */
|
||||
dict_table_t* table); /* in: table instance to drop */
|
||||
#endif /* row0merge.h */
|
||||
|
||||
|
|
|
@ -56,6 +56,35 @@ TODO:
|
|||
#include "mem0mem.h"
|
||||
#include "log0log.h"
|
||||
|
||||
/* Records are stored in the memory for main memory linked list
|
||||
to this structure */
|
||||
|
||||
struct merge_rec_struct {
|
||||
struct merge_rec_struct *next; /* Pointer to next record
|
||||
in the list */
|
||||
rec_t* rec; /* Record */
|
||||
};
|
||||
|
||||
typedef struct merge_rec_struct merge_rec_t;
|
||||
|
||||
/* This structure is head element for main memory linked list
|
||||
used for main memory linked list merge sort */
|
||||
|
||||
struct merge_rec_list_struct {
|
||||
merge_rec_t* head; /* Pointer to head of the
|
||||
list */
|
||||
merge_rec_t* tail; /* Pointer to tail of the
|
||||
list */
|
||||
ulint n_records; /* Number of records in
|
||||
the list */
|
||||
ulint total_size; /* Total size of all records in
|
||||
the list */
|
||||
mem_heap_t* heap; /* Heap where memory for this
|
||||
list is allocated */
|
||||
};
|
||||
|
||||
typedef struct merge_rec_list_struct merge_rec_list_t;
|
||||
|
||||
static
|
||||
dict_index_t*
|
||||
row_merge_dict_table_get_index(
|
||||
|
@ -1394,7 +1423,7 @@ row_merge_read_clustered_index(
|
|||
trx_t* trx, /* in: transaction */
|
||||
dict_table_t* table, /* in: table where index is created */
|
||||
dict_index_t** index, /* in: indexes to be created */
|
||||
merge_file_t** files, /* in: Files where to write index
|
||||
merge_file_t* files, /* in: Files where to write index
|
||||
entries */
|
||||
ulint num_of_idx) /* in: number of indexes to be
|
||||
created */
|
||||
|
@ -1521,7 +1550,7 @@ row_merge_read_clustered_index(
|
|||
|
||||
if (!row_merge_sort_and_store(
|
||||
index[idx_num],
|
||||
files[idx_num],
|
||||
&files[idx_num],
|
||||
block,
|
||||
&(merge_list[idx_num]))) {
|
||||
|
||||
|
@ -1531,7 +1560,7 @@ row_merge_read_clustered_index(
|
|||
}
|
||||
|
||||
n_blocks++;
|
||||
files[idx_num]->num_of_blocks++;
|
||||
files[idx_num].num_of_blocks++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1573,14 +1602,14 @@ next_record:
|
|||
behind this one. This will create a
|
||||
'linked list' of blocks to the disk. */
|
||||
|
||||
block->header.offset = files[idx_num]->offset;
|
||||
block->header.offset = files[idx_num].offset;
|
||||
|
||||
block->header.next= ut_dulint_add(
|
||||
files[idx_num]->offset, MERGE_BLOCK_SIZE);
|
||||
files[idx_num].offset, MERGE_BLOCK_SIZE);
|
||||
|
||||
if (!row_merge_sort_and_store(
|
||||
index[idx_num],
|
||||
files[idx_num],
|
||||
&files[idx_num],
|
||||
block,
|
||||
&(merge_list[idx_num]))) {
|
||||
|
||||
|
@ -1589,7 +1618,7 @@ next_record:
|
|||
goto error_handling;
|
||||
}
|
||||
|
||||
files[idx_num]->num_of_blocks++;
|
||||
files[idx_num].num_of_blocks++;
|
||||
n_blocks++;
|
||||
}
|
||||
|
||||
|
@ -1600,7 +1629,7 @@ next_record:
|
|||
header->next = ut_dulint_create(0, 0);
|
||||
|
||||
row_merge_block_header_write(
|
||||
files[idx_num]->file, header, header->offset);
|
||||
files[idx_num].file, header, header->offset);
|
||||
}
|
||||
|
||||
#ifdef UNIV_DEBUG_INDEX_CREATE
|
||||
|
@ -1880,24 +1909,15 @@ row_merge_remove_index(
|
|||
/*************************************************************************
|
||||
Allocate and initialize memory for a merge file structure */
|
||||
|
||||
merge_file_t*
|
||||
row_merge_create_file_structure(
|
||||
/*============================*/
|
||||
/* out: pointer to merge file
|
||||
structure */
|
||||
mem_heap_t* heap) /* in: heap where merge file structure
|
||||
is allocated */
|
||||
void
|
||||
row_merge_file_create(
|
||||
/*==================*/
|
||||
merge_file_t* merge_file) /* out: merge file structure */
|
||||
{
|
||||
merge_file_t* merge_file;
|
||||
|
||||
merge_file = (merge_file_t*) mem_heap_alloc(heap, sizeof(merge_file_t));
|
||||
|
||||
merge_file->file = innobase_mysql_tmpfile();
|
||||
|
||||
merge_file->offset = ut_dulint_create(0, 0);
|
||||
merge_file->num_of_blocks = 0;
|
||||
|
||||
return(merge_file);
|
||||
}
|
||||
|
||||
#ifdef UNIV_DEBUG_INDEX_CREATE
|
||||
|
@ -2183,9 +2203,8 @@ Check if a transaction can use an index.*/
|
|||
ibool
|
||||
row_merge_is_index_usable(
|
||||
/*======================*/
|
||||
const trx_t* trx, /* in: transaction */
|
||||
const dict_index_t* /* in: index to check */
|
||||
index)
|
||||
const trx_t* trx, /* in: transaction */
|
||||
const dict_index_t* index) /* in: index to check */
|
||||
{
|
||||
if (!trx->read_view) {
|
||||
return(TRUE);
|
||||
|
|
|
@ -4485,8 +4485,7 @@ row_build_index_for_mysql(
|
|||
ulint num_of_keys) /* in: Number of indexes to be
|
||||
created */
|
||||
{
|
||||
merge_file_t** merge_files;
|
||||
mem_heap_t* file_heap;
|
||||
merge_file_t* merge_files;
|
||||
ulint index_num;
|
||||
ulint error = DB_SUCCESS;
|
||||
|
||||
|
@ -4497,19 +4496,13 @@ row_build_index_for_mysql(
|
|||
/* Allocate memory for merge file data structure and initialize
|
||||
fields */
|
||||
|
||||
file_heap = mem_heap_create(
|
||||
num_of_keys * (sizeof(merge_file_t) + sizeof(merge_file_t*)));
|
||||
|
||||
merge_files = mem_heap_alloc(
|
||||
file_heap, num_of_keys * sizeof(merge_file_t*));
|
||||
merge_files = mem_alloc(num_of_keys * sizeof *merge_files);
|
||||
|
||||
for (index_num = 0; index_num < num_of_keys; index_num++) {
|
||||
|
||||
merge_files[index_num] =
|
||||
row_merge_create_file_structure(file_heap);
|
||||
row_merge_file_create(&merge_files[index_num]);
|
||||
}
|
||||
|
||||
|
||||
/* Read clustered index of the table and create files for
|
||||
secondary index entries for merge sort */
|
||||
|
||||
|
@ -4531,7 +4524,7 @@ row_build_index_for_mysql(
|
|||
/* Do a merge sort and insert from those files
|
||||
which we have written at least one block */
|
||||
|
||||
if (merge_files[index_num]->num_of_blocks > 0) {
|
||||
if (merge_files[index_num].num_of_blocks > 0) {
|
||||
dulint offset = ut_dulint_create(0, 0);
|
||||
|
||||
/* Merge sort file using linked list merge
|
||||
|
@ -4539,7 +4532,7 @@ row_build_index_for_mysql(
|
|||
|
||||
offset = row_merge_sort_linked_list_in_disk(
|
||||
index[index_num],
|
||||
merge_files[index_num]->file,
|
||||
merge_files[index_num].file,
|
||||
(int *)&error);
|
||||
|
||||
if (error != DB_SUCCESS) {
|
||||
|
@ -4553,7 +4546,7 @@ row_build_index_for_mysql(
|
|||
trx,
|
||||
index[index_num],
|
||||
new_table,
|
||||
merge_files[index_num]->file,
|
||||
merge_files[index_num].file,
|
||||
ut_dulint_create(0,0));
|
||||
|
||||
if (error != DB_SUCCESS) {
|
||||
|
@ -4568,7 +4561,7 @@ func_exit:
|
|||
row_merge_mark_prebuilt_obsolete(trx, old_table);
|
||||
}
|
||||
|
||||
mem_heap_free(file_heap);
|
||||
mem_free(merge_files);
|
||||
|
||||
return(error);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue