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
9a673e0a
Commit
9a673e0a
authored
Feb 16, 2016
by
Vicențiu Ciorbaru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement DENSE_RANK function.
parent
c30119ad
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
5 deletions
+99
-5
mysql-test/r/win.result
mysql-test/r/win.result
+43
-0
mysql-test/t/win.test
mysql-test/t/win.test
+26
-0
sql/item_windowfunc.cc
sql/item_windowfunc.cc
+18
-0
sql/item_windowfunc.h
sql/item_windowfunc.h
+12
-5
No files found.
mysql-test/r/win.result
View file @
9a673e0a
...
@@ -92,3 +92,46 @@ pk a rank() over (order by a)
...
@@ -92,3 +92,46 @@ pk a rank() over (order by a)
9 4 9
9 4 9
10 4 9
10 4 9
drop table t2;
drop table t2;
#
# Try DENSE_RANK() function
#
create table t3 (
pk int primary key,
a int,
b int
);
insert into t3 values
( 1 , 0, 10),
( 2 , 0, 10),
( 3 , 1, 10),
( 4 , 1, 10),
( 8 , 2, 10),
( 5 , 2, 20),
( 6 , 2, 20),
( 7 , 2, 20),
( 9 , 4, 20),
(10 , 4, 20);
select pk, a, b, rank() over (order by a), dense_rank() over (order by a) from t3;
pk a b rank() over (order by a) dense_rank() over (order by a)
1 0 10 1 1
2 0 10 1 1
3 1 10 3 2
4 1 10 3 2
8 2 10 5 3
5 2 20 5 3
6 2 20 5 3
7 2 20 5 3
9 4 20 9 4
10 4 20 9 4
select pk, a, b, rank() over (partition by b order by a), dense_rank() over (partition by b order by a) from t3;
pk a b rank() over (partition by b order by a) dense_rank() over (partition by b order by a)
1 0 10 1 1
2 0 10 1 1
3 1 10 3 2
4 1 10 3 2
8 2 10 5 3
5 2 20 1 1
6 2 20 1 1
7 2 20 1 1
9 4 20 4 2
10 4 20 4 2
mysql-test/t/win.test
View file @
9a673e0a
...
@@ -85,3 +85,29 @@ select pk, a, rank() over (order by a) from t2;
...
@@ -85,3 +85,29 @@ select pk, a, rank() over (order by a) from t2;
drop
table
t2
;
drop
table
t2
;
--
echo
#
--
echo
# Try DENSE_RANK() function
--
echo
#
create
table
t3
(
pk
int
primary
key
,
a
int
,
b
int
);
insert
into
t3
values
(
1
,
0
,
10
),
(
2
,
0
,
10
),
(
3
,
1
,
10
),
(
4
,
1
,
10
),
(
8
,
2
,
10
),
(
5
,
2
,
20
),
(
6
,
2
,
20
),
(
7
,
2
,
20
),
(
9
,
4
,
20
),
(
10
,
4
,
20
);
select
pk
,
a
,
b
,
rank
()
over
(
order
by
a
),
dense_rank
()
over
(
order
by
a
)
from
t3
;
select
pk
,
a
,
b
,
rank
()
over
(
partition
by
b
order
by
a
),
dense_rank
()
over
(
partition
by
b
order
by
a
)
from
t3
;
drop
table
tr
;
sql/item_windowfunc.cc
View file @
9a673e0a
...
@@ -55,6 +55,24 @@ void Item_sum_rank::setup_window_func(THD *thd, Window_spec *window_spec)
...
@@ -55,6 +55,24 @@ void Item_sum_rank::setup_window_func(THD *thd, Window_spec *window_spec)
clear
();
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
);
}
clear
();
}
bool
Item_sum_dense_rank
::
add
()
{
if
(
test_if_group_changed
(
orderby_fields
)
>
-
1
)
dense_rank
++
;
return
false
;
}
bool
Item_sum_rank
::
add
()
bool
Item_sum_rank
::
add
()
{
{
...
...
sql/item_windowfunc.h
View file @
9a673e0a
...
@@ -135,7 +135,7 @@ class Item_sum_rank: public Item_sum_int
...
@@ -135,7 +135,7 @@ class Item_sum_rank: public Item_sum_int
/*
/*
RANK() OVER (...) Windowing function
DENSE_
RANK() OVER (...) Windowing function
@detail
@detail
- This is a Window function (not just an aggregate)
- This is a Window function (not just an aggregate)
...
@@ -156,11 +156,16 @@ class Item_sum_rank: public Item_sum_int
...
@@ -156,11 +156,16 @@ class Item_sum_rank: public Item_sum_int
class
Item_sum_dense_rank
:
public
Item_sum_int
class
Item_sum_dense_rank
:
public
Item_sum_int
{
{
longlong
dense_rank
;
longlong
dense_rank
;
List
<
Cached_item
>
orderby_fields
;
/* TODO: implementation is missing */
/* TODO: implementation is missing */
void
clear
()
{}
void
clear
()
{
bool
add
()
{
return
false
;
}
dense_rank
=
1
;
}
bool
add
();
void
update_field
()
{}
void
update_field
()
{}
longlong
val_int
()
{
return
dense_rank
;
}
public:
public:
Item_sum_dense_rank
(
THD
*
thd
)
Item_sum_dense_rank
(
THD
*
thd
)
...
@@ -174,7 +179,9 @@ class Item_sum_dense_rank: public Item_sum_int
...
@@ -174,7 +179,9 @@ class Item_sum_dense_rank: public Item_sum_int
{
{
return
"dense_rank"
;
return
"dense_rank"
;
}
}
void
setup_window_func
(
THD
*
thd
,
Window_spec
*
window_spec
);
};
};
...
...
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