← Back to team overview

maria-developers team mailing list archive

Re: Window functions: why some functions are not in select_lex->window_funcs?

 

This is because of this in sql_yacc.yy:


window_func_expr:
          window_func OVER_SYM window_name
          {
            $$= new (thd->mem_root) Item_window_func(thd, (Item_sum *) $1, $3);
            if ($$ == NULL)
              MYSQL_YYABORT;
          }
        |
          window_func OVER_SYM window_spec
          {
            LEX *lex= Lex;
            if (Select->add_window_spec(thd, lex->win_ref,
                                        Select->group_list,
                                        Select->order_list,
                                        lex->win_frame))
              MYSQL_YYABORT;
            $$= new (thd->mem_root) Item_window_func(thd, (Item_sum *) $1,
                                                      thd->lex->win_spec); 
            if ($$ == NULL)
              MYSQL_YYABORT;
            if (Select->add_window_func((Item_window_func *) $$))
              MYSQL_YYABORT;
^^^^^^^^^^^^^^^^^^^ note that add_window_func call is present in this branch
but not in the other.
          }
        ;

Should I fix this?

On Thu, Mar 24, 2016 at 01:35:38AM +0300, Sergey Petrunia wrote:
> Hello Igor,
> 
> I was trying to move JOIN::process_window_functions() from using
> join->fields_list to using join->select_lex->window_funcs.
> 
> And I discovered that join->select_lex->window_funcs does not contain
> window function items that use window definition.  Is this intentional?
> 
> Example:
> 
> 
> create table t0 (a int);
> insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
> create table t1 (pk int, c int);
> insert into t1 select a+1,1 from t0;
> update t1 set c=2 where pk not in (1,2,3,4);
> 
> select  pk, c, 
>   count(*) over 
>   (partition by c order by pk  rows between 2 preceding and 2 following) as CNT
> from t1 
> 
> Here:
> 
>   #1  0x0000555555af5db6 in AGGR_OP::end_send (this=0x7fff4c0086c8)
> (gdb) p join->select_lex->window_funcs
>   $69 = {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x7fff4c005d18, last = 0x7fff4c005d18, elements = 1}, <No data fields>}
>  
> 
> But:
> 
> select  pk, c, 
>   count(*) over w1 as CNT 
> from t1 
> window w1 as (partition by c order by pk  rows between 2 preceding and 2 following);
> 
> 
> (gdb) p join->select_lex->window_funcs
>   $74 = {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x555556d48820, last = 0x55555ab10b70, elements = 0}, <No data fields>}
> 
> BR
>  Sergei
> -- 
> Sergei Petrunia, Software Developer
> MariaDB Corporation | Skype: sergefp | Blog: http://s.petrunia.net/blog
> 
> 

-- 
BR
 Sergei
-- 
Sergei Petrunia, Software Developer
MariaDB Corporation | Skype: sergefp | Blog: http://s.petrunia.net/blog




References