Commit bbb35276 authored by Sergei Golubchik's avatar Sergei Golubchik

Remove engine-specific (but identical) icp callbacks. create one reusable

common icp callback in the handler.cc.

It can also increment status counters, without making the engine
dependent on the exact THD layout (that is different in embedded).
parent 2d19b077
......@@ -4555,6 +4555,27 @@ int handler::compare_key2(key_range *range)
}
/**
ICP callback - to be called by an engine to check the pushed condition
*/
extern "C" enum icp_result handler_index_cond_check(void* h_arg)
{
handler *h= (handler*)h_arg;
THD *thd= h->table->in_use;
enum icp_result res;
if (thd_killed(thd))
return ICP_ABORTED_BY_USER;
if (h->end_range && h->compare_key2(h->end_range) > 0)
return ICP_OUT_OF_RANGE;
h->increment_statistics(&SSV::ha_pushed_index_cond_checks);
if ((res= h->pushed_idx_cond->val_int()? ICP_MATCH : ICP_NO_MATCH) ==
ICP_NO_MATCH)
h->increment_statistics(&SSV::ha_pushed_index_cond_filtered);
return res;
}
int handler::index_read_idx_map(uchar * buf, uint index, const uchar * key,
key_part_map keypart_map,
enum ha_rkey_function find_flag)
......
......@@ -1553,6 +1553,8 @@ public:
{}
};
extern "C" enum icp_result handler_index_cond_check(void* h_arg);
uint calculate_key_len(TABLE *, uint, const uchar *, key_part_map);
/*
bitmap with first N+1 bits set
......@@ -2632,6 +2634,8 @@ public:
{ return ht; }
inline int ha_write_tmp_row(uchar *buf);
inline int ha_update_tmp_row(const uchar * old_data, uchar * new_data);
friend enum icp_result handler_index_cond_check(void* h_arg);
};
#include "multi_range_read.h"
......
......@@ -2243,27 +2243,6 @@ int ha_maria::delete_row(const uchar * buf)
return maria_delete(file, buf);
}
C_MODE_START
ICP_RESULT index_cond_func_maria(void *arg)
{
ha_maria *h= (ha_maria*)arg;
THD *thd= ((TABLE*) h->file->external_ref)->in_use;
ICP_RESULT res;
if (h->end_range)
{
if (h->compare_key2(h->end_range) > 0)
return ICP_OUT_OF_RANGE; /* caller should return HA_ERR_END_OF_FILE already */
}
status_var_increment(thd->status_var.ha_pushed_index_cond_checks);
if ((res= h->pushed_idx_cond->val_int() ? ICP_MATCH : ICP_NO_MATCH) ==
ICP_NO_MATCH)
status_var_increment(thd->status_var.ha_pushed_index_cond_filtered);
return res;
}
C_MODE_END
int ha_maria::index_read_map(uchar * buf, const uchar * key,
key_part_map keypart_map,
enum ha_rkey_function find_flag)
......@@ -2283,7 +2262,7 @@ int ha_maria::index_read_idx_map(uchar * buf, uint index, const uchar * key,
/* Use the pushed index condition if it matches the index we're scanning */
end_range= NULL;
if (index == pushed_idx_cond_keyno)
ma_set_index_cond_func(file, index_cond_func_maria, this);
ma_set_index_cond_func(file, handler_index_cond_check, this);
error= maria_rkey(file, buf, index, key, keypart_map, find_flag);
......@@ -2364,7 +2343,7 @@ int ha_maria::index_init(uint idx, bool sorted)
{
active_index=idx;
if (pushed_idx_cond_keyno == idx)
ma_set_index_cond_func(file, index_cond_func_maria, this);
ma_set_index_cond_func(file, handler_index_cond_check, this);
return 0;
}
......@@ -3797,7 +3776,7 @@ Item *ha_maria::idx_cond_push(uint keyno_arg, Item* idx_cond_arg)
pushed_idx_cond= idx_cond_arg;
in_range_check_pushed_down= TRUE;
if (active_index == pushed_idx_cond_keyno)
ma_set_index_cond_func(file, index_cond_func_maria, this);
ma_set_index_cond_func(file, handler_index_cond_check, this);
return NULL;
}
......
......@@ -1765,33 +1765,11 @@ int ha_myisam::delete_row(const uchar *buf)
}
C_MODE_START
ICP_RESULT index_cond_func_myisam(void *arg)
{
ha_myisam *h= (ha_myisam*)arg;
THD *thd= ((TABLE*) h->file->external_ref)->in_use;
ICP_RESULT res;
if (h->end_range)
{
if (h->compare_key2(h->end_range) > 0)
return ICP_OUT_OF_RANGE; /* caller should return HA_ERR_END_OF_FILE already */
}
status_var_increment(thd->status_var.ha_pushed_index_cond_checks);
if ((res= (ICP_RESULT) test(h->pushed_idx_cond->val_int())) ==
ICP_NO_MATCH)
status_var_increment(thd->status_var.ha_pushed_index_cond_filtered);
return res;
}
C_MODE_END
int ha_myisam::index_init(uint idx, bool sorted)
{
active_index=idx;
if (pushed_idx_cond_keyno == idx)
mi_set_index_cond_func(file, index_cond_func_myisam, this);
mi_set_index_cond_func(file, handler_index_cond_check, this);
return 0;
}
......@@ -1827,7 +1805,7 @@ int ha_myisam::index_read_idx_map(uchar *buf, uint index, const uchar *key,
/* Use the pushed index condition if it matches the index we're scanning */
end_range= NULL;
if (index == pushed_idx_cond_keyno)
mi_set_index_cond_func(file, index_cond_func_myisam, this);
mi_set_index_cond_func(file, handler_index_cond_check, this);
res= mi_rkey(file, buf, index, key, keypart_map, find_flag);
mi_set_index_cond_func(file, NULL, 0);
return res;
......@@ -2346,7 +2324,7 @@ Item *ha_myisam::idx_cond_push(uint keyno_arg, Item* idx_cond_arg)
pushed_idx_cond= idx_cond_arg;
in_range_check_pushed_down= TRUE;
if (active_index == pushed_idx_cond_keyno)
mi_set_index_cond_func(file, index_cond_func_myisam, this);
mi_set_index_cond_func(file, handler_index_cond_check, this);
return NULL;
}
......
......@@ -12573,34 +12573,6 @@ bool ha_innobase::is_thd_killed()
* Index Condition Pushdown interface implementation
*/
/*************************************************************//**
InnoDB index push-down condition check
@return ICP_NO_MATCH, ICP_MATCH, or ICP_OUT_OF_RANGE */
extern "C" UNIV_INTERN
enum icp_result
innobase_index_cond(
/*================*/
void* file) /*!< in/out: pointer to ha_innobase */
{
ha_innobase *h= (ha_innobase*) file;
THD *thd= h->thd();
enum icp_result res;
if (h->is_thd_killed())
return ICP_ABORTED_BY_USER;
if (h->end_range)
{
if (h->compare_key2(h->end_range) > 0)
return ICP_OUT_OF_RANGE; /* caller should return HA_ERR_END_OF_FILE already */
}
status_var_increment(thd->status_var.ha_pushed_index_cond_checks);
if ((res= h->pushed_idx_cond->val_int()? ICP_MATCH : ICP_NO_MATCH) ==
ICP_NO_MATCH)
status_var_increment(thd->status_var.ha_pushed_index_cond_filtered);
return res;
}
/** Attempt to push down an index condition.
* @param[in] keyno MySQL key number
* @param[in] idx_cond Index condition to be checked
......
......@@ -224,7 +224,6 @@ class ha_innobase: public handler
uint table_changes);
bool check_if_supported_virtual_columns(void) { return TRUE; }
THD *thd() { return user_thd; }
private:
/** Builds a 'template' to the prebuilt struct.
......
......@@ -252,7 +252,7 @@ InnoDB index push-down condition check
@return ICP_NO_MATCH, ICP_MATCH, or ICP_OUT_OF_RANGE */
UNIV_INTERN
enum icp_result
innobase_index_cond(
handler_index_cond_check(
/*================*/
void* file) /*!< in/out: pointer to ha_innobase */
__attribute__((nonnull, warn_unused_result));
......
......@@ -3443,7 +3443,7 @@ row_search_idx_cond_check(
index, if the case of the column has been updated in
the past, or a record has been deleted and a record
inserted in a different case. */
result = innobase_index_cond(prebuilt->idx_cond);
result = handler_index_cond_check(prebuilt->idx_cond);
switch (result) {
case ICP_MATCH:
/* Convert the remaining fields to MySQL format.
......
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