Hi!
Most of types generates reversible sort keys, so only key is written in
sort blocks and data is regenerated from it.
INTL strings (IS_INTL_DATA) does not generate reversible sort keys, so
original data is also written.
I think there is an unnecessary pass for them, there is no need to
regenerate data from the key in this case (when direction == 0).
See attached patch.
Is it correct?
Adriano
diff --git a/src/jrd/opt.cpp b/src/jrd/opt.cpp
index 9b3dbfa..ef1ca30 100644
--- a/src/jrd/opt.cpp
+++ b/src/jrd/opt.cpp
@@ -2553,6 +2553,12 @@ SortedStream* OPT_gen_sort(thread_db* tdbb, CompilerScratch* csb, const StreamLi
sort_key->skd_flags |= SKD_binary;
}
+ if ((sort_key->skd_dtype == SKD_varying || sort_key->skd_dtype == SKD_cstring || sort_key->skd_dtype == SKD_text) &&
+ IS_INTL_DATA(desc))
+ {
+ sort_key->skd_flags |= SKD_separate_data;
+ }
+
map_item->clear();
map_item->node = node;
map_item->flagOffset = prev_key->getSkdOffset();
diff --git a/src/jrd/sort.cpp b/src/jrd/sort.cpp
index 8a5e03c..4a21b6a 100644
--- a/src/jrd/sort.cpp
+++ b/src/jrd/sort.cpp
@@ -978,17 +978,21 @@ void Sort::diddleKey(UCHAR* record, bool direction)
}
}
- longs = n >> SHIFTLONG;
- while (--longs >= 0)
+ if (direction || !(key->skd_flags & SKD_separate_data))
{
- c1 = p[3];
- p[3] = *p;
- *p++ = c1;
- c1 = p[1];
- p[1] = *p;
- *p = c1;
- p += 3;
+ longs = n >> SHIFTLONG;
+ while (--longs >= 0)
+ {
+ c1 = p[3];
+ p[3] = *p;
+ *p++ = c1;
+ c1 = p[1];
+ p[1] = *p;
+ *p = c1;
+ p += 3;
+ }
}
+
p = (UCHAR*) wp;
break;
diff --git a/src/jrd/sort.h b/src/jrd/sort.h
index d5de501..5de6be8 100644
--- a/src/jrd/sort.h
+++ b/src/jrd/sort.h
@@ -149,6 +149,7 @@ const int SKD_dec_fixed = 18;
const UCHAR SKD_ascending = 0; // default initializer
const UCHAR SKD_descending = 1;
const UCHAR SKD_binary = 2;
+const UCHAR SKD_separate_data = 4;
// Sort key definition block
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Firebird-Devel mailing list, web interface at
https://lists.sourceforge.net/lists/listinfo/firebird-devel