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
ed61fddf
Commit
ed61fddf
authored
Jun 21, 2017
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext
parents
3a7201ea
0992be92
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
181 additions
and
2 deletions
+181
-2
mysql-test/r/win_insert_select.result
mysql-test/r/win_insert_select.result
+97
-0
mysql-test/t/win_insert_select.test
mysql-test/t/win_insert_select.test
+79
-0
sql/sql_base.cc
sql/sql_base.cc
+5
-2
No files found.
mysql-test/r/win_insert_select.result
0 → 100644
View file @
ed61fddf
CREATE TABLE t1 (c1 INT, c2 VARCHAR(30));
PREPARE populate_table FROM "INSERT into t1 values (1, 'manual_insert_1'),
(4, 'manual_insert_2')";
INSERT INTO t1 SELECT row_number() over(), "should_have_0" FROM t1;
INSERT INTO t1 SELECT 1 + row_number() over(), "should_have_2" FROM t1;
EXECUTE populate_table;
INSERT INTO t1 SELECT 10 + row_number() over(), "should repeat 4 times [11-14]" FROM t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
c1 c2
1 manual_insert_1
4 manual_insert_2
11 should repeat 4 times [11-14]
12 should repeat 4 times [11-14]
13 should repeat 4 times [11-14]
14 should repeat 4 times [11-14]
0 should_have_0
2 should_have_2
DELETE FROM t1;
EXECUTE populate_table;
INSERT INTO t1
SELECT 10 + (dense_rank() over(order by c1)), "dense_rank_insert" from t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
c1 c2
11 dense_rank_insert
12 dense_rank_insert
1 manual_insert_1
4 manual_insert_2
DELETE FROM t1;
EXECUTE populate_table;
INSERT INTO t1
SELECT 100 + (rank() over(order by c1)), "rank_insert" from t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
c1 c2
1 manual_insert_1
4 manual_insert_2
101 rank_insert
102 rank_insert
DELETE FROM t1;
EXECUTE populate_table;
INSERT INTO t1
SELECT 100 + (ntile(10) over(order by c1)), "ntile_insert" from t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
c1 c2
1 manual_insert_1
4 manual_insert_2
101 ntile_insert
102 ntile_insert
DELETE FROM t1;
EXECUTE populate_table;
INSERT INTO t1
SELECT 1000 + (percent_rank() over(order by c1)), "percent_rank_insert" from t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
c1 c2
1 manual_insert_1
4 manual_insert_2
1000 percent_rank_insert
1001 percent_rank_insert
DELETE FROM t1;
EXECUTE populate_table;
INSERT INTO t1
SELECT 1000 + (count(*) over(order by c1)), "count_insert" from t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
c1 c2
1001 count_insert
1002 count_insert
1 manual_insert_1
4 manual_insert_2
DELETE FROM t1;
EXECUTE populate_table;
#
# Test how avg interacts when the results need to be rounded.
#
SELECT 1000 + (avg(c1) over(order by c1)) as avg_expr, c1, "This will be inserted into t1" from t1;
avg_expr c1 This will be inserted into t1
1001.0000 1 This will be inserted into t1
1002.5000 4 This will be inserted into t1
INSERT INTO t1
SELECT 1000 + (avg(c1) over(order by c1)), "avg_insert" from t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
c1 c2
1001 avg_insert
1003 avg_insert
1 manual_insert_1
4 manual_insert_2
DELETE FROM t1;
EXECUTE populate_table;
INSERT INTO t1
SELECT 1000 + (sum(c1) over(order by c1)), "sum_insert" from t1;
SELECT c1, c2
FROM t1
ORDER BY c2, c1;
c1 c2
1 manual_insert_1
4 manual_insert_2
1001 sum_insert
1005 sum_insert
DROP table t1;
mysql-test/t/win_insert_select.test
0 → 100644
View file @
ed61fddf
CREATE
TABLE
t1
(
c1
INT
,
c2
VARCHAR
(
30
));
PREPARE
populate_table
FROM
"INSERT into t1 values (1, 'manual_insert_1'),
(4, 'manual_insert_2')"
;
INSERT
INTO
t1
SELECT
row_number
()
over
(),
"should_have_0"
FROM
t1
;
INSERT
INTO
t1
SELECT
1
+
row_number
()
over
(),
"should_have_2"
FROM
t1
;
EXECUTE
populate_table
;
INSERT
INTO
t1
SELECT
10
+
row_number
()
over
(),
"should repeat 4 times [11-14]"
FROM
t1
;
SELECT
c1
,
c2
FROM
t1
ORDER
BY
c2
,
c1
;
DELETE
FROM
t1
;
EXECUTE
populate_table
;
INSERT
INTO
t1
SELECT
10
+
(
dense_rank
()
over
(
order
by
c1
)),
"dense_rank_insert"
from
t1
;
SELECT
c1
,
c2
FROM
t1
ORDER
BY
c2
,
c1
;
DELETE
FROM
t1
;
EXECUTE
populate_table
;
INSERT
INTO
t1
SELECT
100
+
(
rank
()
over
(
order
by
c1
)),
"rank_insert"
from
t1
;
SELECT
c1
,
c2
FROM
t1
ORDER
BY
c2
,
c1
;
DELETE
FROM
t1
;
EXECUTE
populate_table
;
INSERT
INTO
t1
SELECT
100
+
(
ntile
(
10
)
over
(
order
by
c1
)),
"ntile_insert"
from
t1
;
SELECT
c1
,
c2
FROM
t1
ORDER
BY
c2
,
c1
;
DELETE
FROM
t1
;
EXECUTE
populate_table
;
INSERT
INTO
t1
SELECT
1000
+
(
percent_rank
()
over
(
order
by
c1
)),
"percent_rank_insert"
from
t1
;
SELECT
c1
,
c2
FROM
t1
ORDER
BY
c2
,
c1
;
DELETE
FROM
t1
;
EXECUTE
populate_table
;
INSERT
INTO
t1
SELECT
1000
+
(
count
(
*
)
over
(
order
by
c1
)),
"count_insert"
from
t1
;
SELECT
c1
,
c2
FROM
t1
ORDER
BY
c2
,
c1
;
DELETE
FROM
t1
;
EXECUTE
populate_table
;
--
echo
#
--
echo
# Test how avg interacts when the results need to be rounded.
--
echo
#
SELECT
1000
+
(
avg
(
c1
)
over
(
order
by
c1
))
as
avg_expr
,
c1
,
"This will be inserted into t1"
from
t1
;
INSERT
INTO
t1
SELECT
1000
+
(
avg
(
c1
)
over
(
order
by
c1
)),
"avg_insert"
from
t1
;
SELECT
c1
,
c2
FROM
t1
ORDER
BY
c2
,
c1
;
DELETE
FROM
t1
;
EXECUTE
populate_table
;
INSERT
INTO
t1
SELECT
1000
+
(
sum
(
c1
)
over
(
order
by
c1
)),
"sum_insert"
from
t1
;
SELECT
c1
,
c2
FROM
t1
ORDER
BY
c2
,
c1
;
DROP
table
t1
;
sql/sql_base.cc
View file @
ed61fddf
...
...
@@ -7108,10 +7108,13 @@ bool setup_fields(THD *thd, Ref_ptr_array ref_pointer_array,
split_sum_func() must be called for Window Function items, see
Item_window_func::split_sum_func.
*/
if
((
item
->
with_sum_func
&&
item
->
type
()
!=
Item
::
SUM_FUNC_ITEM
&&
sum_func_list
)
||
item
->
with_window_func
)
if
(
sum_func_list
&&
((
item
->
with_sum_func
&&
item
->
type
()
!=
Item
::
SUM_FUNC_ITEM
)
||
item
->
with_window_func
))
{
item
->
split_sum_func
(
thd
,
ref_pointer_array
,
*
sum_func_list
,
SPLIT_SUM_SELECT
);
}
thd
->
lex
->
current_select
->
select_list_tables
|=
item
->
used_tables
();
thd
->
lex
->
used_tables
|=
item
->
used_tables
();
thd
->
lex
->
current_select
->
cur_pos_in_select_list
++
;
...
...
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