[Commits] 7d70404: Extend Frame_cursor to report the current row it is pointing at

vicentiu vicentiu at mariadb.org
Wed Sep 7 22:39:36 EEST 2016


revision-id: 7d7040460039aad820f4a97471eea18b1205c583 (mariadb-10.2.1-25-g7d70404)
parent(s): 967b22a7a46688f25194ba29844e01ab9c253565
author: Vicențiu Ciorbaru
committer: Vicențiu Ciorbaru
timestamp: 2016-09-07 22:36:47 +0300
message:

Extend Frame_cursor to report the current row it is pointing at

Added an extra virtual method to the Frame_cursor class to allow cursors
to report the row number to which they are pointing.

---
 sql/sql_window.cc | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 72 insertions(+), 3 deletions(-)

diff --git a/sql/sql_window.cc b/sql/sql_window.cc
index 6a7084e..a2e793f 100644
--- a/sql/sql_window.cc
+++ b/sql/sql_window.cc
@@ -795,6 +795,9 @@ class Frame_cursor : public Sql_alloc
     perform_no_action= true;
   }
 
+  /* Retrieves the row number that this cursor currently points at. */
+  virtual ha_rows get_curr_rownum()= 0;
+
 protected:
   inline void add_value_to_items()
   {
@@ -988,6 +991,11 @@ class Frame_range_n_top : public Frame_cursor
     walk_till_non_peer();
   }
 
+  ha_rows get_curr_rownum()
+  {
+    return cursor.get_rownum();
+  }
+
 private:
   void walk_till_non_peer()
   {
@@ -1110,6 +1118,11 @@ class Frame_range_n_bottom: public Frame_cursor
     walk_till_non_peer();
   }
 
+  ha_rows get_curr_rownum()
+  {
+    return cursor.get_rownum();
+  }
+
 private:
   void walk_till_non_peer()
   {
@@ -1200,6 +1213,11 @@ class Frame_range_current_row_bottom: public Frame_cursor
     walk_till_non_peer();
   }
 
+  ha_rows get_curr_rownum()
+  {
+    return cursor.get_rownum();
+  }
+
 private:
   void walk_till_non_peer()
   {
@@ -1299,6 +1317,11 @@ class Frame_range_current_row_top : public Frame_cursor
       while (1);
     }
   }
+
+  ha_rows get_curr_rownum()
+  {
+    return cursor.get_rownum();
+  }
 };
 
 
@@ -1322,15 +1345,25 @@ class Frame_unbounded_preceding : public Frame_cursor
   void next_partition(ha_rows rownum)
   {
     /*
-      UNBOUNDED PRECEDING frame end just stays on the first row.
-      We are top of the frame, so we don't need to update the sum function.
+      UNBOUNDED PRECEDING frame end just stays on the first row of the
+      partition. We are top of the frame, so we don't need to update the sum
+      function.
     */
+    curr_rownum= rownum;
   }
 
   void next_row()
   {
     /* Do nothing, UNBOUNDED PRECEDING frame end doesn't move. */
   }
+
+  ha_rows get_curr_rownum()
+  {
+    return curr_rownum;
+  }
+
+private:
+  ha_rows curr_rownum;
 };
 
 
@@ -1380,6 +1413,11 @@ class Frame_unbounded_following : public Frame_cursor
   {
     /* Do nothing, UNBOUNDED FOLLOWING frame end doesn't move */
   }
+
+  ha_rows get_curr_rownum()
+  {
+    return cursor.get_rownum();
+  }
 };
 
 
@@ -1415,6 +1453,11 @@ class Frame_unbounded_following_set_count : public Frame_unbounded_following
       item_with_row_count->set_row_count(num_rows_in_partition);
     }
   }
+
+  ha_rows get_curr_rownum()
+  {
+    return cursor.get_rownum();
+  }
 };
 
 /////////////////////////////////////////////////////////////////////////////
@@ -1492,6 +1535,11 @@ class Frame_n_rows_preceding : public Frame_cursor
     else
       add_value_to_items();
   }
+
+  ha_rows get_curr_rownum()
+  {
+    return cursor.get_rownum();
+  }
 };
 
 
@@ -1506,17 +1554,33 @@ class Frame_rows_current_row_bottom : public Frame_cursor
 {
 public:
 
+  Frame_rows_current_row_bottom() : curr_rownum(0) {}
+
   void pre_next_partition(ha_rows rownum)
   {
     add_value_to_items();
   }
+
   void next_partition(ha_rows rownum) {}
+
   void pre_next_row()
   {
     /* Temp table's current row is current_row. Add it to the window func */
     add_value_to_items();
   }
-  void next_row() {};
+
+  void next_row()
+  {
+    curr_rownum++;
+  };
+
+  ha_rows get_curr_rownum()
+  {
+    return curr_rownum;
+  }
+
+private:
+  ha_rows curr_rownum;
 };
 
 
@@ -1611,6 +1675,11 @@ class Frame_n_rows_following : public Frame_cursor
     next_row_intern();
   }
 
+  ha_rows get_curr_rownum()
+  {
+    return cursor.get_rownum();
+  }
+
 private:
   bool next_row_intern()
   {


More information about the commits mailing list