summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2022-11-16 14:52:47 +0200
committerSergei Petrunia <sergey@mariadb.com>2023-02-03 10:42:28 +0300
commit66dde8a54ecf91d97eb1ae4a6209e0e2dddcec97 (patch)
treeea6edd11d98d0990159825cf80b9353cc795e7d2 /mysys
parent6418c24c9498a28b3320d26309964203327ae66e (diff)
downloadmariadb-git-66dde8a54ecf91d97eb1ae4a6209e0e2dddcec97.tar.gz
Added rowid_filter support to Aria
This includes: - cleanup and optimization of filtering and pushdown engine code. - Adjusted costs for rowid filters (based on extensive testing and profiling). This made a small two changes to the handler_rowid_filter_is_active() API: - One should not call it with a zero pointer! - One does not need to call handler_rowid_filter_is_active() for every row anymore. It is enough to check if filter is active by calling it call it during index_init() or when handler::rowid_filter_changed() is called The changes was to avoid unnecessary function calls and checks if pushdown conditions and rowid_filter is not used. Updated costs for rowid_filter_lookup() to be closer to reality. The old cost was based only on rowid_compare_cost. This is now changed to take into account the overhead in checking the rowid. Changed the Range_rowid_filter class to use DYNAMIC_ARRAY directly instead of Dynamic_array<>. This was done to be able to use the new append_dynamic() functions which gives a notable speed improvment compared to the old code. Removing the abstraction also makes the code easier to understand. The cost of filtering is now slightly lower than before, which is reflected in some test cases that is now using rowid filters.
Diffstat (limited to 'mysys')
-rw-r--r--mysys/array.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/mysys/array.c b/mysys/array.c
index 6e871ee6343..02a54d44656 100644
--- a/mysys/array.c
+++ b/mysys/array.c
@@ -92,7 +92,7 @@ my_bool init_dynamic_array2(PSI_memory_key psi_key, DYNAMIC_ARRAY *array,
my_bool insert_dynamic(DYNAMIC_ARRAY *array, const void * element)
{
void *buffer;
- if (array->elements == array->max_element)
+ if (unlikely(array->elements == array->max_element))
{ /* Call only when necessary */
if (!(buffer=alloc_dynamic(array)))
return TRUE;
@@ -102,7 +102,42 @@ my_bool insert_dynamic(DYNAMIC_ARRAY *array, const void * element)
buffer=array->buffer+(array->elements * array->size_of_element);
array->elements++;
}
- memcpy(buffer,element,(size_t) array->size_of_element);
+ memcpy(buffer, element, array->size_of_element);
+ return FALSE;
+}
+
+
+/* Fast version of appending to dynamic array */
+
+void init_append_dynamic(DYNAMIC_ARRAY_APPEND *append,
+ DYNAMIC_ARRAY *array)
+{
+ append->array= array;
+ append->pos= array->buffer + array->elements * array->size_of_element;
+ append->end= array->buffer + array->max_element * array->size_of_element;
+}
+
+
+my_bool append_dynamic(DYNAMIC_ARRAY_APPEND *append,
+ const void *element)
+{
+ DYNAMIC_ARRAY *array= append->array;
+ size_t size_of_element= array->size_of_element;
+ if (unlikely(append->pos == append->end))
+ {
+ void *buffer;
+ if (!(buffer=alloc_dynamic(array)))
+ return TRUE;
+ append->pos= (uchar*)buffer + size_of_element;
+ append->end= array->buffer + array->max_element * size_of_element;
+ memcpy(buffer, element, size_of_element);
+ }
+ else
+ {
+ array->elements++;
+ memcpy(append->pos, element, size_of_element);
+ append->pos+= size_of_element;
+ }
return FALSE;
}
@@ -281,7 +316,7 @@ my_bool allocate_dynamic(DYNAMIC_ARRAY *array, size_t max_elements)
void get_dynamic(DYNAMIC_ARRAY *array, void *element, size_t idx)
{
- if (idx >= array->elements)
+ if (unlikely(idx >= array->elements))
{
DBUG_PRINT("warning",("To big array idx: %d, array size is %d",
idx,array->elements));
@@ -306,7 +341,7 @@ void delete_dynamic(DYNAMIC_ARRAY *array)
/*
Just mark as empty if we are using a static buffer
*/
- if (!(array->malloc_flags & MY_INIT_BUFFER_USED) && array->buffer)
+ if (array->buffer && !(array->malloc_flags & MY_INIT_BUFFER_USED))
my_free(array->buffer);
array->buffer= 0;