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_cmpfunc.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 6 deletions(-) (limited to 'sql/item_cmpfunc.cc') diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index dbf380232c4..fa01ae65b0d 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -2747,16 +2747,16 @@ bool Item_cond::walk(Item_processor processor, byte *arg) SYNOPSIS transform() - transformer the transformer callback function to be applied to the nodes - of the tree of the object - arg parameter to be passed to the transformer + transformer the transformer callback function to be applied to the nodes + of the tree of the object + arg parameter to be passed to the transformer DESCRIPTION - The function recursively applies the transform method with the - same transformer to each member item of the condition list. + The function recursively applies the transform method to each + member item of the condition list. If the call of the method for a member item returns a new item the old item is substituted for a new one. - After this the transform method is applied to the root node + After this the transformer is applied to the root node of the Item_cond object. RETURN VALUES @@ -2778,6 +2778,55 @@ Item *Item_cond::transform(Item_transformer transformer, byte *arg) return Item_func::transform(transformer, arg); } + +/* + Compile Item_cond object with a processor and a transformer callback functions + + SYNOPSIS + compile() + analyzer the analyzer callback function to be applied to the nodes + of the tree of the object + arg_p in/out parameter to be passed to the analyzer + transformer the transformer callback function to be applied to the nodes + of the tree of the object + arg_t parameter to be passed to the transformer + + DESCRIPTION + First the function applies the analyzer to the root node of + the Item_func object. Then if the analyzer succeeeds (returns TRUE) + the function recursively applies the compile method to member + item of the condition list. + If the call of the method for a member item returns a new item + the old item is substituted for a new one. + After this the transformer is applied to the root node + of the Item_cond object. + + RETURN VALUES + Item returned as the result of transformation of the root node +*/ + +Item *Item_cond::compile(Item_analyzer analyzer, byte **arg_p, + Item_transformer transformer, byte *arg_t) +{ + if (!(this->*analyzer)(arg_p)) + return 0; + + byte *arg_v= *arg_p; + List_iterator li(list); + Item *item; + while ((item= li++)) + { + /* + The same parameter value of arg_p must be passed + to analyze any argument of the condition formula. + */ + Item *new_item= item->compile(analyzer, &arg_v, transformer, arg_t); + if (new_item && new_item != item) + li.replace(new_item); + } + return Item_func::transform(transformer, arg_t); +} + void Item_cond::traverse_cond(Cond_traverser traverser, void *arg, traverse_order order) { -- 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_cmpfunc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/item_cmpfunc.cc') diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index fa01ae65b0d..3694c01d0aa 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -2811,7 +2811,6 @@ Item *Item_cond::compile(Item_analyzer analyzer, byte **arg_p, if (!(this->*analyzer)(arg_p)) return 0; - byte *arg_v= *arg_p; List_iterator li(list); Item *item; while ((item= li++)) @@ -2820,6 +2819,7 @@ Item *Item_cond::compile(Item_analyzer analyzer, byte **arg_p, The same parameter value of arg_p must be passed to analyze any argument of the condition formula. */ + byte *arg_v= *arg_p; Item *new_item= item->compile(analyzer, &arg_v, transformer, arg_t); if (new_item && new_item != item) li.replace(new_item); -- cgit v1.2.1