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
d70dac20
Commit
d70dac20
authored
Aug 07, 2019
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-20278 PERCENTILE_DISC() returns a wrong data type
parent
e978efd9
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
256 additions
and
115 deletions
+256
-115
mysql-test/main/win_percentile.result
mysql-test/main/win_percentile.result
+183
-98
mysql-test/main/win_percentile.test
mysql-test/main/win_percentile.test
+63
-0
sql/item_windowfunc.cc
sql/item_windowfunc.cc
+10
-2
sql/item_windowfunc.h
sql/item_windowfunc.h
+0
-11
sql/sql_type.h
sql/sql_type.h
+0
-4
No files found.
mysql-test/main/win_percentile.result
View file @
d70dac20
This diff is collapsed.
Click to expand it.
mysql-test/main/win_percentile.test
View file @
d70dac20
...
...
@@ -146,3 +146,66 @@ select * from v1;
select
median
(
val
)
OVER
()
FROM
t1
;
drop
table
t1
;
drop
view
v1
;
--
echo
#
--
echo
# MDEV-20278 PERCENTILE_DISC() returns a wrong data type
--
echo
#
--
echo
# INT variants
CREATE
TABLE
t1
(
name
CHAR
(
30
),
star_rating
INT
);
INSERT
INTO
t1
VALUES
(
'Lord of the Ladybirds'
,
5
);
INSERT
INTO
t1
VALUES
(
'Lord of the Ladybirds'
,
3
);
INSERT
INTO
t1
VALUES
(
'Lady of the Flies'
,
1
);
INSERT
INTO
t1
VALUES
(
'Lady of the Flies'
,
2
);
INSERT
INTO
t1
VALUES
(
'Lady of the Flies'
,
5
);
CREATE
OR
REPLACE
TABLE
t2
AS
SELECT
name
,
PERCENTILE_DISC
(
0.5
)
WITHIN
GROUP
(
ORDER
BY
star_rating
)
OVER
(
PARTITION
BY
name
)
AS
pc
FROM
t1
;
SHOW
CREATE
TABLE
t2
;
DROP
TABLE
t2
,
t1
;
--
echo
# UNSIGNED INT variants
CREATE
OR
REPLACE
TABLE
t1
(
name
CHAR
(
30
),
star_rating
BIGINT
UNSIGNED
);
INSERT
INTO
t1
VALUES
(
'Lord of the Ladybirds'
,
0x8000000000000005
);
INSERT
INTO
t1
VALUES
(
'Lord of the Ladybirds'
,
0x8000000000000003
);
INSERT
INTO
t1
VALUES
(
'Lady of the Flies'
,
0x8000000000000001
);
INSERT
INTO
t1
VALUES
(
'Lady of the Flies'
,
0x8000000000000002
);
INSERT
INTO
t1
VALUES
(
'Lady of the Flies'
,
0x8000000000000003
);
CREATE
OR
REPLACE
TABLE
t2
AS
SELECT
name
,
PERCENTILE_DISC
(
0.5
)
WITHIN
GROUP
(
ORDER
BY
star_rating
)
OVER
(
PARTITION
BY
name
)
AS
pc
FROM
t1
;
SHOW
CREATE
TABLE
t2
;
SELECT
name
,
pc
,
HEX
(
pc
)
FROM
t2
ORDER
BY
name
,
pc
;
DROP
TABLE
t2
,
t1
;
--
echo
# FLOAT variants
CREATE
TABLE
t1
(
name
CHAR
(
30
),
star_rating
FLOAT
);
INSERT
INTO
t1
VALUES
(
'Lord of the Ladybirds'
,
5
);
INSERT
INTO
t1
VALUES
(
'Lord of the Ladybirds'
,
3
);
INSERT
INTO
t1
VALUES
(
'Lady of the Flies'
,
1
);
INSERT
INTO
t1
VALUES
(
'Lady of the Flies'
,
2
);
INSERT
INTO
t1
VALUES
(
'Lady of the Flies'
,
5
);
CREATE
TABLE
t2
AS
SELECT
name
,
PERCENTILE_DISC
(
0.5
)
WITHIN
GROUP
(
ORDER
BY
star_rating
)
OVER
(
PARTITION
BY
name
)
AS
pc
FROM
t1
;
SHOW
CREATE
TABLE
t2
;
DROP
TABLE
t2
,
t1
;
--
echo
# DECIMAL variants
CREATE
OR
REPLACE
TABLE
t1
(
name
CHAR
(
30
),
star_rating
DECIMAL
(
30
,
2
));
INSERT
INTO
t1
VALUES
(
'Lord of the Ladybirds'
,
50000000000
);
INSERT
INTO
t1
VALUES
(
'Lord of the Ladybirds'
,
30000000000
);
INSERT
INTO
t1
VALUES
(
'Lady of the Flies'
,
10000000000
);
INSERT
INTO
t1
VALUES
(
'Lady of the Flies'
,
20000000000
);
INSERT
INTO
t1
VALUES
(
'Lady of the Flies'
,
50000000000
);
CREATE
OR
REPLACE
TABLE
t2
AS
SELECT
name
,
PERCENTILE_DISC
(
0.5
)
WITHIN
GROUP
(
ORDER
BY
star_rating
)
OVER
(
PARTITION
BY
name
)
AS
pc
FROM
t1
;
SHOW
CREATE
TABLE
t2
;
SELECT
*
FROM
t2
ORDER
BY
name
,
pc
;
DROP
TABLE
t2
,
t1
;
sql/item_windowfunc.cc
View file @
d70dac20
...
...
@@ -174,7 +174,8 @@ bool Item_window_func::check_result_type_of_order_item()
{
if
(
only_single_element_order_list
())
{
Item_result
rtype
=
window_spec
->
order_list
->
first
->
item
[
0
]
->
cmp_type
();
Item
*
src_item
=
window_spec
->
order_list
->
first
->
item
[
0
];
Item_result
rtype
=
src_item
->
cmp_type
();
// TODO (varun) : support date type in percentile_cont function
if
(
rtype
!=
REAL_RESULT
&&
rtype
!=
INT_RESULT
&&
rtype
!=
DECIMAL_RESULT
&&
rtype
!=
TIME_RESULT
)
...
...
@@ -182,7 +183,14 @@ bool Item_window_func::check_result_type_of_order_item()
my_error
(
ER_WRONG_TYPE_FOR_PERCENTILE_FUNC
,
MYF
(
0
),
window_func
()
->
func_name
());
return
TRUE
;
}
setting_handler_for_percentile_functions
(
rtype
);
if
(
window_func
()
->
sum_func
()
==
Item_sum
::
PERCENTILE_DISC_FUNC
)
{
Item_sum_percentile_disc
*
func
=
static_cast
<
Item_sum_percentile_disc
*>
(
window_func
());
func
->
set_handler
(
src_item
->
type_handler
());
func
->
Type_std_attributes
::
set
(
src_item
);
Type_std_attributes
::
set
(
src_item
);
}
}
return
FALSE
;
}
...
...
sql/item_windowfunc.h
View file @
d70dac20
...
...
@@ -1097,17 +1097,6 @@ class Item_window_func : public Item_func_or_sum
}
}
void
setting_handler_for_percentile_functions
(
Item_result
rtype
)
const
{
switch
(
window_func
()
->
sum_func
()){
case
Item_sum
:
:
PERCENTILE_DISC_FUNC
:
((
Item_sum_percentile_disc
*
)
window_func
())
->
set_handler_by_cmp_type
(
rtype
);
break
;
default:
return
;
}
}
bool
check_result_type_of_order_item
();
...
...
sql/sql_type.h
View file @
d70dac20
...
...
@@ -3506,10 +3506,6 @@ class Type_handler_hybrid_field_type
{
return
(
m_type_handler
=
Type_handler
::
get_handler_by_result_type
(
type
));
}
const
Type_handler
*
set_handler_by_cmp_type
(
Item_result
type
)
{
return
(
m_type_handler
=
Type_handler
::
get_handler_by_cmp_type
(
type
));
}
const
Type_handler
*
set_handler_by_result_type
(
Item_result
type
,
uint
max_octet_length
,
CHARSET_INFO
*
cs
)
...
...
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