Commit 588f4983 authored by marko's avatar marko

branches/zip: Clean up fast index creation.

row_merge_read(), row_merge_write(): Add UNIV_LIKELY hints.

row_merge_sort_linked_list_in_disk(): Reduce the scope of many variables.
Eliminate the variable "selected".
parent 7dd753ed
...@@ -177,10 +177,10 @@ row_merge_read( ...@@ -177,10 +177,10 @@ row_merge_read(
ut_ad(size <= MERGE_BLOCK_SIZE); ut_ad(size <= MERGE_BLOCK_SIZE);
return(os_file_read(file, buf, return(UNIV_LIKELY(os_file_read(file, buf,
(ulint) (ofs & 0xFFFFFFFF), (ulint) (ofs & 0xFFFFFFFF),
(ulint) (ofs >> 32), (ulint) (ofs >> 32),
size)); size)));
} }
/************************************************************************ /************************************************************************
...@@ -230,10 +230,10 @@ row_merge_write( ...@@ -230,10 +230,10 @@ row_merge_write(
ut_ad(size <= MERGE_BLOCK_SIZE); ut_ad(size <= MERGE_BLOCK_SIZE);
return(os_file_write("(merge)", file, buf, return(UNIV_LIKELY(os_file_write("(merge)", file, buf,
(ulint) (ofs & 0xFFFFFFFF), (ulint) (ofs & 0xFFFFFFFF),
(ulint) (ofs >> 32), (ulint) (ofs >> 32),
size)); size)));
} }
/************************************************************************ /************************************************************************
...@@ -1180,16 +1180,9 @@ row_merge_sort_linked_list_in_disk( ...@@ -1180,16 +1180,9 @@ row_merge_sort_linked_list_in_disk(
merge_block_t* block2; merge_block_t* block2;
merge_block_t* backup1; merge_block_t* backup1;
merge_block_t* backup2; merge_block_t* backup2;
merge_block_header_t header;
merge_file_t output; merge_file_t output;
ulint block_size; ulint block_size;
ulint num_of_merges;
ulint list1_size;
ulint list2_size;
ulint i;
ulint list_head = 0; ulint list_head = 0;
ulint offset;
ibool list_is_empty;
ut_ad(index); ut_ad(index);
...@@ -1199,28 +1192,26 @@ row_merge_sort_linked_list_in_disk( ...@@ -1199,28 +1192,26 @@ row_merge_sort_linked_list_in_disk(
output.file = file; output.file = file;
block_size = 1; /* We start from block size 1 */ for (block_size = 1;; block_size *= 2) {
ibool sorted = TRUE;
for (;;) { ibool list_is_empty = TRUE;
block1 = backup1; block1 = backup1;
row_merge_block_read(file, list_head, block1); 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_is_empty = TRUE;
num_of_merges = 0; /* We count number of merges we do in
this pass */
for (;;) { for (;;) {
num_of_merges++; ulint offset = block1->header.offset;
ulint list1_size = 0;
header = block1->header; ulint list2_size = block_size;
offset = header.offset; ulint i;
list1_size = 0;
/* Count how many list elements we have in the list. */ /* Count how many list elements we have in the list. */
for (i = 0; i < block_size; i++) { for (i = 0; i < block_size; i++) {
merge_block_header_t header;
list1_size++; list1_size++;
/* Here read only the header to iterate the /* Here read only the header to iterate the
...@@ -1239,8 +1230,6 @@ row_merge_sort_linked_list_in_disk( ...@@ -1239,8 +1230,6 @@ row_merge_sort_linked_list_in_disk(
} }
} }
list2_size = block_size;
/* 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. */
...@@ -1260,7 +1249,6 @@ row_merge_sort_linked_list_in_disk( ...@@ -1260,7 +1249,6 @@ row_merge_sort_linked_list_in_disk(
next element of merge comes from list1 or next element of merge comes from list1 or
list2. */ list2. */
merge_block_t* tmp; merge_block_t* tmp;
ulint selected;
if (list1_size == 0) { if (list1_size == 0) {
/* First list is empty, next element /* First list is empty, next element
...@@ -1270,19 +1258,16 @@ row_merge_sort_linked_list_in_disk( ...@@ -1270,19 +1258,16 @@ row_merge_sort_linked_list_in_disk(
if (!block2->header.next) { if (!block2->header.next) {
block2 = NULL; block2 = NULL;
list2_size = 0;
} else {
list2_size--;
} }
list2_size--;
selected = 2;
} else if (list2_size == 0 || !block2) { } else if (list2_size == 0 || !block2) {
/* Second list is empty, next record /* Second list is empty, next record
must come from the first list. */ must come from the first list. */
tmp = block1; tmp = block1;
list1_size--; list1_size--;
selected = 1;
} else { } else {
/* Both lists contain a block and we /* Both lists contain a block and we
need to merge records on these block */ need to merge records on these block */
...@@ -1290,22 +1275,20 @@ row_merge_sort_linked_list_in_disk( ...@@ -1290,22 +1275,20 @@ row_merge_sort_linked_list_in_disk(
tmp = row_merge_block_merge( tmp = row_merge_block_merge(
block1, &block2, index); block1, &block2, index);
block1 = tmp;
backup1 = tmp;
backup2 = block2;
if (tmp == NULL) { if (tmp == NULL) {
goto error_handling; goto error_handling;
} }
block1 = backup1 = tmp;
backup2 = block2;
list1_size--; list1_size--;
selected = 1;
} }
/* Store head and tail offsets of the disk list. /* Store the head offset of the disk
Note that only records on the blocks are list. Note that only records in the
changed not the order of the blocks in the blocks are changed not the order of
disk. */ the blocks in the disk. */
if (list_is_empty) { if (list_is_empty) {
list_is_empty = FALSE; list_is_empty = FALSE;
...@@ -1325,10 +1308,6 @@ row_merge_sort_linked_list_in_disk( ...@@ -1325,10 +1308,6 @@ row_merge_sort_linked_list_in_disk(
row_merge_block_read(file, row_merge_block_read(file,
tmp->header.next, tmp->header.next,
tmp); tmp);
} else {
if (selected == 2) {
block2 = NULL;
}
} }
} }
...@@ -1343,21 +1322,16 @@ row_merge_sort_linked_list_in_disk( ...@@ -1343,21 +1322,16 @@ row_merge_sort_linked_list_in_disk(
block1 = backup2; block1 = backup2;
backup2 = block2; backup2 = block2;
backup1 = block1; backup1 = block1;
}
sorted = FALSE;
}
/* If we have done oly one merge, we have created a sorted if (sorted) {
list */
if (num_of_merges <= 1) {
mem_free(backup1); mem_free(backup1);
mem_free(backup2); mem_free(backup2);
return(list_head); return(list_head);
} else {
/* Otherwise merge lists twice the size */
block_size *= 2;
} }
} }
......
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