Skip to content

Commit ffed20c

Browse files
committed
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.
1 parent e174b13 commit ffed20c

File tree

1 file changed

+72
-3
lines changed

1 file changed

+72
-3
lines changed

sql/sql_window.cc

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,9 @@ class Frame_cursor : public Sql_alloc
795795
perform_no_action= true;
796796
}
797797

798+
/* Retrieves the row number that this cursor currently points at. */
799+
virtual ha_rows get_curr_rownum()= 0;
800+
798801
protected:
799802
inline void add_value_to_items()
800803
{
@@ -988,6 +991,11 @@ class Frame_range_n_top : public Frame_cursor
988991
walk_till_non_peer();
989992
}
990993

994+
ha_rows get_curr_rownum()
995+
{
996+
return cursor.get_rownum();
997+
}
998+
991999
private:
9921000
void walk_till_non_peer()
9931001
{
@@ -1110,6 +1118,11 @@ class Frame_range_n_bottom: public Frame_cursor
11101118
walk_till_non_peer();
11111119
}
11121120

1121+
ha_rows get_curr_rownum()
1122+
{
1123+
return cursor.get_rownum();
1124+
}
1125+
11131126
private:
11141127
void walk_till_non_peer()
11151128
{
@@ -1200,6 +1213,11 @@ class Frame_range_current_row_bottom: public Frame_cursor
12001213
walk_till_non_peer();
12011214
}
12021215

1216+
ha_rows get_curr_rownum()
1217+
{
1218+
return cursor.get_rownum();
1219+
}
1220+
12031221
private:
12041222
void walk_till_non_peer()
12051223
{
@@ -1299,6 +1317,11 @@ class Frame_range_current_row_top : public Frame_cursor
12991317
while (1);
13001318
}
13011319
}
1320+
1321+
ha_rows get_curr_rownum()
1322+
{
1323+
return cursor.get_rownum();
1324+
}
13021325
};
13031326

13041327

@@ -1322,15 +1345,25 @@ class Frame_unbounded_preceding : public Frame_cursor
13221345
void next_partition(ha_rows rownum)
13231346
{
13241347
/*
1325-
UNBOUNDED PRECEDING frame end just stays on the first row.
1326-
We are top of the frame, so we don't need to update the sum function.
1348+
UNBOUNDED PRECEDING frame end just stays on the first row of the
1349+
partition. We are top of the frame, so we don't need to update the sum
1350+
function.
13271351
*/
1352+
curr_rownum= rownum;
13281353
}
13291354

13301355
void next_row()
13311356
{
13321357
/* Do nothing, UNBOUNDED PRECEDING frame end doesn't move. */
13331358
}
1359+
1360+
ha_rows get_curr_rownum()
1361+
{
1362+
return curr_rownum;
1363+
}
1364+
1365+
private:
1366+
ha_rows curr_rownum;
13341367
};
13351368

13361369

@@ -1380,6 +1413,11 @@ class Frame_unbounded_following : public Frame_cursor
13801413
{
13811414
/* Do nothing, UNBOUNDED FOLLOWING frame end doesn't move */
13821415
}
1416+
1417+
ha_rows get_curr_rownum()
1418+
{
1419+
return cursor.get_rownum();
1420+
}
13831421
};
13841422

13851423

@@ -1415,6 +1453,11 @@ class Frame_unbounded_following_set_count : public Frame_unbounded_following
14151453
item_with_row_count->set_row_count(num_rows_in_partition);
14161454
}
14171455
}
1456+
1457+
ha_rows get_curr_rownum()
1458+
{
1459+
return cursor.get_rownum();
1460+
}
14181461
};
14191462

14201463
/////////////////////////////////////////////////////////////////////////////
@@ -1492,6 +1535,11 @@ class Frame_n_rows_preceding : public Frame_cursor
14921535
else
14931536
add_value_to_items();
14941537
}
1538+
1539+
ha_rows get_curr_rownum()
1540+
{
1541+
return cursor.get_rownum();
1542+
}
14951543
};
14961544

14971545

@@ -1506,17 +1554,33 @@ class Frame_rows_current_row_bottom : public Frame_cursor
15061554
{
15071555
public:
15081556

1557+
Frame_rows_current_row_bottom() : curr_rownum(0) {}
1558+
15091559
void pre_next_partition(ha_rows rownum)
15101560
{
15111561
add_value_to_items();
15121562
}
1563+
15131564
void next_partition(ha_rows rownum) {}
1565+
15141566
void pre_next_row()
15151567
{
15161568
/* Temp table's current row is current_row. Add it to the window func */
15171569
add_value_to_items();
15181570
}
1519-
void next_row() {};
1571+
1572+
void next_row()
1573+
{
1574+
curr_rownum++;
1575+
};
1576+
1577+
ha_rows get_curr_rownum()
1578+
{
1579+
return curr_rownum;
1580+
}
1581+
1582+
private:
1583+
ha_rows curr_rownum;
15201584
};
15211585

15221586

@@ -1611,6 +1675,11 @@ class Frame_n_rows_following : public Frame_cursor
16111675
next_row_intern();
16121676
}
16131677

1678+
ha_rows get_curr_rownum()
1679+
{
1680+
return cursor.get_rownum();
1681+
}
1682+
16141683
private:
16151684
bool next_row_intern()
16161685
{

0 commit comments

Comments
 (0)