Commit 13817f1d authored by marko's avatar marko

branches/zip: Minor cleanup of merge_file_t and merge_block_header_t.

Replace byte offsets of type dulint with block offsets of type ulint.
Avoid references to MERGE_BLOCK_SIZE.

Improve the language of some comments.

row_merge_insert_index_tuples(), row_merge_sort_linked_list_in_disk():
Make the offset a ulint.

row_merge_read(), row_merge_write(): Helper functions.  Return the
status of os_file_read() and os_file_write().  TO DO: check the status
in the callers.
parent 96e90174
...@@ -26,7 +26,7 @@ to this structure */ ...@@ -26,7 +26,7 @@ to this structure */
struct merge_file_struct { struct merge_file_struct {
os_file_t file; /* File descriptor */ os_file_t file; /* File descriptor */
dulint offset; /* File offset */ ulint offset; /* File offset */
ulint num_of_blocks; /* Number of blocks */ ulint num_of_blocks; /* Number of blocks */
}; };
...@@ -81,16 +81,16 @@ row_merge_insert_index_tuples( ...@@ -81,16 +81,16 @@ row_merge_insert_index_tuples(
dict_index_t* index, /* in: index */ dict_index_t* index, /* in: index */
dict_table_t* table, /* in: table */ dict_table_t* table, /* in: table */
os_file_t file, /* in: file handle */ os_file_t file, /* in: file handle */
dulint offset); /* in: offset where to start ulint offset); /* in: offset where to start
reading */ reading */
/***************************************************************** /*****************************************************************
Merge sort for linked list in the disk. */ Merge sort for linked list in the disk. */
dulint ulint
row_merge_sort_linked_list_in_disk( row_merge_sort_linked_list_in_disk(
/*===============================*/ /*===============================*/
/* out: offset to first block in /* out: offset to first block in
the list or ut_dulint_max in the list or ULINT_UNDEFINED in
case of error */ case of error */
dict_index_t* index, /* in: index to be created */ dict_index_t* index, /* in: index to be created */
os_file_t file, /* in: File handle */ os_file_t file, /* in: File handle */
......
...@@ -100,8 +100,8 @@ blocks to the disk. Every block contains one header.*/ ...@@ -100,8 +100,8 @@ blocks to the disk. Every block contains one header.*/
struct merge_block_header_struct { struct merge_block_header_struct {
ulint n_records; /* Number of records in the block. */ ulint n_records; /* Number of records in the block. */
dulint offset; /* Offset of this block in the disk. */ ulint offset; /* Offset of this block */
dulint next; /* Offset to next block in the disk. */ ulint next; /* Offset of next block */
}; };
typedef struct merge_block_header_struct merge_block_header_t; typedef struct merge_block_header_struct merge_block_header_t;
...@@ -153,86 +153,118 @@ row_merge_block_create(void) ...@@ -153,86 +153,118 @@ row_merge_block_create(void)
{ {
merge_block_t* mblock; merge_block_t* mblock;
mblock = (merge_block_t*)mem_alloc(MERGE_BLOCK_SIZE); mblock = mem_alloc(sizeof *mblock);
mblock->header.n_records = 0; memset(&mblock->header, 0, sizeof mblock->header);
mblock->header.offset = ut_dulint_create(0, 0);
mblock->header.next = ut_dulint_create(0, 0);
return(mblock); return(mblock);
} }
/************************************************************************ /************************************************************************
Read a merge block from the disk */ Read a merge block from the file system. */
static static
void ibool
row_merge_read(
/*===========*/
/* out: TRUE if request was
successful, FALSE if fail */
os_file_t file, /* in: file handle */
ulint offset, /* in: offset where to read */
void* buf, /* out: data */
ulint size) /* in: number of bytes to read */
{
ib_uint64_t ofs = ((ib_uint64_t) offset) * MERGE_BLOCK_SIZE;
ut_ad(size <= MERGE_BLOCK_SIZE);
return(os_file_read(file, buf,
(ulint) (ofs & 0xFFFFFFFF),
(ulint) (ofs >> 32),
size));
}
/************************************************************************
Read a merge block from the file system. */
static
ibool
row_merge_block_read( row_merge_block_read(
/*=================*/ /*=================*/
/* out: TRUE if request was /* out: TRUE if request was
successful, FALSE if fail */ successful, FALSE if fail */
os_file_t file, /* in: handle to a file */ os_file_t file, /* in: file handle */
void* buf, /* in/out: buffer where to read */ ulint offset, /* in: offset where to read */
dulint offset) /* in: offset where to read */ merge_block_t* block) /* out: merge block */
{ {
ut_ad(buf); return(row_merge_read(file, offset, block, sizeof *block));
os_file_read(file, buf, ut_dulint_get_low(offset),
ut_dulint_get_high(offset), MERGE_BLOCK_SIZE);
} }
/************************************************************************ /************************************************************************
Read a merge block header from the disk */ Read a merge block header from the disk */
static static
void ibool
row_merge_block_header_read( row_merge_block_header_read(
/*========================*/ /*========================*/
/* out: TRUE if request was /* out: TRUE if request was
successful, FALSE if fail */ successful, FALSE if fail */
os_file_t file, /* in: handle to a file */ os_file_t file, /* in: handle to a file */
merge_block_header_t* header, /* in/out: buffer where to read */ ulint offset, /* in: offset where to read */
dulint offset) /* in: offset where to read */ merge_block_header_t* header) /* out: merge block header */
{ {
ut_ad(header); return(row_merge_read(file, offset, header, sizeof *header));
}
os_file_read(file, header, ut_dulint_get_low(offset), /************************************************************************
ut_dulint_get_high(offset), Read a merge block from the file system. */
sizeof(merge_block_header_t)); static
ibool
row_merge_write(
/*============*/
/* out: TRUE if request was
successful, FALSE if fail */
os_file_t file, /* in: file handle */
ulint offset, /* in: offset where to write */
const void* buf, /* in: data */
ulint size) /* in: number of bytes to write */
{
ib_uint64_t ofs = ((ib_uint64_t) offset) * MERGE_BLOCK_SIZE;
ut_ad(size <= MERGE_BLOCK_SIZE);
return(os_file_write("(merge)", file, buf,
(ulint) (ofs & 0xFFFFFFFF),
(ulint) (ofs >> 32),
size));
} }
/************************************************************************ /************************************************************************
Write a merge block header to the disk */ Write a merge block header to the disk */
static static
void ibool
row_merge_block_header_write( row_merge_block_header_write(
/*=========================*/ /*=========================*/
/* out: TRUE if request was /* out: TRUE if request was
successful, FALSE if fail */ successful, FALSE if fail */
os_file_t file, /* in: handle to a file */ os_file_t file, /* in: handle to a file */
merge_block_header_t* header, /* in/out: buffer where to read */ const merge_block_header_t* header) /* in: block header */
dulint offset) /* in: offset where to read */
{ {
ut_ad(header); return(row_merge_write(file, header->offset, header, sizeof *header));
os_file_write("(merge)", file, header, ut_dulint_get_low(offset),
ut_dulint_get_high(offset), sizeof(merge_block_header_t));
} }
/************************************************************************ /************************************************************************
Write a merge block to the disk */ Write a merge block to the disk */
static static
void ibool
row_merge_block_write( row_merge_block_write(
/*==================*/ /*==================*/
/* out: TRUE if request was /* out: TRUE if request was
successful, FALSE if fail */ successful, FALSE if fail */
os_file_t file, /* in: handle to a file */ os_file_t file, /* in: handle to a file */
void* buf, /* in: buffer where write from */ ulint offset, /* in: file offset */
dulint offset) /* in: offset where write to */ const merge_block_t* block) /* in: block header */
{ {
ut_ad(buf); ut_ad(offset == block->header.offset);
os_file_write("(merge)", file, buf, ut_dulint_get_low(offset), return(row_merge_write(file, offset, block, sizeof *block));
ut_dulint_get_high(offset), MERGE_BLOCK_SIZE);
} }
/************************************************************** /**************************************************************
...@@ -328,7 +360,7 @@ row_merge_store_rec_to_block( ...@@ -328,7 +360,7 @@ row_merge_store_rec_to_block(
dest_data = ((char *)mblock + offset); dest_data = ((char *)mblock + offset);
} }
ut_ad(dest_data < ((char *)mblock + MERGE_BLOCK_SIZE)); ut_ad(dest_data < (char*) &mblock[1]);
extra_len = rec_offs_extra_size(offsets); extra_len = rec_offs_extra_size(offsets);
rec_len = rec_offs_size(offsets); rec_len = rec_offs_size(offsets);
...@@ -336,12 +368,12 @@ row_merge_store_rec_to_block( ...@@ -336,12 +368,12 @@ row_merge_store_rec_to_block(
/* 1. Store the extra_len */ /* 1. Store the extra_len */
storage_size = mach_write_compressed((byte *)dest_data, extra_len); storage_size = mach_write_compressed((byte *)dest_data, extra_len);
dest_data+=storage_size; dest_data+=storage_size;
ut_ad(dest_data < ((char *)mblock + MERGE_BLOCK_SIZE)); ut_ad(dest_data < (char*) &mblock[1]);
/* 2. Store the record */ /* 2. Store the record */
memcpy(dest_data, rec - extra_len, rec_len); memcpy(dest_data, rec - extra_len, rec_len);
dest_data+=rec_len; dest_data+=rec_len;
ut_ad(dest_data < ((char *)mblock + MERGE_BLOCK_SIZE)); ut_ad(dest_data < (char*) &mblock[1]);
mblock->header.n_records++; mblock->header.n_records++;
...@@ -389,7 +421,7 @@ row_merge_read_rec_from_block( ...@@ -389,7 +421,7 @@ row_merge_read_rec_from_block(
from_data = ((char *)mblock + tmp_offset); from_data = ((char *)mblock + tmp_offset);
} }
ut_ad(from_data < ((char *)mblock + MERGE_BLOCK_SIZE)); ut_ad(from_data < (const char*) &mblock[1]);
mrec = mem_heap_alloc(heap, sizeof(merge_rec_t)); mrec = mem_heap_alloc(heap, sizeof(merge_rec_t));
...@@ -397,7 +429,7 @@ row_merge_read_rec_from_block( ...@@ -397,7 +429,7 @@ row_merge_read_rec_from_block(
extra_len = mach_read_compressed((byte *)from_data); extra_len = mach_read_compressed((byte *)from_data);
storage_len = mach_get_compressed_size(extra_len); storage_len = mach_get_compressed_size(extra_len);
from_data+=storage_len; from_data+=storage_len;
ut_ad(from_data < ((char *)mblock + MERGE_BLOCK_SIZE)); ut_ad(from_data < (const char*) &mblock[1]);
/* 2. Read the record */ /* 2. Read the record */
rec = (rec_t*)(from_data + extra_len); rec = (rec_t*)(from_data + extra_len);
...@@ -408,7 +440,7 @@ row_merge_read_rec_from_block( ...@@ -408,7 +440,7 @@ row_merge_read_rec_from_block(
ut_ad(rec_validate(rec, sec_offs)); ut_ad(rec_validate(rec, sec_offs));
from_data+=data_len; from_data+=data_len;
ut_ad(from_data < ((char *)mblock + MERGE_BLOCK_SIZE)); ut_ad(from_data < (const char*) &mblock[1]);
/* Return also start offset of the next data tuple */ /* Return also start offset of the next data tuple */
*offset = ((char *)from_data - (char *)mblock); *offset = ((char *)from_data - (char *)mblock);
...@@ -480,7 +512,7 @@ pass is needed the whole output list must be sorted. ...@@ -480,7 +512,7 @@ pass is needed the whole output list must be sorted.
In each pass, two lists of size block_size are merged into lists of In each pass, two lists of size block_size are merged into lists of
size block_size*2. Initially block_size=1. Merge starts by pointing size block_size*2. Initially block_size=1. Merge starts by pointing
a temporary pointer list1 at the head of the list and also preparing a temporary pointer list1 at the head of the list and also preparing
an empty list list_tail which we will add elements to the end. Then: an empty list list_tail where elements will be appended. Then:
1) If list1 is NULL we terminate this pass. 1) If list1 is NULL we terminate this pass.
...@@ -510,7 +542,7 @@ an empty list list_tail which we will add elements to the end. Then: ...@@ -510,7 +542,7 @@ an empty list list_tail which we will add elements to the end. Then:
lists, by advancing list1 or list2 to next element lists, by advancing list1 or list2 to next element
and decreasing list1_size or list2_size. and decreasing list1_size or list2_size.
5.3) Add tmp to the end of the list_tail 5.3) Append tmp to list_tail
6) At this point, we have advanced list1 until it is where 6) At this point, we have advanced list1 until it is where
list2 started out and we have advanced list2 until it is list2 started out and we have advanced list2 until it is
...@@ -837,12 +869,9 @@ row_merge_block_validate( ...@@ -837,12 +869,9 @@ row_merge_block_validate(
fprintf(stderr, fprintf(stderr,
"Block validate %lu records, " "Block validate %lu records, "
"offset (%lu %lu), next (%lu %lu)\n", "offset %lu, next %lu\n",
block->header.n_records, block->header.n_records,
ut_dulint_get_low(block->header.offset), block->header.offset, block->header.next);
ut_dulint_get_high(block->header.offset),
ut_dulint_get_low(block->header.next),
ut_dulint_get_high(block->header.next));
ut_a(block->header.n_records > 0); ut_a(block->header.n_records > 0);
...@@ -914,10 +943,8 @@ row_merge_block_merge( ...@@ -914,10 +943,8 @@ row_merge_block_merge(
/* Copy block offset and next block offset to new blocks */ /* Copy block offset and next block offset to new blocks */
new_block1->header.offset = block1->header.offset; new_block1->header = block1->header;
new_block1->header.next = block1->header.next; new_block2->header = tmp->header;
new_block2->header.offset = tmp->header.offset;
new_block2->header.next = tmp->header.next;
/* Merge all records from both blocks */ /* Merge all records from both blocks */
...@@ -1040,7 +1067,7 @@ row_merge_block_merge( ...@@ -1040,7 +1067,7 @@ row_merge_block_merge(
some cases these keys do not fit to two empty blocks some cases these keys do not fit to two empty blocks
in a different order. Therefore, some empty space is in a different order. Therefore, some empty space is
left to every block. However, it has not been prooven left to every block. However, it has not been prooven
that this empty space is enought in all cases. Therefore, that this empty space is enough in all cases. Therefore,
here these overloaded records should be put on another here these overloaded records should be put on another
block. */ block. */
} }
...@@ -1087,18 +1114,17 @@ the list and in each pass it combines each adjacent pair of ...@@ -1087,18 +1114,17 @@ the list and in each pass it combines each adjacent pair of
small sorted lists into one larger sorted list. When only a one small sorted lists into one larger sorted list. When only a one
pass is needed the whole output list must be sorted. pass is needed the whole output list must be sorted.
Linked list resides at the disk where every block represents a The linked list is stored in the file system. File blocks represent
item in the linked list and these items are single linked together items of linked list. The list is singly linked by the next offset
with next offset found from block header. Offset is calculated stored in block header. Offset is calculated from the start of the
from the start of the file. Thus whenever next item in the list file. Thus whenever next item in the list is requested this item is
is requested this item is read from the disk. Similarly every read from the disk. Similarly every item is witten back to the disk
item is witten back to the disk when we have sorted two blocks when we have sorted two blocks in the memory.
in the memory.
In each pass, two lists of size block_size are merged into lists of In each pass, two lists of size block_size are merged into lists of
size block_size*2. Initially block_size=1. Merge starts by pointing size block_size*2. Initially block_size=1. Merge starts by pointing
a temporary pointer list1 at the head of the list and also preparing a temporary pointer list1 at the head of the list and also preparing
an empty list list_tail which we will add elements to the end. Then: an empty list list_tail where elements will be appended. Then:
1) If block1 is NULL we terminate this pass. 1) If block1 is NULL we terminate this pass.
...@@ -1128,7 +1154,7 @@ an empty list list_tail which we will add elements to the end. Then: ...@@ -1128,7 +1154,7 @@ an empty list list_tail which we will add elements to the end. Then:
lists, by advancing list1 or list2 to next element lists, by advancing list1 or list2 to next element
and decreasing list1_size or list2_size. and decreasing list1_size or list2_size.
5.3) Add tmp to the end of the list_tail 5.3) Append tmp to list_tail
6) At this point, we have advanced list1 until it is where 6) At this point, we have advanced list1 until it is where
list2 started out and we have advanced list2 until it is list2 started out and we have advanced list2 until it is
...@@ -1140,11 +1166,11 @@ As soon as a pass like this is performed with only one merge, the ...@@ -1140,11 +1166,11 @@ As soon as a pass like this is performed with only one merge, the
algorithm terminates. Otherwise, double the value of block_size algorithm terminates. Otherwise, double the value of block_size
and go back to the beginning. */ and go back to the beginning. */
dulint ulint
row_merge_sort_linked_list_in_disk( row_merge_sort_linked_list_in_disk(
/*===============================*/ /*===============================*/
/* out: offset to first block in /* out: offset to first block in
the list or ut_dulint_max in the list or ULINT_UNDEFINED in
case of error */ case of error */
dict_index_t* index, /* in: index to be created */ dict_index_t* index, /* in: index to be created */
os_file_t file, /* in: File handle */ os_file_t file, /* in: File handle */
...@@ -1161,9 +1187,8 @@ row_merge_sort_linked_list_in_disk( ...@@ -1161,9 +1187,8 @@ row_merge_sort_linked_list_in_disk(
ulint list1_size; ulint list1_size;
ulint list2_size; ulint list2_size;
ulint i; ulint i;
dulint list_head; ulint list_head = 0;
dulint list_tail; ulint offset;
dulint offset;
ibool list_is_empty; ibool list_is_empty;
ut_ad(index); ut_ad(index);
...@@ -1172,20 +1197,16 @@ row_merge_sort_linked_list_in_disk( ...@@ -1172,20 +1197,16 @@ row_merge_sort_linked_list_in_disk(
backup1 = block1 = row_merge_block_create(); backup1 = block1 = row_merge_block_create();
backup2 = block2 = row_merge_block_create(); backup2 = block2 = row_merge_block_create();
list_head = ut_dulint_create(0, 0);
list_tail = ut_dulint_create(0, 0);
output.file = file; output.file = file;
block_size = 1; /* We start from block size 1 */ block_size = 1; /* We start from block size 1 */
for (;;) { for (;;) {
block1 = backup1; block1 = backup1;
row_merge_block_read(file, block1, list_head); row_merge_block_read(file, list_head, block1);
ut_ad(row_merge_block_validate(block1, index)); ut_ad(row_merge_block_validate(block1, index));
list_head = ut_dulint_create(0, 0);
list_tail = ut_dulint_create(0, 0);
list_is_empty = TRUE; list_is_empty = TRUE;
num_of_merges = 0; /* We count number of merges we do in num_of_merges = 0; /* We count number of merges we do in
this pass */ this pass */
...@@ -1205,15 +1226,15 @@ row_merge_sort_linked_list_in_disk( ...@@ -1205,15 +1226,15 @@ row_merge_sort_linked_list_in_disk(
/* Here read only the header to iterate the /* Here read only the header to iterate the
list in the disk. */ list in the disk. */
row_merge_block_header_read(file, &header, row_merge_block_header_read(file, offset,
offset); &header);
offset = header.next; offset = header.next;
/* If the offset is zero we have arrived to the /* If the offset is zero we have arrived to the
end of disk list */ end of disk list */
if (ut_dulint_is_zero(offset)) { if (!offset) {
break; break;
} }
} }
...@@ -1223,11 +1244,11 @@ row_merge_sort_linked_list_in_disk( ...@@ -1223,11 +1244,11 @@ row_merge_sort_linked_list_in_disk(
/* If offset is zero we have reached end of the list in /* If offset is zero we have reached end of the list in
the disk. */ the disk. */
if (ut_dulint_is_zero(offset)) { if (!offset) {
block2 = NULL; block2 = NULL;
} else { } else {
block2 = backup2; block2 = backup2;
row_merge_block_read(file, block2, offset); row_merge_block_read(file, offset, block2);
ut_ad(row_merge_block_validate(block2, index)); ut_ad(row_merge_block_validate(block2, index));
} }
...@@ -1247,8 +1268,7 @@ row_merge_sort_linked_list_in_disk( ...@@ -1247,8 +1268,7 @@ row_merge_sort_linked_list_in_disk(
tmp = block2; tmp = block2;
if (ut_dulint_is_zero( if (!block2->header.next) {
block2->header.next)) {
block2 = NULL; block2 = NULL;
} }
...@@ -1292,20 +1312,19 @@ row_merge_sort_linked_list_in_disk( ...@@ -1292,20 +1312,19 @@ row_merge_sort_linked_list_in_disk(
list_head = tmp->header.offset; list_head = tmp->header.offset;
} }
list_tail = tmp->header.offset;
ut_ad(row_merge_block_validate(tmp, index)); ut_ad(row_merge_block_validate(tmp, index));
row_merge_block_write( row_merge_block_write(
file, tmp, tmp->header.offset); file, tmp->header.offset, tmp);
/* Now we can read the next record from the /* Now we can read the next record from the
selected list if it contains more records */ selected list if it contains more records */
if (!ut_dulint_is_zero(tmp->header.next)) { if (tmp->header.next) {
row_merge_block_read(file, tmp, row_merge_block_read(file,
tmp->header.next); tmp->header.next,
tmp);
} else { } else {
if (selected == 2) { if (selected == 2) {
block2 = NULL; block2 = NULL;
...@@ -1346,10 +1365,9 @@ row_merge_sort_linked_list_in_disk( ...@@ -1346,10 +1365,9 @@ row_merge_sort_linked_list_in_disk(
/* In the sort phase we can have duplicate key error, inform this to /* In the sort phase we can have duplicate key error, inform this to
upper layer */ upper layer */
list_head = ut_dulint_max;
*error = DB_DUPLICATE_KEY; *error = DB_DUPLICATE_KEY;
return(list_head); return(ULINT_UNDEFINED);
} }
/************************************************************************ /************************************************************************
...@@ -1383,13 +1401,10 @@ row_merge_sort_and_store( ...@@ -1383,13 +1401,10 @@ row_merge_sort_and_store(
create a 'linked list' of blocks to the disk. */ create a 'linked list' of blocks to the disk. */
block->header.offset = file->offset; block->header.offset = file->offset;
block->header.next = ++file->offset;
block->header.next= ut_dulint_add(file->offset, MERGE_BLOCK_SIZE);
/* Thirdly, write block to the disk */ /* Thirdly, write block to the disk */
row_merge_block_write(file->file, block, file->offset); row_merge_block_write(file->file, block->header.offset, block);
file->offset= ut_dulint_add(file->offset, MERGE_BLOCK_SIZE);
return(1); return(1);
} }
...@@ -1461,7 +1476,6 @@ row_merge_read_clustered_index( ...@@ -1461,7 +1476,6 @@ row_merge_read_clustered_index(
are stored for memory sort and are stored for memory sort and
then written to the disk */ then written to the disk */
merge_rec_list_t** merge_list; /* Temporary list for records*/ merge_rec_list_t** merge_list; /* Temporary list for records*/
merge_block_header_t* header; /* Block header */
rec_t* rec; /* Record in the persistent rec_t* rec; /* Record in the persistent
cursor*/ cursor*/
btr_pcur_t pcur; /* Persistent cursor on the btr_pcur_t pcur; /* Persistent cursor on the
...@@ -1563,7 +1577,7 @@ row_merge_read_clustered_index( ...@@ -1563,7 +1577,7 @@ row_merge_read_clustered_index(
new_mrec, rec_offs_size(sec_offs), new_mrec, rec_offs_size(sec_offs),
merge_list[idx_num]); merge_list[idx_num]);
/* If we have enought data tuples to form a block /* If we have enough data tuples to form a block
sort linked list and store it to the block and sort linked list and store it to the block and
write this block to the disk. Note that not all write this block to the disk. Note that not all
data tuples in the list fit to the block.*/ data tuples in the list fit to the block.*/
...@@ -1626,9 +1640,7 @@ row_merge_read_clustered_index( ...@@ -1626,9 +1640,7 @@ row_merge_read_clustered_index(
'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 = files[idx_num].offset + 1;
block->header.next= ut_dulint_add(
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],
...@@ -1645,14 +1657,11 @@ row_merge_read_clustered_index( ...@@ -1645,14 +1657,11 @@ row_merge_read_clustered_index(
n_blocks++; n_blocks++;
} }
/* To the last block header we set (0, 0) to next /* Write the last block. */
offset to mark the end of the list. */ block->header.next = 0; /* end-of-list marker */
header = &(block->header);
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, &block->header);
} }
#ifdef UNIV_DEBUG_INDEX_CREATE #ifdef UNIV_DEBUG_INDEX_CREATE
...@@ -1691,7 +1700,7 @@ row_merge_insert_index_tuples( ...@@ -1691,7 +1700,7 @@ row_merge_insert_index_tuples(
dict_index_t* index, /* in: index */ dict_index_t* index, /* in: index */
dict_table_t* table, /* in: table */ dict_table_t* table, /* in: table */
os_file_t file, /* in: file handle */ os_file_t file, /* in: file handle */
dulint offset) /* in: offset where to start ulint offset) /* in: offset where to start
reading */ reading */
{ {
merge_block_t* block; merge_block_t* block;
...@@ -1701,7 +1710,6 @@ row_merge_insert_index_tuples( ...@@ -1701,7 +1710,6 @@ row_merge_insert_index_tuples(
mem_heap_t* dtuple_heap; mem_heap_t* dtuple_heap;
mem_heap_t* graph_heap; mem_heap_t* graph_heap;
ulint error = DB_SUCCESS; ulint error = DB_SUCCESS;
ibool more_records = TRUE;
ibool was_lock_wait = FALSE; ibool was_lock_wait = FALSE;
ut_ad(trx && index && table); ut_ad(trx && index && table);
...@@ -1721,12 +1729,13 @@ row_merge_insert_index_tuples( ...@@ -1721,12 +1729,13 @@ row_merge_insert_index_tuples(
block = row_merge_block_create(); block = row_merge_block_create();
rec_heap = mem_heap_create(128); rec_heap = mem_heap_create(128);
dtuple_heap = mem_heap_create(256); dtuple_heap = mem_heap_create(256);
row_merge_block_read(file, block, offset);
while (more_records) { do {
ulint n_rec; ulint n_rec;
ulint tuple_offset; ulint tuple_offset;
row_merge_block_read(file, offset, block);
ut_ad(row_merge_block_validate(block, index)); ut_ad(row_merge_block_validate(block, index));
tuple_offset = 0; tuple_offset = 0;
...@@ -1773,13 +1782,7 @@ row_merge_insert_index_tuples( ...@@ -1773,13 +1782,7 @@ row_merge_insert_index_tuples(
/* If we have reached the end of the disk list we have /* If we have reached the end of the disk list we have
inserted all of the index entries to the index. */ inserted all of the index entries to the index. */
} while (offset);
if (ut_dulint_is_zero(offset)) {
more_records = FALSE;
} else {
row_merge_block_read(file, block, offset);
}
}
que_thr_stop_for_mysql_no_error(thr, trx); que_thr_stop_for_mysql_no_error(thr, trx);
que_graph_free(thr->graph); que_graph_free(thr->graph);
...@@ -1894,7 +1897,7 @@ row_merge_file_create( ...@@ -1894,7 +1897,7 @@ row_merge_file_create(
{ {
merge_file->file = innobase_mysql_tmpfile(); merge_file->file = innobase_mysql_tmpfile();
merge_file->offset = ut_dulint_create(0, 0); merge_file->offset = 0;
merge_file->num_of_blocks = 0; merge_file->num_of_blocks = 0;
} }
......
...@@ -4522,12 +4522,10 @@ row_build_index_for_mysql( ...@@ -4522,12 +4522,10 @@ row_build_index_for_mysql(
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);
/* Merge sort file using linked list merge /* Merge sort file using linked list merge
sort for files. */ sort for files. */
offset = row_merge_sort_linked_list_in_disk( 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);
...@@ -4535,8 +4533,7 @@ row_build_index_for_mysql( ...@@ -4535,8 +4533,7 @@ row_build_index_for_mysql(
if (error == DB_SUCCESS) { if (error == DB_SUCCESS) {
error = row_merge_insert_index_tuples( error = row_merge_insert_index_tuples(
trx, index[index_num], new_table, trx, index[index_num], new_table,
merge_files[index_num].file, merge_files[index_num].file, 0);
ut_dulint_zero);
} }
if (error != DB_SUCCESS) { if (error != DB_SUCCESS) {
......
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