Commit c85552f4 authored by Varun Gupta's avatar Varun Gupta

Added a class Frame_unbounded_following_set_count_special, which is required to ignore

all the null values while calculating the number of rows in the partition
parent 31f1541f
...@@ -908,13 +908,14 @@ class Table_read_cursor : public Rowid_seq_cursor ...@@ -908,13 +908,14 @@ class Table_read_cursor : public Rowid_seq_cursor
class Partition_read_cursor : public Table_read_cursor class Partition_read_cursor : public Table_read_cursor
{ {
public: public:
Partition_read_cursor(THD *thd, SQL_I_List<ORDER> *partition_list) : Partition_read_cursor(THD *thd, SQL_I_List<ORDER> *partition_list, SQL_I_List<ORDER> *order_list) :
bound_tracker(thd, partition_list) {} bound_tracker(thd, partition_list), order_tracker(thd, order_list) {}
void init(READ_RECORD *info) void init(READ_RECORD *info)
{ {
Table_read_cursor::init(info); Table_read_cursor::init(info);
bound_tracker.init(); bound_tracker.init();
order_tracker.init();
end_of_partition= false; end_of_partition= false;
} }
...@@ -966,9 +967,39 @@ class Partition_read_cursor : public Table_read_cursor ...@@ -966,9 +967,39 @@ class Partition_read_cursor : public Table_read_cursor
} }
return 0; return 0;
} }
bool next_func(ha_rows *counter)
{
if (next())
return true;
if (!check_for_null_row())
{
(*counter)++;
}
return false;
}
bool fetch_func(ha_rows *counter)
{
if (fetch())
return true;
if (!check_for_null_row())
{
(*counter)++;
}
return false;
}
bool check_for_null_row()
{
if (!end_of_partition)
{
if (order_tracker.compare_with_cache_for_null_values())
return true;
}
return false;
}
private: private:
Group_bound_tracker bound_tracker; Group_bound_tracker bound_tracker;
Group_bound_tracker order_tracker;
bool end_of_partition; bool end_of_partition;
}; };
...@@ -1200,7 +1231,7 @@ class Frame_range_n_top : public Frame_cursor ...@@ -1200,7 +1231,7 @@ class Frame_range_n_top : public Frame_cursor
SQL_I_List<ORDER> *partition_list, SQL_I_List<ORDER> *partition_list,
SQL_I_List<ORDER> *order_list, SQL_I_List<ORDER> *order_list,
bool is_preceding_arg, Item *n_val_arg) : bool is_preceding_arg, Item *n_val_arg) :
cursor(thd, partition_list), n_val(n_val_arg), item_add(NULL), cursor(thd, partition_list, NULL), n_val(n_val_arg), item_add(NULL),
is_preceding(is_preceding_arg) is_preceding(is_preceding_arg)
{ {
DBUG_ASSERT(order_list->elements == 1); DBUG_ASSERT(order_list->elements == 1);
...@@ -1339,7 +1370,7 @@ class Frame_range_n_bottom: public Frame_cursor ...@@ -1339,7 +1370,7 @@ class Frame_range_n_bottom: public Frame_cursor
SQL_I_List<ORDER> *partition_list, SQL_I_List<ORDER> *partition_list,
SQL_I_List<ORDER> *order_list, SQL_I_List<ORDER> *order_list,
bool is_preceding_arg, Item *n_val_arg) : bool is_preceding_arg, Item *n_val_arg) :
cursor(thd, partition_list), n_val(n_val_arg), item_add(NULL), cursor(thd, partition_list, NULL), n_val(n_val_arg), item_add(NULL),
is_preceding(is_preceding_arg), added_values(false) is_preceding(is_preceding_arg), added_values(false)
{ {
DBUG_ASSERT(order_list->elements == 1); DBUG_ASSERT(order_list->elements == 1);
...@@ -1469,7 +1500,7 @@ class Frame_range_current_row_bottom: public Frame_cursor ...@@ -1469,7 +1500,7 @@ class Frame_range_current_row_bottom: public Frame_cursor
Frame_range_current_row_bottom(THD *thd, Frame_range_current_row_bottom(THD *thd,
SQL_I_List<ORDER> *partition_list, SQL_I_List<ORDER> *partition_list,
SQL_I_List<ORDER> *order_list) : SQL_I_List<ORDER> *order_list) :
cursor(thd, partition_list), peer_tracker(thd, order_list) cursor(thd, partition_list, NULL), peer_tracker(thd, order_list)
{ {
} }
...@@ -1684,7 +1715,7 @@ class Frame_unbounded_following : public Frame_cursor ...@@ -1684,7 +1715,7 @@ class Frame_unbounded_following : public Frame_cursor
Frame_unbounded_following(THD *thd, Frame_unbounded_following(THD *thd,
SQL_I_List<ORDER> *partition_list, SQL_I_List<ORDER> *partition_list,
SQL_I_List<ORDER> *order_list) : SQL_I_List<ORDER> *order_list) :
cursor(thd, partition_list) {} cursor(thd, partition_list, order_list){}
void init(READ_RECORD *info) void init(READ_RECORD *info)
{ {
...@@ -1756,6 +1787,35 @@ class Frame_unbounded_following_set_count : public Frame_unbounded_following ...@@ -1756,6 +1787,35 @@ class Frame_unbounded_following_set_count : public Frame_unbounded_following
} }
}; };
class Frame_unbounded_following_set_count_special : public Frame_unbounded_following_set_count
{
public:
Frame_unbounded_following_set_count_special(
THD *thd,
SQL_I_List<ORDER> *partition_list, SQL_I_List<ORDER> *order_list) :
Frame_unbounded_following_set_count(thd, partition_list, order_list)
{}
void next_partition(ha_rows rownum)
{
ha_rows num_rows_in_partition= 0;
if (cursor.fetch_func(&num_rows_in_partition))
return;
/* Walk to the end of the partition, find how many rows there are. */
while (!cursor.next_func(&num_rows_in_partition));
List_iterator_fast<Item_sum> it(sum_functions);
Item_sum* item;
while ((item= it++))
{
Item_sum_window_with_row_count* item_with_row_count =
static_cast<Item_sum_window_with_row_count *>(item);
item_with_row_count->set_row_count(num_rows_in_partition);
}
}
};
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ROWS-type frame bounds // ROWS-type frame bounds
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
...@@ -1953,7 +2013,7 @@ class Frame_n_rows_following : public Frame_cursor ...@@ -1953,7 +2013,7 @@ class Frame_n_rows_following : public Frame_cursor
SQL_I_List<ORDER> *order_list, SQL_I_List<ORDER> *order_list,
bool is_top_bound_arg, ha_rows n_rows_arg) : bool is_top_bound_arg, ha_rows n_rows_arg) :
is_top_bound(is_top_bound_arg), n_rows(n_rows_arg), is_top_bound(is_top_bound_arg), n_rows(n_rows_arg),
cursor(thd, partition_list) cursor(thd, partition_list, NULL)
{ {
} }
...@@ -2564,9 +2624,18 @@ void get_window_functions_required_cursors( ...@@ -2564,9 +2624,18 @@ void get_window_functions_required_cursors(
*/ */
if (item_win_func->requires_partition_size()) if (item_win_func->requires_partition_size())
{ {
fc= new Frame_unbounded_following_set_count(thd, if (item_win_func->only_single_element_order_list())
{
fc= new Frame_unbounded_following_set_count_special(thd,
item_win_func->window_spec->partition_list, item_win_func->window_spec->partition_list,
item_win_func->window_spec->order_list); item_win_func->window_spec->order_list);
}
else
{
fc= new Frame_unbounded_following_set_count(thd,
item_win_func->window_spec->partition_list,
item_win_func->window_spec->order_list);
}
fc->add_sum_func(sum_func); fc->add_sum_func(sum_func);
cursor_manager->add_cursor(fc); cursor_manager->add_cursor(fc);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment