From: Jorgen Loland Date: February 9 2011 1:06pm Subject: Re: bzr commit into mysql-trunk branch (jorgen.loland:3605) Bug#59793 List-Archive: http://lists.mysql.com/commits/130861 Message-Id: <4D529144.3080408@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit On 02/08/2011 12:53 PM, Tor Didriksen wrote: >> +Item *Item_func_xor::neg_transformer(THD *thd) >> +{ >> + Item *neg_argument; >> + Item_func_xor *new_item; >> + if ((neg_argument= args[0]->neg_transformer(thd))) >> + // args[0] has neg_tranformer >> + new_item= new Item_func_xor(neg_argument, args[1]); >> + else if ((neg_argument= args[1]->neg_transformer(thd))) >> + // args[0] has neg_tranformer >> + new_item= new Item_func_xor(args[0], neg_argument); >> + else >> + { >> + neg_argument= new Item_func_not(args[0]); >> + new_item= new Item_func_xor(neg_argument, args[1]); > > If you use placement new here, you will save my_pthread_getspecific_ptr, > and since you have the thd here anyways: > > new_item= new (thd->mem_root) Item_func_xor(neg_argument, args[1]); Good suggestion. Thanks. >> + const char *func_name() const { return "xor"; } >> + longlong val_int(); >> + void top_level_item() {} > > Could you explain why you override this virtual function? IIUC, top_level_item() is used to tell an item that it doesn't matter if it returns FALSE or NULL. Consider SELECT ... WHERE cond1 AND cond2; Here Item_cond_and has two conditions, and because WHERE FALSE and WHERE NULL are treated equally, Item_cond_and::val_int() can stop processing and return 0 for this item if any of the operands evaluates to FALSE. That's because this AND is top-level, as in AND / \ cond1 cond2 If the AND is not top level, as in WHERE cond0 OR (cond1 AND cond2) the OR needs to know if AND evaluates to NULL or FALSE: If NULL, the OR is also NULL. If FALSE, OR evaluates to TRUE if cond0 is TRUE. Note that even if it's not a top-level item, AND can still short circuit if either of it's operands turns out to be NULL. Top-level is about whether or not processing can stop when an operand is FALSE. For XOR, a FALSE operand does not mean that processing can be short circuited, hence top_level_item() does nothing. -- Jørgen Løland | Senior Software Engineer | +47 73842138 Oracle MySQL Trondheim, Norway