Commit 828a7856 authored by mskold@mysql.com's avatar mskold@mysql.com

Condition pushdown v.2

parent f21a7371
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -75,74 +75,89 @@ typedef union ndb_item_qualification { ...@@ -75,74 +75,89 @@ typedef union ndb_item_qualification {
Item_func::Functype function_type; // Instead of Item::FUNC_ITEM Item_func::Functype function_type; // Instead of Item::FUNC_ITEM
} NDB_ITEM_QUALIFICATION; } NDB_ITEM_QUALIFICATION;
class Ndb_item_string_value {
public:
String s;
CHARSET_INFO *c;
};
typedef struct ndb_item_field_value { typedef struct ndb_item_field_value {
Field* field; Field* field;
int column_no; int column_no;
} NDB_ITEM_FIELD_VALUE; } NDB_ITEM_FIELD_VALUE;
typedef union ndb_item_value { typedef union ndb_item_value {
longlong int_value; const Item *item;
double real_value;
Ndb_item_string_value *string_value;
NDB_ITEM_FIELD_VALUE *field_value; NDB_ITEM_FIELD_VALUE *field_value;
} NDB_ITEM_VALUE; } NDB_ITEM_VALUE;
class Ndb_item { class Ndb_item {
public: public:
Ndb_item(NDB_ITEM_TYPE item_type); Ndb_item(NDB_ITEM_TYPE item_type) : type(item_type) {};
Ndb_item(NDB_ITEM_TYPE item_type, Ndb_item(NDB_ITEM_TYPE item_type,
NDB_ITEM_QUALIFICATION item_qualification, NDB_ITEM_QUALIFICATION item_qualification,
const Item *item_value); const Item *item_value)
Ndb_item(longlong int_value); : type(item_type), qualification(item_qualification)
Ndb_item(double real_value);
Ndb_item(Field *field, int column_no);
Ndb_item(Item_func::Functype func_type);
~Ndb_item();
void print(String *str);
uint32 pack_length() { return value.field_value->field->pack_length(); };
// Getters and Setters
longlong get_int_value() { return value.int_value; };
double get_real_value() { return value.real_value; };
String * get_string_value() { return &value.string_value->s; };
CHARSET_INFO * get_string_charset() { return value.string_value->c; };
Field * get_field() { return value.field_value->field; };
int get_field_no() { return value.field_value->column_no; };
const void * get_value()
{ {
switch(qualification.value_type) { switch(item_type) {
case(Item::INT_ITEM): { case(NDB_VALUE):
return (void *) &value.int_value; value.item= item_value;
break;
case(NDB_FIELD): {
NDB_ITEM_FIELD_VALUE *field_value= new NDB_ITEM_FIELD_VALUE();
Item_field *field_item= (Item_field *) item_value;
field_value->field= field_item->field;
field_value->column_no= -1; // Will be fetched at scan filter generation
value.field_value= field_value;
break;
} }
case(Item::REAL_ITEM): { case(NDB_FUNCTION):
return (void *) &value.real_value; case(NDB_END_COND):
break; break;
} }
case(Item::STRING_ITEM): };
case(Item::VARBIN_ITEM): { Ndb_item(Field *field, int column_no) : type(NDB_FIELD)
return value.string_value->s.ptr(); {
NDB_ITEM_FIELD_VALUE *field_value= new NDB_ITEM_FIELD_VALUE();
qualification.field_type= field->type();
field_value->field= field;
field_value->column_no= column_no;
value.field_value= field_value;
};
Ndb_item(Item_func::Functype func_type) : type(NDB_FUNCTION)
{
qualification.function_type= func_type;
};
~Ndb_item()
{
if (type == NDB_FIELD)
{
delete value.field_value;
value.field_value= NULL;
} }
};
uint32 pack_length()
{
switch(type) {
case(NDB_FIELD):
return value.field_value->field->pack_length();
default: default:
break; break;
} }
return NULL; return 0;
};
Field * get_field() { return value.field_value->field; };
int get_field_no() { return value.field_value->column_no; };
char* get_val() { return value.field_value->field->ptr; };
void save_in_field(Ndb_item *field_item)
{
Field *field = field_item->value.field_value->field;
const Item *item= value.item;
if (item && field)
((Item *)item)->save_in_field(field, false);
} }
public:
NDB_ITEM_TYPE type; NDB_ITEM_TYPE type;
NDB_ITEM_QUALIFICATION qualification; NDB_ITEM_QUALIFICATION qualification;
private: private:
NDB_ITEM_VALUE value; NDB_ITEM_VALUE value;
}; };
class Ndb_cond { class Ndb_cond {
...@@ -179,7 +194,7 @@ class Ndb_cond_traverse_context { ...@@ -179,7 +194,7 @@ class Ndb_cond_traverse_context {
bool *supported, Ndb_cond_stack* stack) bool *supported, Ndb_cond_stack* stack)
: table(tab), ndb_table(ndb_tab), : table(tab), ndb_table(ndb_tab),
supported_ptr(supported), stack_ptr(stack), cond_ptr(NULL), supported_ptr(supported), stack_ptr(stack), cond_ptr(NULL),
expect_mask(0), expect_field_result_mask(0) expect_mask(0), expect_field_result_mask(0), skip(0)
{ {
if (stack) if (stack)
cond_ptr= stack->ndb_cond; cond_ptr= stack->ndb_cond;
...@@ -231,6 +246,7 @@ class Ndb_cond_traverse_context { ...@@ -231,6 +246,7 @@ class Ndb_cond_traverse_context {
Ndb_cond* cond_ptr; Ndb_cond* cond_ptr;
uint expect_mask; uint expect_mask;
uint expect_field_result_mask; uint expect_field_result_mask;
uint skip;
}; };
/* /*
...@@ -406,7 +422,7 @@ class ha_ndbcluster: public handler ...@@ -406,7 +422,7 @@ class ha_ndbcluster: public handler
void no_uncommitted_rows_reset(THD *); void no_uncommitted_rows_reset(THD *);
/* /*
Condition Pushdown to Handler (CPDH), private methods Condition pushdown
*/ */
void cond_clear(); void cond_clear();
bool serialize_cond(const COND *cond, Ndb_cond_stack *ndb_cond); bool serialize_cond(const COND *cond, Ndb_cond_stack *ndb_cond);
......
...@@ -352,7 +352,7 @@ void Item_func::traverse_cond(Item_cond_traverser traverser, ...@@ -352,7 +352,7 @@ void Item_func::traverse_cond(Item_cond_traverser traverser,
switch (order) { switch (order) {
case(PREFIX): case(PREFIX):
(traverser)(this, argument); (*traverser)(this, argument);
for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++) for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++)
{ {
(*arg)->traverse_cond(traverser, argument, order); (*arg)->traverse_cond(traverser, argument, order);
...@@ -363,7 +363,7 @@ void Item_func::traverse_cond(Item_cond_traverser traverser, ...@@ -363,7 +363,7 @@ void Item_func::traverse_cond(Item_cond_traverser traverser,
{ {
(*arg)->traverse_cond(traverser, argument, order); (*arg)->traverse_cond(traverser, argument, order);
} }
(traverser)(this, argument); (*traverser)(this, argument);
} }
} }
} }
......
...@@ -4172,9 +4172,9 @@ enum options_mysqld ...@@ -4172,9 +4172,9 @@ enum options_mysqld
OPT_INNODB_LOCKS_UNSAFE_FOR_BINLOG, OPT_INNODB_LOCKS_UNSAFE_FOR_BINLOG,
OPT_SAFE_SHOW_DB, OPT_INNODB_SAFE_BINLOG, OPT_SAFE_SHOW_DB, OPT_INNODB_SAFE_BINLOG,
OPT_INNODB, OPT_ISAM, OPT_INNODB, OPT_ISAM,
OPT_ENGINE_CONDITION_PUSHDOWN,
OPT_NDBCLUSTER, OPT_NDB_CONNECTSTRING, OPT_NDB_USE_EXACT_COUNT, OPT_NDBCLUSTER, OPT_NDB_CONNECTSTRING, OPT_NDB_USE_EXACT_COUNT,
OPT_NDB_FORCE_SEND, OPT_NDB_AUTOINCREMENT_PREFETCH_SZ, OPT_NDB_FORCE_SEND, OPT_NDB_AUTOINCREMENT_PREFETCH_SZ,
OPT_NDB_CONDITION_PUSHDOWN,
OPT_NDB_SHM, OPT_NDB_OPTIMIZED_NODE_SELECTION, OPT_NDB_SHM, OPT_NDB_OPTIMIZED_NODE_SELECTION,
OPT_SKIP_SAFEMALLOC, OPT_SKIP_SAFEMALLOC,
OPT_TEMP_POOL, OPT_TX_ISOLATION, OPT_TEMP_POOL, OPT_TX_ISOLATION,
...@@ -4424,6 +4424,12 @@ Disable with --skip-bdb (will save memory).", ...@@ -4424,6 +4424,12 @@ Disable with --skip-bdb (will save memory).",
{"enable-pstack", OPT_DO_PSTACK, "Print a symbolic stack trace on failure.", {"enable-pstack", OPT_DO_PSTACK, "Print a symbolic stack trace on failure.",
(gptr*) &opt_do_pstack, (gptr*) &opt_do_pstack, 0, GET_BOOL, NO_ARG, 0, 0, (gptr*) &opt_do_pstack, (gptr*) &opt_do_pstack, 0, GET_BOOL, NO_ARG, 0, 0,
0, 0, 0, 0}, 0, 0, 0, 0},
{"engine-condition-pushdown",
OPT_ENGINE_CONDITION_PUSHDOWN,
"Push supported query conditions to the storage engine.",
(gptr*) &global_system_variables.engine_condition_pushdown,
(gptr*) &global_system_variables.engine_condition_pushdown,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"exit-info", 'T', "Used for debugging; Use at your own risk!", 0, 0, 0, {"exit-info", 'T', "Used for debugging; Use at your own risk!", 0, 0, 0,
GET_LONG, OPT_ARG, 0, 0, 0, 0, 0, 0}, GET_LONG, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"external-locking", OPT_USE_LOCKING, "Use system (external) locking. With this option enabled you can run myisamchk to test (not repair) tables while the MySQL server is running.", {"external-locking", OPT_USE_LOCKING, "Use system (external) locking. With this option enabled you can run myisamchk to test (not repair) tables while the MySQL server is running.",
...@@ -4657,12 +4663,6 @@ Disable with --skip-ndbcluster (will save memory).", ...@@ -4657,12 +4663,6 @@ Disable with --skip-ndbcluster (will save memory).",
(gptr*) &opt_ndbcluster, (gptr*) &opt_ndbcluster, 0, GET_BOOL, NO_ARG, (gptr*) &opt_ndbcluster, (gptr*) &opt_ndbcluster, 0, GET_BOOL, NO_ARG,
OPT_NDBCLUSTER_DEFAULT, 0, 0, 0, 0, 0}, OPT_NDBCLUSTER_DEFAULT, 0, 0, 0, 0, 0},
#ifdef HAVE_NDBCLUSTER_DB #ifdef HAVE_NDBCLUSTER_DB
{"ndb-condition-pushdown",
OPT_NDB_CONDITION_PUSHDOWN,
"Push supported query conditions to the ndbcluster storage engine.",
(gptr*) &global_system_variables.ndb_condition_pushdown,
(gptr*) &global_system_variables.ndb_condition_pushdown,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"ndb-connectstring", OPT_NDB_CONNECTSTRING, {"ndb-connectstring", OPT_NDB_CONNECTSTRING,
"Connect string for ndbcluster.", "Connect string for ndbcluster.",
(gptr*) &opt_ndbcluster_connectstring, (gptr*) &opt_ndbcluster_connectstring,
......
...@@ -388,6 +388,11 @@ sys_var_long_ptr sys_innodb_thread_concurrency("innodb_thread_concurrency", ...@@ -388,6 +388,11 @@ sys_var_long_ptr sys_innodb_thread_concurrency("innodb_thread_concurrency",
&srv_thread_concurrency); &srv_thread_concurrency);
#endif #endif
/* Condition pushdown to storage engine */
sys_var_thd_bool
sys_engine_condition_pushdown("engine_condition_pushdown",
&SV::engine_condition_pushdown);
#ifdef HAVE_NDBCLUSTER_DB #ifdef HAVE_NDBCLUSTER_DB
/* ndb thread specific variable settings */ /* ndb thread specific variable settings */
sys_var_thd_ulong sys_var_thd_ulong
...@@ -399,9 +404,6 @@ sys_var_thd_bool ...@@ -399,9 +404,6 @@ sys_var_thd_bool
sys_ndb_use_exact_count("ndb_use_exact_count", &SV::ndb_use_exact_count); sys_ndb_use_exact_count("ndb_use_exact_count", &SV::ndb_use_exact_count);
sys_var_thd_bool sys_var_thd_bool
sys_ndb_use_transactions("ndb_use_transactions", &SV::ndb_use_transactions); sys_ndb_use_transactions("ndb_use_transactions", &SV::ndb_use_transactions);
sys_var_thd_bool
sys_ndb_condition_pushdown("ndb_condition_pushdown",
&SV::ndb_condition_pushdown);
#endif #endif
/* Time/date/datetime formats */ /* Time/date/datetime formats */
...@@ -668,12 +670,12 @@ sys_var *sys_variables[]= ...@@ -668,12 +670,12 @@ sys_var *sys_variables[]=
&sys_innodb_thread_sleep_delay, &sys_innodb_thread_sleep_delay,
&sys_innodb_thread_concurrency, &sys_innodb_thread_concurrency,
#endif #endif
&sys_engine_condition_pushdown,
#ifdef HAVE_NDBCLUSTER_DB #ifdef HAVE_NDBCLUSTER_DB
&sys_ndb_autoincrement_prefetch_sz, &sys_ndb_autoincrement_prefetch_sz,
&sys_ndb_force_send, &sys_ndb_force_send,
&sys_ndb_use_exact_count, &sys_ndb_use_exact_count,
&sys_ndb_use_transactions, &sys_ndb_use_transactions,
&sys_ndb_condition_pushdown,
#endif #endif
&sys_unique_checks, &sys_unique_checks,
&sys_updatable_views_with_limit, &sys_updatable_views_with_limit,
...@@ -847,14 +849,14 @@ struct show_var_st init_vars[]= { ...@@ -847,14 +849,14 @@ struct show_var_st init_vars[]= {
#ifdef __NT__ #ifdef __NT__
{"named_pipe", (char*) &opt_enable_named_pipe, SHOW_MY_BOOL}, {"named_pipe", (char*) &opt_enable_named_pipe, SHOW_MY_BOOL},
#endif #endif
{sys_engine_condition_pushdown.name,
(char*) &sys_engine_condition_pushdown, SHOW_SYS},
#ifdef HAVE_NDBCLUSTER_DB #ifdef HAVE_NDBCLUSTER_DB
{sys_ndb_autoincrement_prefetch_sz.name, {sys_ndb_autoincrement_prefetch_sz.name,
(char*) &sys_ndb_autoincrement_prefetch_sz, SHOW_SYS}, (char*) &sys_ndb_autoincrement_prefetch_sz, SHOW_SYS},
{sys_ndb_force_send.name, (char*) &sys_ndb_force_send, SHOW_SYS}, {sys_ndb_force_send.name, (char*) &sys_ndb_force_send, SHOW_SYS},
{sys_ndb_use_exact_count.name,(char*) &sys_ndb_use_exact_count, SHOW_SYS}, {sys_ndb_use_exact_count.name,(char*) &sys_ndb_use_exact_count, SHOW_SYS},
{sys_ndb_use_transactions.name,(char*) &sys_ndb_use_transactions, SHOW_SYS}, {sys_ndb_use_transactions.name,(char*) &sys_ndb_use_transactions, SHOW_SYS},
{sys_ndb_condition_pushdown.name, (char*) &sys_ndb_condition_pushdown,
SHOW_SYS},
#endif #endif
{sys_net_buffer_length.name,(char*) &sys_net_buffer_length, SHOW_SYS}, {sys_net_buffer_length.name,(char*) &sys_net_buffer_length, SHOW_SYS},
{sys_net_read_timeout.name, (char*) &sys_net_read_timeout, SHOW_SYS}, {sys_net_read_timeout.name, (char*) &sys_net_read_timeout, SHOW_SYS},
......
...@@ -430,6 +430,7 @@ struct system_variables ...@@ -430,6 +430,7 @@ struct system_variables
my_bool low_priority_updates; my_bool low_priority_updates;
my_bool new_mode; my_bool new_mode;
my_bool query_cache_wlock_invalidate; my_bool query_cache_wlock_invalidate;
my_bool engine_condition_pushdown;
#ifdef HAVE_INNOBASE_DB #ifdef HAVE_INNOBASE_DB
my_bool innodb_table_locks; my_bool innodb_table_locks;
#endif /* HAVE_INNOBASE_DB */ #endif /* HAVE_INNOBASE_DB */
...@@ -438,7 +439,6 @@ struct system_variables ...@@ -438,7 +439,6 @@ struct system_variables
my_bool ndb_force_send; my_bool ndb_force_send;
my_bool ndb_use_exact_count; my_bool ndb_use_exact_count;
my_bool ndb_use_transactions; my_bool ndb_use_transactions;
my_bool ndb_condition_pushdown;
#endif /* HAVE_NDBCLUSTER_DB */ #endif /* HAVE_NDBCLUSTER_DB */
my_bool old_passwords; my_bool old_passwords;
......
...@@ -5300,6 +5300,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -5300,6 +5300,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if (!(tmp= add_found_match_trig_cond(first_inner_tab, tmp, 0))) if (!(tmp= add_found_match_trig_cond(first_inner_tab, tmp, 0)))
DBUG_RETURN(1); DBUG_RETURN(1);
tab->select_cond=sel->cond=tmp; tab->select_cond=sel->cond=tmp;
if (current_thd->variables.engine_condition_pushdown)
tab->table->file->cond_push(tmp); // Push condition to handler tab->table->file->cond_push(tmp); // Push condition to handler
} }
else else
...@@ -5422,7 +5423,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -5422,7 +5423,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
join->thd->memdup((gptr) sel, sizeof(SQL_SELECT)); join->thd->memdup((gptr) sel, sizeof(SQL_SELECT));
tab->cache.select->cond=tmp; tab->cache.select->cond=tmp;
tab->cache.select->read_tables=join->const_table_map; tab->cache.select->read_tables=join->const_table_map;
if (tmp != tab->select_cond) if (current_thd->variables.engine_condition_pushdown &&
(tmp != tab->select_cond))
tab->table->file->cond_push(tmp); // Push condition to handler tab->table->file->cond_push(tmp); // Push condition to handler
} }
} }
......
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