Commit d33e525a authored by marko's avatar marko

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.
parent 43382b1a
...@@ -52,35 +52,6 @@ struct merge_block_struct { ...@@ -52,35 +52,6 @@ struct merge_block_struct {
typedef struct merge_block_struct merge_block_t; 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 /* Information about temporary files used in merge sort are stored
to this structure */ to this structure */
...@@ -138,7 +109,7 @@ row_merge_read_clustered_index( ...@@ -138,7 +109,7 @@ row_merge_read_clustered_index(
trx_t* trx, /* in: transaction */ trx_t* trx, /* in: transaction */
dict_table_t* table, /* in: table where index is created */ dict_table_t* table, /* in: table where index is created */
dict_index_t** index, /* in: indexes to be 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 */ entries */
ulint num_of_idx); /* in: number of indexes to be ulint num_of_idx); /* in: number of indexes to be
created */ created */
...@@ -170,30 +141,12 @@ row_merge_sort_linked_list_in_disk( ...@@ -170,30 +141,12 @@ row_merge_sort_linked_list_in_disk(
int* error); /* out: 0 or error */ int* error); /* out: 0 or error */
/************************************************************************* /*************************************************************************
Allocate and initialize memory for a merge file structure */ 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 */
void
row_merge_file_create(
/*==================*/
merge_file_t* merge_file); /* out: merge file structure */
/************************************************************************* /*************************************************************************
Remove a index from system tables */ Remove a index from system tables */
...@@ -288,8 +241,7 @@ row_merge_is_index_usable( ...@@ -288,8 +241,7 @@ row_merge_is_index_usable(
/* out: TRUE if index can be used by /* out: TRUE if index can be used by
the transaction else FALSE*/ the transaction else FALSE*/
const trx_t* trx, /* in: transaction */ const trx_t* trx, /* in: transaction */
const dict_index_t* /* in: index to check */ const dict_index_t* index); /* in: index to check */
index);
/************************************************************************* /*************************************************************************
If there are views that refer to the old table name then we "attach" to 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.*/ the new instance of the table else we drop it immediately.*/
...@@ -302,4 +254,3 @@ row_merge_drop_table( ...@@ -302,4 +254,3 @@ row_merge_drop_table(
trx_t* trx, /* in: transaction */ trx_t* trx, /* in: transaction */
dict_table_t* table); /* in: table instance to drop */ dict_table_t* table); /* in: table instance to drop */
#endif /* row0merge.h */ #endif /* row0merge.h */
...@@ -56,6 +56,35 @@ Created 12/4/2005 Jan Lindstrom ...@@ -56,6 +56,35 @@ Created 12/4/2005 Jan Lindstrom
#include "mem0mem.h" #include "mem0mem.h"
#include "log0log.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 static
dict_index_t* dict_index_t*
row_merge_dict_table_get_index( row_merge_dict_table_get_index(
...@@ -1394,7 +1423,7 @@ row_merge_read_clustered_index( ...@@ -1394,7 +1423,7 @@ row_merge_read_clustered_index(
trx_t* trx, /* in: transaction */ trx_t* trx, /* in: transaction */
dict_table_t* table, /* in: table where index is created */ dict_table_t* table, /* in: table where index is created */
dict_index_t** index, /* in: indexes to be 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 */ entries */
ulint num_of_idx) /* in: number of indexes to be ulint num_of_idx) /* in: number of indexes to be
created */ created */
...@@ -1521,7 +1550,7 @@ row_merge_read_clustered_index( ...@@ -1521,7 +1550,7 @@ row_merge_read_clustered_index(
if (!row_merge_sort_and_store( if (!row_merge_sort_and_store(
index[idx_num], index[idx_num],
files[idx_num], &files[idx_num],
block, block,
&(merge_list[idx_num]))) { &(merge_list[idx_num]))) {
...@@ -1531,7 +1560,7 @@ row_merge_read_clustered_index( ...@@ -1531,7 +1560,7 @@ row_merge_read_clustered_index(
} }
n_blocks++; n_blocks++;
files[idx_num]->num_of_blocks++; files[idx_num].num_of_blocks++;
} }
} }
...@@ -1573,14 +1602,14 @@ row_merge_read_clustered_index( ...@@ -1573,14 +1602,14 @@ row_merge_read_clustered_index(
behind this one. This will create a behind this one. This will create a
'linked list' of blocks to the disk. */ '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( 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( if (!row_merge_sort_and_store(
index[idx_num], index[idx_num],
files[idx_num], &files[idx_num],
block, block,
&(merge_list[idx_num]))) { &(merge_list[idx_num]))) {
...@@ -1589,7 +1618,7 @@ row_merge_read_clustered_index( ...@@ -1589,7 +1618,7 @@ row_merge_read_clustered_index(
goto error_handling; goto error_handling;
} }
files[idx_num]->num_of_blocks++; files[idx_num].num_of_blocks++;
n_blocks++; n_blocks++;
} }
...@@ -1600,7 +1629,7 @@ row_merge_read_clustered_index( ...@@ -1600,7 +1629,7 @@ row_merge_read_clustered_index(
header->next = ut_dulint_create(0, 0); header->next = ut_dulint_create(0, 0);
row_merge_block_header_write( row_merge_block_header_write(
files[idx_num]->file, header, header->offset); files[idx_num].file, header, header->offset);
} }
#ifdef UNIV_DEBUG_INDEX_CREATE #ifdef UNIV_DEBUG_INDEX_CREATE
...@@ -1880,24 +1909,15 @@ row_merge_remove_index( ...@@ -1880,24 +1909,15 @@ row_merge_remove_index(
/************************************************************************* /*************************************************************************
Allocate and initialize memory for a merge file structure */ Allocate and initialize memory for a merge file structure */
merge_file_t* void
row_merge_create_file_structure( row_merge_file_create(
/*============================*/ /*==================*/
/* out: pointer to merge file merge_file_t* merge_file) /* out: merge file structure */
structure */
mem_heap_t* heap) /* in: heap where merge file structure
is allocated */
{ {
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->file = innobase_mysql_tmpfile();
merge_file->offset = ut_dulint_create(0, 0); merge_file->offset = ut_dulint_create(0, 0);
merge_file->num_of_blocks = 0; merge_file->num_of_blocks = 0;
return(merge_file);
} }
#ifdef UNIV_DEBUG_INDEX_CREATE #ifdef UNIV_DEBUG_INDEX_CREATE
...@@ -2184,8 +2204,7 @@ ibool ...@@ -2184,8 +2204,7 @@ ibool
row_merge_is_index_usable( row_merge_is_index_usable(
/*======================*/ /*======================*/
const trx_t* trx, /* in: transaction */ const trx_t* trx, /* in: transaction */
const dict_index_t* /* in: index to check */ const dict_index_t* index) /* in: index to check */
index)
{ {
if (!trx->read_view) { if (!trx->read_view) {
return(TRUE); return(TRUE);
......
...@@ -4485,8 +4485,7 @@ row_build_index_for_mysql( ...@@ -4485,8 +4485,7 @@ row_build_index_for_mysql(
ulint num_of_keys) /* in: Number of indexes to be ulint num_of_keys) /* in: Number of indexes to be
created */ created */
{ {
merge_file_t** merge_files; merge_file_t* merge_files;
mem_heap_t* file_heap;
ulint index_num; ulint index_num;
ulint error = DB_SUCCESS; ulint error = DB_SUCCESS;
...@@ -4497,19 +4496,13 @@ row_build_index_for_mysql( ...@@ -4497,19 +4496,13 @@ row_build_index_for_mysql(
/* Allocate memory for merge file data structure and initialize /* Allocate memory for merge file data structure and initialize
fields */ fields */
file_heap = mem_heap_create( merge_files = mem_alloc(num_of_keys * sizeof *merge_files);
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*));
for (index_num = 0; index_num < num_of_keys; index_num++) { for (index_num = 0; index_num < num_of_keys; index_num++) {
merge_files[index_num] = row_merge_file_create(&merge_files[index_num]);
row_merge_create_file_structure(file_heap);
} }
/* Read clustered index of the table and create files for /* Read clustered index of the table and create files for
secondary index entries for merge sort */ secondary index entries for merge sort */
...@@ -4531,7 +4524,7 @@ row_build_index_for_mysql( ...@@ -4531,7 +4524,7 @@ row_build_index_for_mysql(
/* Do a merge sort and insert from those files /* Do a merge sort and insert from those files
which we have written at least one block */ 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); dulint offset = ut_dulint_create(0, 0);
/* Merge sort file using linked list merge /* Merge sort file using linked list merge
...@@ -4539,7 +4532,7 @@ row_build_index_for_mysql( ...@@ -4539,7 +4532,7 @@ row_build_index_for_mysql(
offset = row_merge_sort_linked_list_in_disk( offset = row_merge_sort_linked_list_in_disk(
index[index_num], index[index_num],
merge_files[index_num]->file, merge_files[index_num].file,
(int *)&error); (int *)&error);
if (error != DB_SUCCESS) { if (error != DB_SUCCESS) {
...@@ -4553,7 +4546,7 @@ row_build_index_for_mysql( ...@@ -4553,7 +4546,7 @@ row_build_index_for_mysql(
trx, trx,
index[index_num], index[index_num],
new_table, new_table,
merge_files[index_num]->file, merge_files[index_num].file,
ut_dulint_create(0,0)); ut_dulint_create(0,0));
if (error != DB_SUCCESS) { if (error != DB_SUCCESS) {
...@@ -4568,7 +4561,7 @@ row_build_index_for_mysql( ...@@ -4568,7 +4561,7 @@ row_build_index_for_mysql(
row_merge_mark_prebuilt_obsolete(trx, old_table); row_merge_mark_prebuilt_obsolete(trx, old_table);
} }
mem_heap_free(file_heap); mem_free(merge_files);
return(error); return(error);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment