Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
8d1f8e88
Commit
8d1f8e88
authored
Mar 23, 2016
by
Igor Babaev
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bb-10.2-mdev9543' of github.com:MariaDB/server into bb-10.2-mdev9543
parents
82cb35be
d8b8b5af
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
62 deletions
+74
-62
sql/item_windowfunc.cc
sql/item_windowfunc.cc
+7
-19
sql/item_windowfunc.h
sql/item_windowfunc.h
+67
-3
sql/sql_window.cc
sql/sql_window.cc
+0
-40
No files found.
sql/item_windowfunc.cc
View file @
8d1f8e88
...
...
@@ -178,29 +178,21 @@ void Item_window_func::setup_partition_border_check(THD *thd)
void
Item_sum_rank
::
setup_window_func
(
THD
*
thd
,
Window_spec
*
window_spec
)
{
/* TODO: move this into Item_window_func? */
for
(
ORDER
*
curr
=
window_spec
->
order_list
->
first
;
curr
;
curr
=
curr
->
next
)
{
Cached_item
*
tmp
=
new_Cached_item
(
thd
,
curr
->
item
[
0
],
TRUE
);
orderby_fields
.
push_back
(
tmp
);
}
peer_tracker
.
init
(
thd
,
window_spec
->
order_list
);
clear
();
}
void
Item_sum_dense_rank
::
setup_window_func
(
THD
*
thd
,
Window_spec
*
window_spec
)
{
/* TODO: consider moving this && Item_sum_rank's implementation */
for
(
ORDER
*
curr
=
window_spec
->
order_list
->
first
;
curr
;
curr
=
curr
->
next
)
{
Cached_item
*
tmp
=
new_Cached_item
(
thd
,
curr
->
item
[
0
],
TRUE
);
orderby_fields
.
push_back
(
tmp
);
}
peer_tracker
.
init
(
thd
,
window_spec
->
order_list
);
clear
();
}
bool
Item_sum_dense_rank
::
add
()
{
if
(
test_if_group_changed
(
orderby_fields
)
>
-
1
)
dense_rank
++
;
if
(
peer_tracker
.
check_if_next_group
()
)
dense_rank
++
;
return
false
;
}
...
...
@@ -209,7 +201,7 @@ bool Item_sum_dense_rank::add()
bool
Item_sum_rank
::
add
()
{
row_number
++
;
if
(
test_if_group_changed
(
orderby_fields
)
>
-
1
)
if
(
peer_tracker
.
check_if_next_group
()
)
{
/* Row value changed */
cur_rank
=
row_number
;
...
...
@@ -237,7 +229,7 @@ void Item_window_func::advance_window()
bool
Item_sum_percent_rank
::
add
()
{
row_number
++
;
if
(
test_if_group_changed
(
orderby_fields
)
>
-
1
)
if
(
peer_tracker
.
check_if_next_group
()
)
{
/* Row value changed. */
cur_rank
=
row_number
;
...
...
@@ -248,11 +240,7 @@ bool Item_sum_percent_rank::add()
void
Item_sum_percent_rank
::
setup_window_func
(
THD
*
thd
,
Window_spec
*
window_spec
)
{
/* TODO: move this into Item_window_func? */
for
(
ORDER
*
curr
=
window_spec
->
order_list
->
first
;
curr
;
curr
=
curr
->
next
)
{
Cached_item
*
tmp
=
new_Cached_item
(
thd
,
curr
->
item
[
0
],
TRUE
);
orderby_fields
.
push_back
(
tmp
);
}
peer_tracker
.
init
(
thd
,
window_spec
->
order_list
);
clear
();
}
...
...
sql/item_windowfunc.h
View file @
8d1f8e88
...
...
@@ -6,6 +6,54 @@
class
Window_spec
;
int
test_if_group_changed
(
List
<
Cached_item
>
&
list
);
/* A wrapper around test_if_group_changed */
class
Group_bound_tracker
{
List
<
Cached_item
>
group_fields
;
public:
void
init
(
THD
*
thd
,
SQL_I_List
<
ORDER
>
*
list
)
{
for
(
ORDER
*
curr
=
list
->
first
;
curr
;
curr
=
curr
->
next
)
{
Cached_item
*
tmp
=
new_Cached_item
(
thd
,
curr
->
item
[
0
],
TRUE
);
group_fields
.
push_back
(
tmp
);
}
}
void
cleanup
()
{
group_fields
.
empty
();
}
/*
Check if the current row is in a different group than the previous row
this function was called for.
The new row's group becomes the current row's group.
*/
bool
check_if_next_group
()
{
if
(
test_if_group_changed
(
group_fields
)
>
-
1
)
return
true
;
return
false
;
}
int
compare_with_cache
()
{
List_iterator
<
Cached_item
>
li
(
group_fields
);
Cached_item
*
ptr
;
int
res
;
while
((
ptr
=
li
++
))
{
if
((
res
=
ptr
->
cmp_read_only
()))
return
res
;
}
return
0
;
}
};
/*
ROW_NUMBER() OVER (...)
...
...
@@ -74,7 +122,7 @@ class Item_sum_rank: public Item_sum_int
longlong
row_number
;
// just ROW_NUMBER()
longlong
cur_rank
;
// current value
List
<
Cached_item
>
orderby_fields
;
Group_bound_tracker
peer_tracker
;
public:
void
clear
()
{
...
...
@@ -111,6 +159,11 @@ class Item_sum_rank: public Item_sum_int
}
void
setup_window_func
(
THD
*
thd
,
Window_spec
*
window_spec
);
void
cleanup
()
{
peer_tracker
.
cleanup
();
Item_sum_int
::
cleanup
();
}
};
...
...
@@ -136,7 +189,7 @@ class Item_sum_rank: public Item_sum_int
class
Item_sum_dense_rank
:
public
Item_sum_int
{
longlong
dense_rank
;
List
<
Cached_item
>
orderby_fields
;
Group_bound_tracker
peer_tracker
;
/*
XXX(cvicentiu) This class could potentially be implemented in the rank
class, with a switch for the DENSE case.
...
...
@@ -167,6 +220,11 @@ class Item_sum_dense_rank: public Item_sum_int
void
setup_window_func
(
THD
*
thd
,
Window_spec
*
window_spec
);
void
cleanup
()
{
peer_tracker
.
cleanup
();
Item_sum_int
::
cleanup
();
}
};
/* TODO-cvicentiu
...
...
@@ -365,7 +423,13 @@ class Item_sum_percent_rank: public Item_sum_window_with_context,
longlong
cur_rank
;
// Current rank of the current row.
longlong
row_number
;
// Value if this were ROW_NUMBER() function.
List
<
Cached_item
>
orderby_fields
;
Group_bound_tracker
peer_tracker
;
void
cleanup
()
{
peer_tracker
.
cleanup
();
Item_sum_window_with_context
::
cleanup
();
}
/* Helper function so that we don't cast the context every time. */
Window_context_row_count
*
get_context_
()
...
...
sql/sql_window.cc
View file @
8d1f8e88
...
...
@@ -387,46 +387,6 @@ class Table_read_cursor : public Rowid_seq_cursor
/////////////////////////////////////////////////////////////////////////////
/* A wrapper around test_if_group_changed */
class
Group_bound_tracker
{
List
<
Cached_item
>
group_fields
;
public:
void
init
(
THD
*
thd
,
SQL_I_List
<
ORDER
>
*
list
)
{
for
(
ORDER
*
curr
=
list
->
first
;
curr
;
curr
=
curr
->
next
)
{
Cached_item
*
tmp
=
new_Cached_item
(
thd
,
curr
->
item
[
0
],
TRUE
);
group_fields
.
push_back
(
tmp
);
}
}
/*
Check if the current row is in a different group than the previous row
this function was called for.
The new row's group becomes the current row's group.
*/
bool
check_if_next_group
()
{
if
(
test_if_group_changed
(
group_fields
)
>
-
1
)
return
true
;
return
false
;
}
int
compare_with_cache
()
{
List_iterator
<
Cached_item
>
li
(
group_fields
);
Cached_item
*
ptr
;
int
res
;
while
((
ptr
=
li
++
))
{
if
((
res
=
ptr
->
cmp_read_only
()))
return
res
;
}
return
0
;
}
};
/*
Window frame bound cursor. Abstract interface.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment