summaryrefslogtreecommitdiff
path: root/sql/field.cc
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2020-03-28 12:31:22 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2020-12-04 23:38:09 +0530
commit202393086e4da6c6864778dcb87339f159ea48f6 (patch)
tree203cb33f02b64b59de11f86c56ba423f352ba0d2 /sql/field.cc
parente9f33b7760539e2ba60fb236fab8eaf0ce53ca4a (diff)
downloadmariadb-git-bb-10.6-mdev21829.tar.gz
MDEV-21829: Use packed sort keys in Unique objectsbb-10.6-mdev21829
The task deals with packing the values stored in the Unique tree for each record. The changes brought by this feature is: 1) Unique tree can have dynamic length keys 2) Format of keys looks like <key_length> <packed_value1> <packed_value2> ....... <packed_valueN> Unique class is currently used in 1) agg_func(DISTINCT col) Here most aggregate functions like SUM, AVG accept only fixed size arguments so it is not beneficial to use packing for these. Packing is done for COUNT and GROUP_CONCAT (or JSON_ARRAYAGG) aggregate function as these are meaningful 2) index-merge stores row-ids index merge stores row-ids which are of fixed size, so packing is not required 3) Engine Independent Table statistics Packing is done here for variable length data types This task is an extension to MDEV-21580.
Diffstat (limited to 'sql/field.cc')
-rw-r--r--sql/field.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 2173670572d..587cbdfb8c3 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1064,6 +1064,47 @@ Field::make_packed_sort_key_part(uchar *buff,
}
+/*
+ @brief
+ Create a packed sort key part
+
+ @param buff buffer where values are written
+ @param sort_field sort column structure
+
+ @details
+ This function stores the original values for the fixed size columns and
+ does not covert them to mem-comparable images.
+
+ @retval
+ length of the bytes written, does not include the NULL bytes
+*/
+
+uint
+Field::make_packed_key_part(uchar *buff, const SORT_FIELD_ATTR *sort_field)
+{
+ if (maybe_null())
+ {
+ if (is_null())
+ {
+ *buff++= 0;
+ return 0; // For NULL values don't write any data
+ }
+ *buff++=1;
+ }
+ memcpy(buff, ptr, sort_field->original_length);
+ return sort_field->original_length;
+}
+
+
+uint
+Field_longstr::make_packed_key_part(uchar *buff,
+ const SORT_FIELD_ATTR *sort_field)
+{
+ return make_packed_sort_key_part(buff, sort_field);
+}
+
+
+
uint
Field_longstr::make_packed_sort_key_part(uchar *buff,
const SORT_FIELD_ATTR *sort_field)