• Georgi Kodinov's avatar
    Bug#37662 nested if() inside sum() is parsed in exponential time · ae4a35fd
    Georgi Kodinov authored
          
    min() and max() functions are implemented in MySQL as macros.
    This means that max(a,b) is expanded to: ((a) > (b) ? (a) : (b))
    Note how 'a' is quoted two times.
    Now imagine 'a' is a recursive function call that's several 10s of levels deep.
    And the recursive function does max() with a function arg as well to dive into
    recursion.
    This means that simple function call can take most of the clock time.
    Identified and fixed several such calls to max()/min() : including the IF() 
    sql function implementation.
    
    mysql-test/r/func_if.result:
      Bug#37662 test case
    mysql-test/t/func_if.test:
      Bug#37662 test case
    sql/item.cc:
      Bug#37662 don't call expensive functions as arguments to min/max
    sql/item_cmpfunc.cc:
      Bug#37662 don't call expensive functions as arguments to min/max
    sql/item_func.cc:
      Bug#37662 don't call expensive functions as arguments to min/max
    ae4a35fd
item.cc 193 KB