summaryrefslogtreecommitdiff
path: root/sql/sql_window.h
blob: e6a6e6b1e3f3831d32c9a6c6dee1286212e7694d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef SQL_WINDOW_INCLUDED
#define SQL_WINDOW_INCLUDED


#include "my_global.h"
#include "item.h"

class Window_frame_bound : public Sql_alloc
{

public:

  enum Bound_precedence_type
  {
    PRECEDING,
    FOLLOWING
  };

  Bound_precedence_type precedence_type;

  Item *offset;

};


class Window_frame : public Sql_alloc
{

public:

  enum Frame_units
  {
    UNITS_ROWS,
    UNITS_RANGE
  };

  enum Frame_exclusion
  {
    EXCL_NONE,
    EXCL_CURRENT_ROW,
    EXCL_GROUP,
    EXCL_TIES
  };

  Frame_units units;

  Window_frame_bound *top_bound;

  Window_frame_bound *bottom_bound;

  Frame_exclusion exclusion;

  Window_frame(Frame_units win_frame_units,
               Window_frame_bound *win_frame_top_bound,
               Window_frame_bound *win_frame_bottom_bound,
               Frame_exclusion win_frame_exclusion)
    : units(win_frame_units), top_bound(win_frame_top_bound),
      bottom_bound(win_frame_bottom_bound), exclusion(win_frame_exclusion) {}

};

class Window_spec : public Sql_alloc
{
 public:

  LEX_STRING *window_ref;

  SQL_I_List<ORDER> partition_list;

  SQL_I_List<ORDER> order_list;

  Window_frame *window_frame;

  Window_spec(LEX_STRING *win_ref,
              SQL_I_List<ORDER> part_list,
              SQL_I_List<ORDER> ord_list,
              Window_frame *win_frame)
    : window_ref(win_ref), partition_list(part_list), order_list(ord_list),
      window_frame(win_frame) {}
};

class Window_def : public Window_spec
{
 public:

  LEX_STRING *window_name;

  Window_def(LEX_STRING *win_name,
             LEX_STRING *win_ref, 
             SQL_I_List<ORDER> part_list,
             SQL_I_List<ORDER> ord_list,
             Window_frame *win_frame) 
    : Window_spec(win_ref, part_list, ord_list, win_frame),
      window_name(win_name) {}

};

int setup_windows(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
	          List<Item> &fields, List<Item> &all_fields, 
                  List<Window_spec> win_specs);

#endif /* SQL_WINDOW_INCLUDED */