diff options
author | Varun Gupta <varunraiko1803@gmail.com> | 2017-06-27 02:24:32 +0530 |
---|---|---|
committer | Varun Gupta <varunraiko1803@gmail.com> | 2017-11-01 23:13:01 +0530 |
commit | c85552f42b12026f4a1f6c63973601c494b8f8b5 (patch) | |
tree | 4854c1310502cd619bc3a9eb9e0f571bd268f852 /sql/sql_window.cc | |
parent | 31f1541f1e367f6eb91f948c4e814bb6554e6b78 (diff) | |
download | mariadb-git-c85552f42b12026f4a1f6c63973601c494b8f8b5.tar.gz |
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
Diffstat (limited to 'sql/sql_window.cc')
-rw-r--r-- | sql/sql_window.cc | 85 |
1 files changed, 77 insertions, 8 deletions
diff --git a/sql/sql_window.cc b/sql/sql_window.cc index dc8c66120ff..e8925d5f45d 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -908,13 +908,14 @@ private: class Partition_read_cursor : public Table_read_cursor { public: - Partition_read_cursor(THD *thd, SQL_I_List<ORDER> *partition_list) : - bound_tracker(thd, partition_list) {} + Partition_read_cursor(THD *thd, SQL_I_List<ORDER> *partition_list, SQL_I_List<ORDER> *order_list) : + bound_tracker(thd, partition_list), order_tracker(thd, order_list) {} void init(READ_RECORD *info) { Table_read_cursor::init(info); bound_tracker.init(); + order_tracker.init(); end_of_partition= false; } @@ -966,9 +967,39 @@ public: } 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: Group_bound_tracker bound_tracker; + Group_bound_tracker order_tracker; bool end_of_partition; }; @@ -1200,7 +1231,7 @@ public: SQL_I_List<ORDER> *partition_list, SQL_I_List<ORDER> *order_list, 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) { DBUG_ASSERT(order_list->elements == 1); @@ -1339,7 +1370,7 @@ public: SQL_I_List<ORDER> *partition_list, SQL_I_List<ORDER> *order_list, 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) { DBUG_ASSERT(order_list->elements == 1); @@ -1469,7 +1500,7 @@ public: Frame_range_current_row_bottom(THD *thd, SQL_I_List<ORDER> *partition_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 @@ public: Frame_unbounded_following(THD *thd, SQL_I_List<ORDER> *partition_list, SQL_I_List<ORDER> *order_list) : - cursor(thd, partition_list) {} + cursor(thd, partition_list, order_list){} void init(READ_RECORD *info) { @@ -1756,6 +1787,35 @@ public: } }; +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 ///////////////////////////////////////////////////////////////////////////// @@ -1953,7 +2013,7 @@ public: SQL_I_List<ORDER> *order_list, bool is_top_bound_arg, ha_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( */ 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->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); cursor_manager->add_cursor(fc); } |