From 87166702295a95036698a0ef1cda51be76666e90 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Sep 2006 11:06:37 -0700 Subject: Fixed bug #21698: erroneously a field could be replaced by an equal constant under any circumstances. In fact this substitution can be allowed if the field is not of a type string or if the field reference serves as an argument of a comparison predicate. mysql-test/r/func_str.result: Added test cases for bug #21698. mysql-test/r/heap_hash.result: Adjusted results after the fix for bug #21198. mysql-test/t/func_str.test: Added test cases for bug #21698. sql/item.cc: Fixed bug #21198. Added a method to check whether a field reference can be substituted for a constant equal to the field. This substitution is allowed if the field is not of a type string or if the field reference serves as an argument of a comparison predicate. sql/item.h: Fixed bug #21698. Added a new virtual transformation method for a item 'compile' with two callback function parameters. Added a new virtual method 'subst_argument_checker' to be used as an amnalyzer method. This method is supposed to set its in/out argument to NULL for the nodes where substitution of a string field for a constant is not valid. sql/item_cmpfunc.cc: Fixed bug #21698. Added an implementation of the compile method for class Item_cond. First it processes the Item_cond node with a callback function and if the latter returns TRUE it proceeds with a transformation performed by another callback function. sql/item_cmpfunc.h: Fixed bug #21698. Added the implementations of 'subst_argument_checker' for the Item_func and Item_cond classes. This method is supposed to set its in/out argument to NULL for the nodes where substitution of a string field for a constant is not valid. Added the declaration of an implementation of the compile method for class Item_cond. First it processes the Item_cond node with a callback function and if the latter returns TRUE it proceeds with a transformation performed by another callback function. sql/item_func.cc: Fixed bug #21698. Added an implementation of the compile method for class Item_func. First it processes the Item_func node with a callback function and if the latter returns TRUE it proceeds with a transformation performed by another callback function. sql/item_func.h: Fixed bug #21698. Added the declaration of the implementation of the compile method for class Item_func. First it processes the Item_func node with a callback function and if the latter returns TRUE it proceeds with a transformation performed by another callback function. sql/sql_select.cc: Fixed bug #21698. Limited the conditions at which a field can be substituted a for an equal constant in a formula. This substitution is allowed if the field is not of a type string or if the field reference serves as an argument of a comparison predicate. --- sql/item.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'sql/item.h') diff --git a/sql/item.h b/sql/item.h index e3df0fdf389..f6145d6e20c 100644 --- a/sql/item.h +++ b/sql/item.h @@ -410,7 +410,8 @@ public: }; -typedef bool (Item::*Item_processor)(byte *arg); +typedef bool (Item::*Item_processor) (byte *arg); +typedef bool (Item::*Item_analyzer) (byte **argp); typedef Item* (Item::*Item_transformer) (byte *arg); typedef void (*Cond_traverser) (const Item *item, void *arg); @@ -739,6 +740,14 @@ public: return (this->*transformer)(arg); } + virtual Item* compile(Item_analyzer analyzer, byte **arg_p, + Item_transformer transformer, byte *arg_t) + { + if ((this->*analyzer) (arg_p)) + return ((this->*transformer) (arg_t)); + return 0; + } + virtual void traverse_cond(Cond_traverser traverser, void *arg, traverse_order order) { @@ -753,6 +762,12 @@ public: virtual bool change_context_processor(byte *context) { return 0; } virtual bool reset_query_id_processor(byte *query_id) { return 0; } virtual bool is_expensive_processor(byte *arg) { return 0; } + virtual bool subst_argument_checker(byte **arg) + { + if (*arg) + *arg= NULL; + return TRUE; + } virtual Item *equal_fields_propagator(byte * arg) { return this; } virtual Item *set_no_const_sub(byte *arg) { return this; } @@ -1254,6 +1269,7 @@ public: return field->can_be_compared_as_longlong(); } Item_equal *find_item_equal(COND_EQUAL *cond_equal); + bool subst_argument_checker(byte **arg); Item *equal_fields_propagator(byte *arg); Item *set_no_const_sub(byte *arg); Item *replace_equal_field(byte *arg); -- cgit v1.2.1 From a65342f38daf35199c21f366fe9ada98a11f4de9 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 9 Sep 2006 09:43:09 -0700 Subject: Post-pushbuild corrections for fix of bug #21698. --- sql/item.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'sql/item.h') diff --git a/sql/item.h b/sql/item.h index f6145d6e20c..cdd0f863aea 100644 --- a/sql/item.h +++ b/sql/item.h @@ -411,6 +411,17 @@ public: typedef bool (Item::*Item_processor) (byte *arg); +/* + Analyzer function + SYNOPSIS + argp in/out IN: Analysis parameter + OUT: Parameter to be passed to the transformer + + RETURN + TRUE Invoke the transformer + FALSE Don't do it + +*/ typedef bool (Item::*Item_analyzer) (byte **argp); typedef Item* (Item::*Item_transformer) (byte *arg); typedef void (*Cond_traverser) (const Item *item, void *arg); @@ -740,6 +751,22 @@ public: return (this->*transformer)(arg); } + /* + This function performs a generic "compilation" of the Item tree. + The process of compilation is assumed to go as follows: + + compile() + { + if (this->*some_analyzer(...)) + { + compile children if any; + this->*some_transformer(...); + } + } + + i.e. analysis is performed top-down while transformation is done + bottom-up. + */ virtual Item* compile(Item_analyzer analyzer, byte **arg_p, Item_transformer transformer, byte *arg_t) { -- cgit v1.2.1