Commit b532be9f authored by Sergei Petrunia's avatar Sergei Petrunia

Merge ../10.2-window-funcs-r12 into 10.2

parents a4c81986 0f62eee2
......@@ -109,6 +109,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/table_cache.cc ../sql/mf_iocache_encr.cc
../sql/item_inetfunc.cc
../sql/wsrep_dummy.cc ../sql/encryption.cc
../sql/item_windowfunc.cc ../sql/sql_window.cc
../sql/sql_cte.cc
${GEN_SOURCES}
${MYSYS_LIBWRAP_SOURCE}
......
......@@ -492,8 +492,9 @@ ANALYZE
"select_id": 1,
"r_loops": 1,
"volatile parameter": "REPLACED",
"having_condition": "(TOP > a)",
"having_condition": "(TOP > t2.a)",
"filesort": {
"sort_key": "t2.a",
"r_loops": 1,
"volatile parameter": "REPLACED",
"r_used_priority_queue": false,
......@@ -523,6 +524,7 @@ ANALYZE
"r_loops": 1,
"volatile parameter": "REPLACED",
"filesort": {
"sort_key": "t2.a",
"r_loops": 1,
"volatile parameter": "REPLACED",
"r_used_priority_queue": false,
......@@ -563,6 +565,7 @@ ANALYZE
"r_loops": 1,
"volatile parameter": "REPLACED",
"filesort": {
"sort_key": "t2.a",
"r_loops": 1,
"volatile parameter": "REPLACED",
"r_used_priority_queue": false,
......@@ -684,18 +687,20 @@ ANALYZE
"r_loops": 1,
"volatile parameter": "REPLACED",
"filesort": {
"sort_key": "group_concat(t3.f3 separator ',')",
"r_loops": 1,
"volatile parameter": "REPLACED",
"r_used_priority_queue": false,
"r_output_rows": 0,
"volatile parameter": "REPLACED",
"filesort": {
"r_loops": 1,
"volatile parameter": "REPLACED",
"r_used_priority_queue": false,
"r_output_rows": 0,
"volatile parameter": "REPLACED",
"temporary_table": {
"temporary_table": {
"filesort": {
"sort_key": "(subquery#2)",
"r_loops": 1,
"volatile parameter": "REPLACED",
"r_used_priority_queue": false,
"r_output_rows": 0,
"volatile parameter": "REPLACED",
"temporary_table": {
"table": {
"table_name": "t2",
......
......@@ -172,8 +172,8 @@ EXPLAIN
"query_block": {
"select_id": 1,
"filesort": {
"sort_key": "t2.b",
"temporary_table": {
"function": "buffer",
"table": {
"table_name": "t0",
"access_type": "ALL",
......@@ -205,6 +205,7 @@ ANALYZE
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"filesort": {
"sort_key": "t2.b",
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"r_limit": 4,
......@@ -257,6 +258,7 @@ EXPLAIN
"select_id": 1,
"read_sorted_file": {
"filesort": {
"sort_key": "t0.a",
"table": {
"table_name": "t0",
"access_type": "ALL",
......@@ -290,6 +292,7 @@ ANALYZE
"read_sorted_file": {
"r_rows": 10,
"filesort": {
"sort_key": "t0.a",
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"r_used_priority_queue": false,
......@@ -346,6 +349,7 @@ ANALYZE
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"filesort": {
"sort_key": "t2.c",
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"r_used_priority_queue": false,
......@@ -455,18 +459,20 @@ ANALYZE
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"filesort": {
"sort_key": "count(distinct t5.b)",
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"r_limit": 1,
"r_used_priority_queue": true,
"r_output_rows": 2,
"filesort": {
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"r_used_priority_queue": false,
"r_output_rows": 6,
"r_buffer_size": "REPLACED",
"temporary_table": {
"temporary_table": {
"filesort": {
"sort_key": "t5.a",
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"r_used_priority_queue": false,
"r_output_rows": 6,
"r_buffer_size": "REPLACED",
"temporary_table": {
"table": {
"table_name": "t6",
......@@ -511,26 +517,31 @@ EXPLAIN
"query_block": {
"select_id": 1,
"filesort": {
"sort_key": "count(distinct t5.b)",
"temporary_table": {
"function": "buffer",
"table": {
"table_name": "t6",
"access_type": "ALL",
"rows": 5,
"filtered": 100,
"attached_condition": "((t6.b > 0) and (t6.a <= 5))"
},
"block-nl-join": {
"table": {
"table_name": "t5",
"access_type": "ALL",
"rows": 7,
"filtered": 100
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"attached_condition": "(t5.a = t6.a)"
"filesort": {
"sort_key": "t5.a",
"temporary_table": {
"table": {
"table_name": "t6",
"access_type": "ALL",
"rows": 5,
"filtered": 100,
"attached_condition": "((t6.b > 0) and (t6.a <= 5))"
},
"block-nl-join": {
"table": {
"table_name": "t5",
"access_type": "ALL",
"rows": 7,
"filtered": 100
},
"buffer_type": "flat",
"buffer_size": "256Kb",
"join_type": "BNL",
"attached_condition": "(t5.a = t6.a)"
}
}
}
}
}
......
......@@ -231,8 +231,8 @@ CREATE VIEW v1 AS SELECT a, MIN(b) AS b FROM t2 GROUP BY a;
EXPLAIN
SELECT * FROM v1, t1 WHERE v1.b=t1.a ORDER BY v1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 Using filesort
1 PRIMARY <derived2> ref key0 key0 5 const 1 Using where
1 PRIMARY t1 system NULL NULL NULL NULL 1
1 PRIMARY <derived2> ref key0 key0 5 const 1 Using where; Using filesort
2 DERIVED t2 ALL NULL NULL NULL NULL 10 Using temporary; Using filesort
SELECT * FROM v1, t1 WHERE v1.b=t1.a ORDER BY v1.a;
a b a
......
......@@ -175,7 +175,7 @@ explain SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using where; Using temporary
1 SIMPLE t3 ref a a 5 test.t1.b 2 Using index
1 SIMPLE t2 index a a 4 NULL 5 Using where; Using index; Distinct; Using join buffer (flat, BNL join)
1 SIMPLE t2 index a a 4 NULL 5 Using where; Using index; Using join buffer (flat, BNL join)
SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
a
1
......@@ -302,11 +302,11 @@ WHERE
AND ((t1.id=j_lj_t3.id AND t3_lj.id IS NULL) OR (t1.id=t3.id AND t3.idx=2));
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index id id 4 NULL 2 Using index; Using temporary
1 SIMPLE t2 index id id 8 NULL 1 Using index; Distinct; Using join buffer (flat, BNL join)
1 SIMPLE t3 index id id 8 NULL 1 Using index; Distinct; Using join buffer (flat, BNL join)
1 SIMPLE j_lj_t2 index id id 4 NULL 2 Using where; Using index; Distinct; Using join buffer (flat, BNL join)
1 SIMPLE t2_lj ref id id 4 test.j_lj_t2.id 1 Using where; Using index; Distinct
1 SIMPLE j_lj_t3 index id id 4 NULL 2 Using where; Using index; Distinct; Using join buffer (flat, BNL join)
1 SIMPLE t2 index id id 8 NULL 1 Using index; Using join buffer (flat, BNL join)
1 SIMPLE t3 index id id 8 NULL 1 Using index; Using join buffer (flat, BNL join)
1 SIMPLE j_lj_t2 index id id 4 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
1 SIMPLE t2_lj ref id id 4 test.j_lj_t2.id 1 Using where; Using index
1 SIMPLE j_lj_t3 index id id 4 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
1 SIMPLE t3_lj ref id id 4 test.j_lj_t3.id 1 Using where; Using index; Distinct
SELECT DISTINCT
t1.id
......@@ -518,7 +518,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT DISTINCT t1_1.a, t1_1.b FROM t1 t1_1, t1 t1_2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1_1 ALL NULL NULL NULL NULL 3 Using temporary
1 SIMPLE t1_2 index NULL PRIMARY 4 NULL 3 Using index; Distinct; Using join buffer (flat, BNL join)
1 SIMPLE t1_2 index NULL PRIMARY 4 NULL 3 Using index; Using join buffer (flat, BNL join)
EXPLAIN SELECT DISTINCT t1_1.a, t1_1.b FROM t1 t1_1, t1 t1_2
WHERE t1_1.a = t1_2.a;
id select_type table type possible_keys key key_len ref rows Extra
......@@ -916,8 +916,8 @@ SELECT STRAIGHT_JOIN DISTINCT t1.id FROM
t1, v1, t2 WHERE v1.id = t2.i AND t1.i1 = v1.i1 AND t2.i != 3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 96 100.00 Using where; Using temporary
1 PRIMARY <derived2> ref key0 key0 5 test.t1.i1 9 100.00 Using where; Distinct
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Distinct; Using join buffer (flat, BNL join)
1 PRIMARY <derived2> ref key0 key0 5 test.t1.i1 9 100.00 Using where
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 96 100.00
Warnings:
Note 1003 select straight_join distinct `test`.`t1`.`id` AS `id` from `test`.`t1` join `test`.`v1` join `test`.`t2` where ((`test`.`t2`.`i` = `v1`.`id`) and (`v1`.`i1` = `test`.`t1`.`i1`) and (`v1`.`id` <> 3))
......
......@@ -486,8 +486,8 @@ EXPLAIN
"query_block": {
"select_id": 2,
"filesort": {
"sort_key": "t1.a",
"temporary_table": {
"function": "buffer",
"table": {
"table_name": "t1",
"access_type": "ALL",
......@@ -530,8 +530,8 @@ EXPLAIN
"query_block": {
"select_id": 2,
"filesort": {
"sort_key": "t1.a",
"temporary_table": {
"function": "buffer",
"table": {
"table_name": "t1",
"access_type": "ALL",
......@@ -576,7 +576,6 @@ EXPLAIN
"query_block": {
"select_id": 2,
"temporary_table": {
"function": "buffer",
"table": {
"table_name": "t1",
"access_type": "ALL",
......@@ -1132,8 +1131,8 @@ EXPLAIN
"select_id": 1,
"having_condition": "(TOP > t2.a)",
"filesort": {
"sort_key": "t2.a",
"temporary_table": {
"function": "buffer",
"table": {
"table_name": "t2",
"access_type": "ALL",
......@@ -1151,8 +1150,8 @@ EXPLAIN
"query_block": {
"select_id": 1,
"filesort": {
"sort_key": "t2.a",
"temporary_table": {
"function": "buffer",
"table": {
"table_name": "t2",
"access_type": "ALL",
......@@ -1181,8 +1180,8 @@ EXPLAIN
"query_block": {
"select_id": 1,
"filesort": {
"sort_key": "t2.a",
"temporary_table": {
"function": "buffer",
"table": {
"table_name": "t2",
"access_type": "ALL",
......@@ -1380,7 +1379,6 @@ EXPLAIN
"query_block": {
"select_id": 1,
"temporary_table": {
"function": "buffer",
"table": {
"table_name": "t1",
"access_type": "ALL",
......
......@@ -1519,7 +1519,7 @@ SELECT MAX(pk) as max, i
FROM t1
ORDER BY max;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using temporary
1 SIMPLE t1 ALL NULL NULL NULL NULL 3
# Only 11 is correct for collumn i in this result
SELECT MAX(pk) as max, i
......
......@@ -1346,12 +1346,43 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR JOIN (PRIMARY,i2);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 144
#
# For this explain, the query plan is weird: if we are using
# the primary key for reasons other than doing grouping, can't
# GROUP BY code take advantage of this? Well, currently it doesnt:
EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR GROUP BY (PRIMARY,i2) GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 4 NULL 144 Using index
1 SIMPLE t1 index NULL PRIMARY 4 NULL 144 Using index; Using filesort
# Here's a proof it is really doing sorting:
flush status;
SELECT a FROM t1 IGNORE INDEX FOR GROUP BY (PRIMARY,i2) GROUP BY a;
show status like 'Sort_%';
Variable_name Value
Sort_merge_passes 0
Sort_priority_queue_sorts 0
Sort_range 0
Sort_rows 144
Sort_scan 1
# Proof ends.
#
# For this explain, the query plan is weird: if we are using
# the primary key for reasons other than doing sorting, can't
# ORDER BY code take advantage of this? Well, currently it doesnt:
EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY,i2) ORDER BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 4 NULL 144 Using index
1 SIMPLE t1 index NULL PRIMARY 4 NULL 144 Using index; Using filesort
# Here's a proof it is really doing sorting:
flush status;
SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY,i2) ORDER BY a;
show status like 'Sort_%';
Variable_name Value
Sort_merge_passes 0
Sort_priority_queue_sorts 0
Sort_range 0
Sort_rows 144
Sort_scan 1
# Proof ends.
#
SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY,i2) ORDER BY a;
a
1
......
......@@ -470,10 +470,9 @@ WHERE table2.f1 = 2
GROUP BY table1.f1, table2.f2
HAVING (table2.f2 = 8 AND table1.f1 >= 6);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE table2 const PRIMARY PRIMARY 4 const 1 100.00 Using filesort
1 SIMPLE table1 ALL NULL NULL NULL NULL 4 100.00 Using where
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible HAVING noticed after reading const tables
Warnings:
Note 1003 select `test`.`table1`.`f1` AS `f1`,7 AS `f2` from `test`.`t1` `table1` join `test`.`t1` `table2` where (`test`.`table1`.`f3` = 9) group by `test`.`table1`.`f1`,7 having ((7 = 8) and (`test`.`table1`.`f1` >= 6))
Note 1003 select `test`.`table1`.`f1` AS `f1`,7 AS `f2` from `test`.`t1` `table1` join `test`.`t1` `table2` where (`test`.`table1`.`f3` = 9) group by `test`.`table1`.`f1`,7 having 0
EXPLAIN EXTENDED
SELECT table1.f1, table2.f2
FROM t1 AS table1
......@@ -482,10 +481,9 @@ WHERE table2.f1 = 2
GROUP BY table1.f1, table2.f2
HAVING (table2.f2 = 8);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE table2 const PRIMARY PRIMARY 4 const 1 100.00 Using filesort
1 SIMPLE table1 ALL NULL NULL NULL NULL 4 100.00 Using where
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible HAVING noticed after reading const tables
Warnings:
Note 1003 select `test`.`table1`.`f1` AS `f1`,7 AS `f2` from `test`.`t1` `table1` join `test`.`t1` `table2` where (`test`.`table1`.`f3` = 9) group by `test`.`table1`.`f1`,7 having (7 = 8)
Note 1003 select `test`.`table1`.`f1` AS `f1`,7 AS `f2` from `test`.`t1` `table1` join `test`.`t1` `table2` where (`test`.`table1`.`f3` = 9) group by `test`.`table1`.`f1`,7 having 0
DROP TABLE t1;
#
# Bug#52336 Segfault / crash in 5.1 copy_fields (param=0x9872980) at sql_select.cc:15355
......
......@@ -5412,9 +5412,9 @@ WHERE t2.c IN (SELECT c FROM t3,t4 WHERE t4.a < 10) AND
t2.a BETWEEN 4 and 5
ORDER BY t2.b;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 Using filesort
1 PRIMARY t1 system NULL NULL NULL NULL 1
1 PRIMARY t3 system NULL NULL NULL NULL 1
1 PRIMARY t2 range a,c a 5 NULL 1 Using index condition; Using where
1 PRIMARY t2 range a,c a 5 NULL 1 Using index condition; Using where; Using filesort
1 PRIMARY t4 ref c c 5 test.t2.c 2 Using where; Start temporary; End temporary
SELECT * FROM t1,t2
WHERE t2.c IN (SELECT c FROM t3,t4 WHERE t4.a < 10) AND
......
......@@ -1289,8 +1289,8 @@ SELECT t1.a, COUNT( t2.b ), SUM( t2.b ), MAX( t2.b )
FROM t1 JOIN t2 USING( a )
GROUP BY t1.a WITH ROLLUP;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 Using filesort
1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using where
1 SIMPLE t1 system NULL NULL NULL NULL 1
1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using where; Using filesort
SELECT t1.a, COUNT( t2.b ), SUM( t2.b ), MAX( t2.b )
FROM t1 JOIN t2 USING( a )
GROUP BY t1.a WITH ROLLUP;
......@@ -1429,8 +1429,8 @@ EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 Using filesort
1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index; Using filesort
SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2;
......@@ -1846,8 +1846,8 @@ EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 Using filesort
1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index; Using filesort
SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2;
......
......@@ -1300,8 +1300,8 @@ SELECT t1.a, COUNT( t2.b ), SUM( t2.b ), MAX( t2.b )
FROM t1 JOIN t2 USING( a )
GROUP BY t1.a WITH ROLLUP;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 Using filesort
1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using where
1 SIMPLE t1 system NULL NULL NULL NULL 1
1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using where; Using filesort
SELECT t1.a, COUNT( t2.b ), SUM( t2.b ), MAX( t2.b )
FROM t1 JOIN t2 USING( a )
GROUP BY t1.a WITH ROLLUP;
......@@ -1440,8 +1440,8 @@ EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 Using filesort
1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index; Using filesort
SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2;
......@@ -1857,8 +1857,8 @@ EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 Using filesort
1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index; Using filesort
SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2;
......
......@@ -80,13 +80,13 @@ create table t1 (a int);
insert into t1 values (1),(2),(3),(4),(5),(6),(7);
explain select count(*) c FROM t1 WHERE a > 0 ORDER BY c LIMIT 3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where; Using temporary
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where
select count(*) c FROM t1 WHERE a > 0 ORDER BY c LIMIT 3;
c
7
explain select sum(a) c FROM t1 WHERE a > 0 ORDER BY c LIMIT 3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where; Using temporary
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where
select sum(a) c FROM t1 WHERE a > 0 ORDER BY c LIMIT 3;
c
28
......
......@@ -471,9 +471,11 @@ id select_type table type possible_keys key key_len ref rows Extra
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 0;
c1 sum(c2)
Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 2 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete.
Warning 1931 Query execution was interrupted. The query examined at least 1 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete.
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 1;
ERROR HY000: Sort aborted:
c1 sum(c2)
Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 3 rows, which exceeds LIMIT ROWS EXAMINED (1). The query result may be incomplete.
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 20;
c1 sum(c2)
aa 3
......@@ -496,9 +498,11 @@ id select_type table type possible_keys key key_len ref rows Extra
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 0;
c1 sum(c2)
Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 2 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete.
Warning 1931 Query execution was interrupted. The query examined at least 1 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete.
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 1;
ERROR HY000: Sort aborted:
c1 sum(c2)
Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 3 rows, which exceeds LIMIT ROWS EXAMINED (1). The query result may be incomplete.
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 20;
c1 sum(c2)
aa 3
......@@ -627,7 +631,7 @@ CREATE TABLE t4 (a int);
INSERT INTO t4 values (1), (2);
INSERT INTO t4 SELECT a + 2 FROM t4 LIMIT ROWS EXAMINED 0;
Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 2 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete.
Warning 1931 Query execution was interrupted. The query examined at least 1 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete.
select * from t4;
a
1
......@@ -666,7 +670,7 @@ MDEV-115
SET @@optimizer_switch='in_to_exists=on,outer_join_with_cache=on';
CREATE TABLE t1 ( a VARCHAR(3) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('USA');
INSERT INTO t1 VALUES ('USA'),('CAN');
CREATE TABLE t2 ( b INT );
INSERT INTO t2 VALUES (3899),(3914),(3888);
CREATE TABLE t3 ( c VARCHAR(33), d INT );
......@@ -676,8 +680,8 @@ SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 Using temporary
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Distinct
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
2 SUBQUERY t3 ALL NULL NULL NULL NULL 3
2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
SELECT DISTINCT a AS field1 FROM t1, t2
......@@ -685,24 +689,27 @@ WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
field1
Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 23 rows, which exceeds LIMIT ROWS EXAMINED (20). The query result may be incomplete.
Warning 1931 Query execution was interrupted. The query examined at least 21 rows, which exceeds LIMIT ROWS EXAMINED (20). The query result may be incomplete.
EXPLAIN
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 14;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 Using temporary
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Distinct
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 14;
a
USA
Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 15 rows, which exceeds LIMIT ROWS EXAMINED (14). The query result may be incomplete.
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 15;
a
USA
CAN
Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 16 rows, which exceeds LIMIT ROWS EXAMINED (15). The query result may be incomplete.
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 16;
a
USA
CAN
Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 17 rows, which exceeds LIMIT ROWS EXAMINED (16). The query result may be incomplete.
drop table t1,t2,t3;
......
......@@ -7,8 +7,8 @@ explain select 1 from
(select f2, f3, val, count(id) from t4 join t2 left join t3 on 0) top
join t1 on f1 = f3 where f3 = 'aaaa' order by val;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 const PRIMARY PRIMARY 12 const 1 Using index; Using filesort
1 PRIMARY <derived2> ref key0 key0 13 const 0 Using where
1 PRIMARY t1 const PRIMARY PRIMARY 12 const 1 Using index
1 PRIMARY <derived2> ref key0 key0 13 const 0 Using where; Using filesort
2 DERIVED t4 ALL NULL NULL NULL NULL 1
2 DERIVED t2 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join)
2 DERIVED t3 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (incremental, BNL join)
......
......@@ -523,11 +523,11 @@ a
explain select sql_big_result distinct t1.a from t1,t2 order by t2.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 Using temporary
1 SIMPLE t2 index NULL PRIMARY 4 NULL 2 Using index; Distinct
1 SIMPLE t2 index NULL PRIMARY 4 NULL 2 Using index
explain select distinct t1.a from t1,t2 order by t2.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 Using temporary
1 SIMPLE t2 index NULL PRIMARY 4 NULL 2 Using index; Distinct
1 SIMPLE t2 index NULL PRIMARY 4 NULL 2 Using index
drop table t1,t2;
create table t1 (
c1 varchar(32),
......
......@@ -83,20 +83,20 @@ UNIQUE KEY e_n (email,name)
);
EXPLAIN SELECT SQL_CALC_FOUND_ROWS DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL LIMIT 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY,kid NULL NULL NULL 0 const row not found
1 SIMPLE t2 index NULL e_n 104 NULL 10
1 SIMPLE t1 system PRIMARY,kid NULL NULL NULL 0 const row not found; Using temporary
1 SIMPLE t2 ALL NULL NULL NULL NULL 200
SELECT SQL_CALC_FOUND_ROWS DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL LIMIT 10;
email
email1
email2
email3
email4
email5
email6
email7
email8
email9
email10
email100
email101
email102
email103
email104
email105
email106
email107
SELECT FOUND_ROWS();
FOUND_ROWS()
200
......
......@@ -1162,7 +1162,7 @@ SELECT b AS field1, b AS field2 FROM t1, t2, t3 WHERE d = b ORDER BY field1, fie
connection default;
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 system NULL NULL NULL NULL 1 Using filesort
1 SIMPLE t2 system NULL NULL NULL NULL 1
1 SIMPLE t1 range b b 6 NULL 107 Using where; Using index
1 SIMPLE t3 ref PRIMARY PRIMARY 5 test.t1.b 1 Using index
Warnings:
......
......@@ -19,7 +19,7 @@ SELECT 1 FROM t1
WHERE NOT EXISTS (SELECT 1 FROM t2 WHERE 1 = (SELECT MIN(t2.b) FROM t3))
ORDER BY count(*);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 5 NULL 2 Using where; Using index; Using temporary
1 PRIMARY t1 index NULL a 5 NULL 2 Using where; Using index
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
3 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 0 const row not found
# should not crash the next statement
......@@ -2003,8 +2003,8 @@ FROM t2 JOIN t3 ON t3.f4 = t2.f4
WHERE t3.f1 = 8
GROUP BY 1, 2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 system NULL NULL NULL NULL 1 Using filesort
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
1 PRIMARY t3 system NULL NULL NULL NULL 1
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using filesort
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
3 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table
PREPARE st1 FROM "
......
This diff is collapsed.
create table t1 (
pk int primary key,
a int,
b int,
c real
);
insert into t1 values
(101 , 0, 10, 1.1),
(102 , 0, 10, 2.1),
(103 , 1, 10, 3.1),
(104 , 1, 10, 4.1),
(108 , 2, 10, 5.1),
(105 , 2, 20, 6.1),
(106 , 2, 20, 7.1),
(107 , 2, 20, 8.15),
(109 , 4, 20, 9.15),
(110 , 4, 20, 10.15),
(111 , 5, NULL, 11.15),
(112 , 5, 1, 12.25),
(113 , 5, NULL, 13.35),
(114 , 5, NULL, 14.50),
(115 , 5, NULL, 15.65),
(116 , 6, 1, NULL),
(117 , 6, 1, 10),
(118 , 6, 1, 1.1),
(119 , 6, 1, NULL),
(120 , 6, 1, NULL),
(121 , 6, 1, NULL),
(122 , 6, 1, 2.2),
(123 , 6, 1, 20.1),
(124 , 6, 1, -10.4),
(125 , 6, 1, NULL),
(126 , 6, 1, NULL),
(127 , 6, 1, NULL);
select pk, a, b, avg(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
from t1;
pk a b avg(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
101 0 10 10.0000
102 0 10 10.0000
103 1 10 10.0000
104 1 10 10.0000
105 2 20 20.0000
106 2 20 20.0000
107 2 20 16.6667
108 2 10 15.0000
109 4 20 20.0000
110 4 20 20.0000
111 5 NULL 1.0000
112 5 1 1.0000
113 5 NULL 1.0000
114 5 NULL NULL
115 5 NULL NULL
116 6 1 1.0000
117 6 1 1.0000
118 6 1 1.0000
119 6 1 1.0000
120 6 1 1.0000
121 6 1 1.0000
122 6 1 1.0000
123 6 1 1.0000
124 6 1 1.0000
125 6 1 1.0000
126 6 1 1.0000
127 6 1 1.0000
select pk, a, c, avg(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
from t1;
pk a c avg(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
101 0 1.1 1.6
102 0 2.1 1.6
103 1 3.1 3.5999999999999996
104 1 4.1 3.5999999999999996
105 2 6.1 6.6
106 2 7.1 7.116666666666667
107 2 8.15 6.783333333333334
108 2 5.1 6.625000000000001
109 4 9.15 9.65
110 4 10.15 9.65
111 5 11.15 11.7
112 5 12.25 12.25
113 5 13.35 13.366666666666667
114 5 14.5 14.5
115 5 15.65 15.075
116 6 NULL 10
117 6 10 5.55
118 6 1.1 5.55
119 6 NULL 1.0999999999999996
120 6 NULL NULL
121 6 NULL 2.1999999999999997
122 6 2.2 11.15
123 6 20.1 3.966666666666667
124 6 -10.4 4.85
125 6 NULL -10.400000000000002
126 6 NULL NULL
127 6 NULL NULL
drop table t1;
create table t1 (
pk int primary key,
a int,
b int
);
create table t2 (
pk int primary key,
a int,
b int
);
insert into t1 values
( 1 , 0, 1),
( 2 , 0, 2),
( 3 , 1, 4),
( 4 , 1, 8),
( 5 , 2, 32),
( 6 , 2, 64),
( 7 , 2, 128),
( 8 , 2, 16);
insert into t2 values
( 1 , 0, 2),
( 2 , 0, 2),
( 3 , 1, 4),
( 4 , 1, 4),
( 5 , 2, 16),
( 6 , 2, 64),
( 7 , 2, 128),
( 8 , 2, 16);
# Test bit functions on only one partition.
select pk, a, b,
bit_or(b) over (order by pk) as bit_or,
bit_and(b) over (order by pk) as bit_and,
bit_xor(b) over (order by pk) as bit_xor
from t1;
pk a b bit_or bit_and bit_xor
1 0 1 1 1 1
2 0 2 3 0 3
3 1 4 7 0 7
4 1 8 15 0 15
5 2 32 47 0 47
6 2 64 111 0 111
7 2 128 239 0 239
8 2 16 255 0 255
select pk, a, b,
bit_or(b) over (order by pk) as bit_or,
bit_and(b) over (order by pk) as bit_and,
bit_xor(b) over (order by pk) as bit_xor
from t2;
pk a b bit_or bit_and bit_xor
1 0 2 2 2 2
2 0 2 2 2 0
3 1 4 6 0 4
4 1 4 6 0 0
5 2 16 22 0 16
6 2 64 86 0 80
7 2 128 214 0 208
8 2 16 214 0 192
# Test multiple partitions with bit functions.
select pk, a, b,
bit_or(b) over (partition by a order by pk) as bit_or,
bit_and(b) over (partition by a order by pk) as bit_and,
bit_xor(b) over (partition by a order by pk) as bit_xor
from t1;
pk a b bit_or bit_and bit_xor
1 0 1 1 1 1
2 0 2 3 0 3
3 1 4 4 4 4
4 1 8 12 0 12
5 2 32 32 32 32
6 2 64 96 0 96
7 2 128 224 0 224
8 2 16 240 0 240
select pk, a, b,
bit_or(b) over (partition by a order by pk) as bit_or,
bit_and(b) over (partition by a order by pk) as bit_and,
bit_xor(b) over (partition by a order by pk) as bit_xor
from t2;
pk a b bit_or bit_and bit_xor
1 0 2 2 2 2
2 0 2 2 2 0
3 1 4 4 4 4
4 1 4 4 4 0
5 2 16 16 16 16
6 2 64 80 0 80
7 2 128 208 0 208
8 2 16 208 0 192
# Test remove function for bit functions using a sliding window.
select pk, a, b,
bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as bit_or,
bit_and(b) over (partition by a order by pk) as bit_and,
bit_xor(b) over (partition by a order by pk) as bit_xor
from t1;
pk a b bit_or bit_and bit_xor
1 0 1 3 1 1
2 0 2 3 0 3
3 1 4 12 4 4
4 1 8 12 0 12
5 2 32 96 32 32
6 2 64 224 0 96
7 2 128 208 0 224
8 2 16 144 0 240
select pk, a, b,
bit_or(b) over (partition by a order by pk) as bit_or,
bit_and(b) over (partition by a order by pk) as bit_and,
bit_xor(b) over (partition by a order by pk) as bit_xor
from t2;
pk a b bit_or bit_and bit_xor
1 0 2 2 2 2
2 0 2 2 2 0
3 1 4 4 4 4
4 1 4 4 4 0
5 2 16 16 16 16
6 2 64 80 0 80
7 2 128 208 0 208
8 2 16 208 0 192
drop table t1;
drop table t2;
create table t1 (
pk int primary key,
a int,
b int
);
insert into t1 values
(11 , 0, 10),
(12 , 0, 10),
(13 , 1, 10),
(14 , 1, 10),
(18 , 2, 10),
(15 , 2, 20),
(16 , 2, 20),
(17 , 2, 20),
(19 , 4, 20),
(20 , 4, 20);
select pk, a, b, ntile(-1) over (order by a)
from t1;
ERROR HY000: Argument of NTILE must be greater than 0
select pk, a, b,
ntile(0) over (order by a)
from t1;
ERROR HY000: Argument of NTILE must be greater than 0
select pk, a, b,
ntile(1) over (order by pk)
from t1;
pk a b ntile(1) over (order by pk)
11 0 10 1
12 0 10 1
13 1 10 1
14 1 10 1
15 2 20 1
16 2 20 1
17 2 20 1
18 2 10 1
19 4 20 1
20 4 20 1
select pk, a, b,
ntile(2) over (order by pk)
from t1;
pk a b ntile(2) over (order by pk)
11 0 10 1
12 0 10 1
13 1 10 1
14 1 10 1
15 2 20 1
16 2 20 2
17 2 20 2
18 2 10 2
19 4 20 2
20 4 20 2
select pk, a, b,
ntile(3) over (order by pk)
from t1;
pk a b ntile(3) over (order by pk)
11 0 10 1
12 0 10 1
13 1 10 1
14 1 10 1
15 2 20 2
16 2 20 2
17 2 20 2
18 2 10 3
19 4 20 3
20 4 20 3
select pk, a, b,
ntile(4) over (order by pk)
from t1;
pk a b ntile(4) over (order by pk)
11 0 10 1
12 0 10 1
13 1 10 1
14 1 10 2
15 2 20 2
16 2 20 2
17 2 20 3
18 2 10 3
19 4 20 4
20 4 20 4
select pk, a, b,
ntile(5) over (order by pk)
from t1;
pk a b ntile(5) over (order by pk)
11 0 10 1
12 0 10 1
13 1 10 2
14 1 10 2
15 2 20 3
16 2 20 3
17 2 20 4
18 2 10 4
19 4 20 5
20 4 20 5
select pk, a, b,
ntile(6) over (order by pk)
from t1;
pk a b ntile(6) over (order by pk)
11 0 10 1
12 0 10 1
13 1 10 2
14 1 10 2
15 2 20 3
16 2 20 3
17 2 20 4
18 2 10 4
19 4 20 5
20 4 20 6
select pk, a, b,
ntile(7) over (order by pk)
from t1;
pk a b ntile(7) over (order by pk)
11 0 10 1
12 0 10 1
13 1 10 2
14 1 10 2
15 2 20 3
16 2 20 3
17 2 20 4
18 2 10 5
19 4 20 6
20 4 20 7
select pk, a, b,
ntile(8) over (order by pk)
from t1;
pk a b ntile(8) over (order by pk)
11 0 10 1
12 0 10 1
13 1 10 2
14 1 10 2
15 2 20 3
16 2 20 4
17 2 20 5
18 2 10 6
19 4 20 7
20 4 20 8
select pk, a, b,
ntile(9) over (order by pk)
from t1;
pk a b ntile(9) over (order by pk)
11 0 10 1
12 0 10 1
13 1 10 2
14 1 10 3
15 2 20 4
16 2 20 5
17 2 20 6
18 2 10 7
19 4 20 8
20 4 20 9
select pk, a, b,
ntile(10) over (order by pk)
from t1;
pk a b ntile(10) over (order by pk)
11 0 10 1
12 0 10 2
13 1 10 3
14 1 10 4
15 2 20 5
16 2 20 6
17 2 20 7
18 2 10 8
19 4 20 9
20 4 20 10
select pk, a, b,
ntile(11) over (order by pk)
from t1;
pk a b ntile(11) over (order by pk)
11 0 10 1
12 0 10 2
13 1 10 3
14 1 10 4
15 2 20 5
16 2 20 6
17 2 20 7
18 2 10 8
19 4 20 9
20 4 20 10
select pk, a, b,
ntile(20) over (order by pk)
from t1;
pk a b ntile(20) over (order by pk)
11 0 10 1
12 0 10 2
13 1 10 3
14 1 10 4
15 2 20 5
16 2 20 6
17 2 20 7
18 2 10 8
19 4 20 9
20 4 20 10
select pk, a, b,
ntile(1) over (partition by b order by pk)
from t1;
pk a b ntile(1) over (partition by b order by pk)
11 0 10 1
12 0 10 1
13 1 10 1
14 1 10 1
18 2 10 1
15 2 20 1
16 2 20 1
17 2 20 1
19 4 20 1
20 4 20 1
select pk, a, b,
ntile(2) over (partition by b order by pk)
from t1;
pk a b ntile(2) over (partition by b order by pk)
11 0 10 1
12 0 10 1
13 1 10 1
14 1 10 2
18 2 10 2
15 2 20 1
16 2 20 1
17 2 20 1
19 4 20 2
20 4 20 2
select pk, a, b,
ntile(3) over (partition by b order by pk)
from t1;
pk a b ntile(3) over (partition by b order by pk)
11 0 10 1
12 0 10 1
13 1 10 2
14 1 10 2
18 2 10 3
15 2 20 1
16 2 20 1
17 2 20 2
19 4 20 2
20 4 20 3
select pk, a, b,
ntile(4) over (partition by b order by pk)
from t1;
pk a b ntile(4) over (partition by b order by pk)
11 0 10 1
12 0 10 1
13 1 10 2
14 1 10 3
18 2 10 4
15 2 20 1
16 2 20 1
17 2 20 2
19 4 20 3
20 4 20 4
select pk, a, b,
ntile(5) over (partition by b order by pk)
from t1;
pk a b ntile(5) over (partition by b order by pk)
11 0 10 1
12 0 10 2
13 1 10 3
14 1 10 4
18 2 10 5
15 2 20 1
16 2 20 2
17 2 20 3
19 4 20 4
20 4 20 5
select pk, a, b,
ntile(6) over (partition by b order by pk)
from t1;
pk a b ntile(6) over (partition by b order by pk)
11 0 10 1
12 0 10 2
13 1 10 3
14 1 10 4
18 2 10 5
15 2 20 1
16 2 20 2
17 2 20 3
19 4 20 4
20 4 20 5
select pk, a, b,
ntile(7) over (partition by b order by pk)
from t1;
pk a b ntile(7) over (partition by b order by pk)
11 0 10 1
12 0 10 2
13 1 10 3
14 1 10 4
18 2 10 5
15 2 20 1
16 2 20 2
17 2 20 3
19 4 20 4
20 4 20 5
select pk, a, b,
ntile(8) over (partition by b order by pk)
from t1;
pk a b ntile(8) over (partition by b order by pk)
11 0 10 1
12 0 10 2
13 1 10 3
14 1 10 4
18 2 10 5
15 2 20 1
16 2 20 2
17 2 20 3
19 4 20 4
20 4 20 5
select pk, a, b,
ntile(9) over (partition by b order by pk)
from t1;
pk a b ntile(9) over (partition by b order by pk)
11 0 10 1
12 0 10 2
13 1 10 3
14 1 10 4
18 2 10 5
15 2 20 1
16 2 20 2
17 2 20 3
19 4 20 4
20 4 20 5
select pk, a, b,
ntile(10) over (partition by b order by pk)
from t1;
pk a b ntile(10) over (partition by b order by pk)
11 0 10 1
12 0 10 2
13 1 10 3
14 1 10 4
18 2 10 5
15 2 20 1
16 2 20 2
17 2 20 3
19 4 20 4
20 4 20 5
select pk, a, b,
ntile(11) over (partition by b order by pk)
from t1;
pk a b ntile(11) over (partition by b order by pk)
11 0 10 1
12 0 10 2
13 1 10 3
14 1 10 4
18 2 10 5
15 2 20 1
16 2 20 2
17 2 20 3
19 4 20 4
20 4 20 5
select pk, a, b,
ntile(20) over (partition by b order by pk)
from t1;
pk a b ntile(20) over (partition by b order by pk)
11 0 10 1
12 0 10 2
13 1 10 3
14 1 10 4
18 2 10 5
15 2 20 1
16 2 20 2
17 2 20 3
19 4 20 4
20 4 20 5
select pk, a, b,
ntile(1 + 3) over (partition by b order by pk)
from t1;
pk a b ntile(1 + 3) over (partition by b order by pk)
11 0 10 1
12 0 10 1
13 1 10 2
14 1 10 3
18 2 10 4
15 2 20 1
16 2 20 1
17 2 20 2
19 4 20 3
20 4 20 4
select pk, a, b,
ntile((select 4)) over (partition by b order by pk)
from t1;
pk a b ntile((select 4)) over (partition by b order by pk)
11 0 10 1
12 0 10 1
13 1 10 2
14 1 10 3
18 2 10 4
15 2 20 1
16 2 20 1
17 2 20 2
19 4 20 3
20 4 20 4
select t1.a from t1 where pk = 11;
a
0
select pk, a, b,
ntile((select a from t1 where pk=11)) over (partition by b order by pk)
from t1;
ERROR HY000: Argument of NTILE must be greater than 0
select t1.a from t1 where pk = 13;
a
1
select pk, a, b,
ntile((select a from t1 where pk=13)) over (partition by b order by pk)
from t1;
pk a b ntile((select a from t1 where pk=13)) over (partition by b order by pk)
11 0 10 1
12 0 10 1
13 1 10 1
14 1 10 1
18 2 10 1
15 2 20 1
16 2 20 1
17 2 20 1
19 4 20 1
20 4 20 1
explain
select pk, a, b,
ntile((select a from t1 where pk=13)) over (partition by b order by pk)
from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 10 Using temporary
2 SUBQUERY t1 const PRIMARY PRIMARY 4 const 1
select a from t1;
a
0
0
1
1
2
2
2
2
4
4
select pk, a, b,
ntile((select a from t1)) over (partition by b order by pk)
from t1;
ERROR 21000: Subquery returns more than 1 row
drop table t1;
drop table if exists t0,t1;
create table t0(a int primary key);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1(
pk int,
a int,
key(pk)
);
insert into t1
select
A.a + B.a* 10 + C.a * 100,
1
from t0 A, t0 B, t0 C;
select
pk,
count(a) over (order by pk rows between 2 preceding and 2 following)
from t1
where pk between 1 and 30
order by pk desc
limit 4;
pk count(a) over (order by pk rows between 2 preceding and 2 following)
30 3
29 4
28 5
27 5
drop table t0,t1;
create table t1 (
pk int primary key,
a int,
b int
);
insert into t1 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,
percent_rank() over (order by a),
cume_dist() over (order by a)
from t1;
pk a b percent_rank() over (order by a) cume_dist() over (order by a)
1 0 10 0.0000000000 0.2000000000
2 0 10 0.0000000000 0.2000000000
3 1 10 0.2222222222 0.4000000000
4 1 10 0.2222222222 0.4000000000
8 2 10 0.4444444444 0.8000000000
5 2 20 0.4444444444 0.8000000000
6 2 20 0.4444444444 0.8000000000
7 2 20 0.4444444444 0.8000000000
9 4 20 0.8888888889 1.0000000000
10 4 20 0.8888888889 1.0000000000
select pk, a, b,
percent_rank() over (order by pk),
cume_dist() over (order by pk)
from t1 order by pk;
pk a b percent_rank() over (order by pk) cume_dist() over (order by pk)
1 0 10 0.0000000000 0.1000000000
2 0 10 0.1111111111 0.2000000000
3 1 10 0.2222222222 0.3000000000
4 1 10 0.3333333333 0.4000000000
5 2 20 0.4444444444 0.5000000000
6 2 20 0.5555555556 0.6000000000
7 2 20 0.6666666667 0.7000000000
8 2 10 0.7777777778 0.8000000000
9 4 20 0.8888888889 0.9000000000
10 4 20 1.0000000000 1.0000000000
select pk, a, b,
percent_rank() over (partition by a order by a),
cume_dist() over (partition by a order by a)
from t1;
pk a b percent_rank() over (partition by a order by a) cume_dist() over (partition by a order by a)
1 0 10 0.0000000000 1.0000000000
2 0 10 0.0000000000 1.0000000000
3 1 10 0.0000000000 1.0000000000
4 1 10 0.0000000000 1.0000000000
8 2 10 0.0000000000 1.0000000000
5 2 20 0.0000000000 1.0000000000
6 2 20 0.0000000000 1.0000000000
7 2 20 0.0000000000 1.0000000000
9 4 20 0.0000000000 1.0000000000
10 4 20 0.0000000000 1.0000000000
drop table t1;
#
# Try DENSE_RANK() function
#
create table t1 (
pk int primary key,
a int,
b int
);
insert into t1 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) as rank,
dense_rank() over (order by a) as dense_rank
from t1;
pk a b rank dense_rank
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) as rank,
dense_rank() over (partition by b order by a) as dense_rank
from t1;
pk a b rank dense_rank
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 0
6 2 20 1 0
7 2 20 1 0
9 4 20 4 1
10 4 20 4 1
drop table t1;
#
# Test with null values in the table.
#
create table t2 (s1 int, s2 char(5));
insert into t2 values (1,'a');
insert into t2 values (null,null);
insert into t2 values (1,null);
insert into t2 values (null,'a');
insert into t2 values (null,'c');
insert into t2 values (2,'b');
insert into t2 values (-1,'');
select *, rank() over (order by s1) as rank,
dense_rank() over (order by s1) as dense_rank
from t2;
s1 s2 rank dense_rank
1 a 5 3
NULL NULL 1 1
1 NULL 5 3
NULL a 1 1
NULL c 1 1
2 b 7 4
-1 4 2
select *, rank() over (partition by s2 order by s1) as rank,
dense_rank() over (partition by s2 order by s1) as dense_rank
from t2;
s1 s2 rank dense_rank
1 a 2 2
NULL NULL 1 1
1 NULL 2 2
NULL a 1 1
NULL c 1 1
2 b 1 1
-1 1 1
select *, rank() over (order by s2) as rank,
dense_rank() over (order by s2) as dense_rank
from t2;
s1 s2 rank dense_rank
1 a 4 3
NULL NULL 1 1
1 NULL 1 1
NULL a 4 3
NULL c 7 5
2 b 6 4
-1 3 2
select *, rank() over (partition by s1 order by s2) as rank,
dense_rank() over (partition by s1 order by s2) as dense_rank
from t2;
s1 s2 rank dense_rank
1 a 2 2
NULL NULL 1 1
1 NULL 1 1
NULL a 2 2
NULL c 3 3
2 b 1 1
-1 1 1
drop table t2;
create table t1 (
pk int primary key,
a int,
b int,
c real
);
insert into t1 values
(101 , 0, 10, 1.1),
(102 , 0, 10, 2.1),
(103 , 1, 10, 3.1),
(104 , 1, 10, 4.1),
(108 , 2, 10, 5.1),
(105 , 2, 20, 6.1),
(106 , 2, 20, 7.1),
(107 , 2, 20, 8.15),
(109 , 4, 20, 9.15),
(110 , 4, 20, 10.15),
(111 , 5, NULL, 11.15),
(112 , 5, 1, 12.25),
(113 , 5, NULL, 13.35),
(114 , 5, NULL, 14.50),
(115 , 5, NULL, 15.65),
(116 , 6, 1, NULL),
(117 , 6, 1, 10),
(118 , 6, 1, 1.1),
(119 , 6, 1, NULL),
(120 , 6, 1, NULL),
(121 , 6, 1, NULL),
(122 , 6, 1, 2.2),
(123 , 6, 1, 20.1),
(124 , 6, 1, -10.4),
(125 , 6, 1, NULL),
(126 , 6, 1, NULL),
(127 , 6, 1, NULL);
select pk, a, b, sum(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
from t1;
pk a b sum(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
101 0 10 20
102 0 10 20
103 1 10 20
104 1 10 20
105 2 20 40
106 2 20 60
107 2 20 50
108 2 10 30
109 4 20 40
110 4 20 40
111 5 NULL 1
112 5 1 1
113 5 NULL 1
114 5 NULL NULL
115 5 NULL NULL
116 6 1 2
117 6 1 3
118 6 1 3
119 6 1 3
120 6 1 3
121 6 1 3
122 6 1 3
123 6 1 3
124 6 1 3
125 6 1 3
126 6 1 3
127 6 1 2
select pk, a, c, sum(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
from t1;
pk a c sum(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
101 0 1.1 3.2
102 0 2.1 3.2
103 1 3.1 7.199999999999999
104 1 4.1 7.199999999999999
105 2 6.1 13.2
106 2 7.1 21.35
107 2 8.15 20.35
108 2 5.1 13.250000000000002
109 4 9.15 19.3
110 4 10.15 19.3
111 5 11.15 23.4
112 5 12.25 36.75
113 5 13.35 40.1
114 5 14.5 43.5
115 5 15.65 30.15
116 6 NULL 10
117 6 10 11.1
118 6 1.1 11.1
119 6 NULL 1.0999999999999996
120 6 NULL NULL
121 6 NULL 2.1999999999999997
122 6 2.2 22.3
123 6 20.1 11.9
124 6 -10.4 9.7
125 6 NULL -10.400000000000002
126 6 NULL NULL
127 6 NULL NULL
drop table t1;
......@@ -554,11 +554,11 @@ a
explain select sql_big_result distinct t1.a from t1,t2 order by t2.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 Using temporary
1 SIMPLE t2 index NULL PRIMARY 4 NULL 2 Using index; Distinct
1 SIMPLE t2 index NULL PRIMARY 4 NULL 2 Using index
explain select distinct t1.a from t1,t2 order by t2.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 Using temporary
1 SIMPLE t2 index NULL PRIMARY 4 NULL 2 Using index; Distinct
1 SIMPLE t2 index NULL PRIMARY 4 NULL 2 Using index
drop table t1,t2;
create table t1 (
c1 varchar(32),
......
......@@ -996,8 +996,33 @@ EXPLAIN SELECT a FROM t1 WHERE a < 2 ORDER BY a;
EXPLAIN SELECT a FROM t1 WHERE a < 2 GROUP BY a;
EXPLAIN SELECT a FROM t1 IGNORE INDEX (PRIMARY,i2);
EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR JOIN (PRIMARY,i2);
--echo #
--echo # For this explain, the query plan is weird: if we are using
--echo # the primary key for reasons other than doing grouping, can't
--echo # GROUP BY code take advantage of this? Well, currently it doesnt:
EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR GROUP BY (PRIMARY,i2) GROUP BY a;
--echo # Here's a proof it is really doing sorting:
flush status;
--disable_result_log
SELECT a FROM t1 IGNORE INDEX FOR GROUP BY (PRIMARY,i2) GROUP BY a;
--enable_result_log
show status like 'Sort_%';
--echo # Proof ends.
--echo #
--echo # For this explain, the query plan is weird: if we are using
--echo # the primary key for reasons other than doing sorting, can't
--echo # ORDER BY code take advantage of this? Well, currently it doesnt:
EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY,i2) ORDER BY a;
--echo # Here's a proof it is really doing sorting:
flush status;
--disable_result_log
SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY,i2) ORDER BY a;
--enable_result_log
show status like 'Sort_%';
--echo # Proof ends.
--echo #
SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY,i2) ORDER BY a;
EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY)
IGNORE INDEX FOR GROUP BY (i2) GROUP BY a;
......
......@@ -305,7 +305,6 @@ select c1, sum(c2) from t3 group by c1;
explain
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 0;
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 0;
--error 1028
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 1;
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 20;
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 21;
......@@ -321,7 +320,6 @@ insert into t3i values
explain
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 0;
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 0;
--error 1028
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 1;
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 20;
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 21;
......@@ -432,7 +430,7 @@ drop table t1,t2,t1i,t2i;
SET @@optimizer_switch='in_to_exists=on,outer_join_with_cache=on';
CREATE TABLE t1 ( a VARCHAR(3) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('USA');
INSERT INTO t1 VALUES ('USA'),('CAN');
CREATE TABLE t2 ( b INT );
INSERT INTO t2 VALUES (3899),(3914),(3888);
......
This diff is collapsed.
create table t1 (
pk int primary key,
a int,
b int,
c real
);
insert into t1 values
(101 , 0, 10, 1.1),
(102 , 0, 10, 2.1),
(103 , 1, 10, 3.1),
(104 , 1, 10, 4.1),
(108 , 2, 10, 5.1),
(105 , 2, 20, 6.1),
(106 , 2, 20, 7.1),
(107 , 2, 20, 8.15),
(109 , 4, 20, 9.15),
(110 , 4, 20, 10.15),
(111 , 5, NULL, 11.15),
(112 , 5, 1, 12.25),
(113 , 5, NULL, 13.35),
(114 , 5, NULL, 14.50),
(115 , 5, NULL, 15.65),
(116 , 6, 1, NULL),
(117 , 6, 1, 10),
(118 , 6, 1, 1.1),
(119 , 6, 1, NULL),
(120 , 6, 1, NULL),
(121 , 6, 1, NULL),
(122 , 6, 1, 2.2),
(123 , 6, 1, 20.1),
(124 , 6, 1, -10.4),
(125 , 6, 1, NULL),
(126 , 6, 1, NULL),
(127 , 6, 1, NULL);
--sorted_result
select pk, a, b, avg(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
from t1;
--sorted_result
select pk, a, c, avg(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
from t1;
drop table t1;
create table t1 (
pk int primary key,
a int,
b int
);
create table t2 (
pk int primary key,
a int,
b int
);
insert into t1 values
( 1 , 0, 1),
( 2 , 0, 2),
( 3 , 1, 4),
( 4 , 1, 8),
( 5 , 2, 32),
( 6 , 2, 64),
( 7 , 2, 128),
( 8 , 2, 16);
insert into t2 values
( 1 , 0, 2),
( 2 , 0, 2),
( 3 , 1, 4),
( 4 , 1, 4),
( 5 , 2, 16),
( 6 , 2, 64),
( 7 , 2, 128),
( 8 , 2, 16);
--echo # Test bit functions on only one partition.
select pk, a, b,
bit_or(b) over (order by pk) as bit_or,
bit_and(b) over (order by pk) as bit_and,
bit_xor(b) over (order by pk) as bit_xor
from t1;
select pk, a, b,
bit_or(b) over (order by pk) as bit_or,
bit_and(b) over (order by pk) as bit_and,
bit_xor(b) over (order by pk) as bit_xor
from t2;
--echo # Test multiple partitions with bit functions.
select pk, a, b,
bit_or(b) over (partition by a order by pk) as bit_or,
bit_and(b) over (partition by a order by pk) as bit_and,
bit_xor(b) over (partition by a order by pk) as bit_xor
from t1;
select pk, a, b,
bit_or(b) over (partition by a order by pk) as bit_or,
bit_and(b) over (partition by a order by pk) as bit_and,
bit_xor(b) over (partition by a order by pk) as bit_xor
from t2;
--echo # Test remove function for bit functions using a sliding window.
select pk, a, b,
bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as bit_or,
bit_and(b) over (partition by a order by pk) as bit_and,
bit_xor(b) over (partition by a order by pk) as bit_xor
from t1;
select pk, a, b,
bit_or(b) over (partition by a order by pk) as bit_or,
bit_and(b) over (partition by a order by pk) as bit_and,
bit_xor(b) over (partition by a order by pk) as bit_xor
from t2;
#select pk, a, b, bit_or(b) over (order by a) as count from t1 order by a, pk;
#select pk, a, b, bit_and(b) over (order by a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as count from t1 order by a, pk;
#select pk, a, b, bit_xor(b) over (order by a, pk ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as count from t2 order by pk;
#select pk, a, b, bit_or(b) over (order by a, pk ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as count from t2 order by pk;
#select pk, a, b, bit_and(b) over (order by a, pk ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) as count from t3 order by pk;
drop table t1;
drop table t2;
create table t1 (
pk int primary key,
a int,
b int
);
insert into t1 values
(11 , 0, 10),
(12 , 0, 10),
(13 , 1, 10),
(14 , 1, 10),
(18 , 2, 10),
(15 , 2, 20),
(16 , 2, 20),
(17 , 2, 20),
(19 , 4, 20),
(20 , 4, 20);
# TODO Try invalid queries too.
--error ER_INVALID_NTILE_ARGUMENT
select pk, a, b, ntile(-1) over (order by a)
from t1;
--error ER_INVALID_NTILE_ARGUMENT
select pk, a, b,
ntile(0) over (order by a)
from t1;
--sorted_result
select pk, a, b,
ntile(1) over (order by pk)
from t1;
--sorted_result
select pk, a, b,
ntile(2) over (order by pk)
from t1;
--sorted_result
select pk, a, b,
ntile(3) over (order by pk)
from t1;
--sorted_result
select pk, a, b,
ntile(4) over (order by pk)
from t1;
--sorted_result
select pk, a, b,
ntile(5) over (order by pk)
from t1;
--sorted_result
select pk, a, b,
ntile(6) over (order by pk)
from t1;
--sorted_result
select pk, a, b,
ntile(7) over (order by pk)
from t1;
--sorted_result
select pk, a, b,
ntile(8) over (order by pk)
from t1;
--sorted_result
select pk, a, b,
ntile(9) over (order by pk)
from t1;
--sorted_result
select pk, a, b,
ntile(10) over (order by pk)
from t1;
--sorted_result
select pk, a, b,
ntile(11) over (order by pk)
from t1;
--sorted_result
select pk, a, b,
ntile(20) over (order by pk)
from t1;
select pk, a, b,
ntile(1) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile(2) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile(3) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile(4) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile(5) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile(6) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile(7) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile(8) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile(9) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile(10) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile(11) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile(20) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile(1 + 3) over (partition by b order by pk)
from t1;
select pk, a, b,
ntile((select 4)) over (partition by b order by pk)
from t1;
select t1.a from t1 where pk = 11;
--error ER_INVALID_NTILE_ARGUMENT
select pk, a, b,
ntile((select a from t1 where pk=11)) over (partition by b order by pk)
from t1;
select t1.a from t1 where pk = 13;
select pk, a, b,
ntile((select a from t1 where pk=13)) over (partition by b order by pk)
from t1;
explain
select pk, a, b,
ntile((select a from t1 where pk=13)) over (partition by b order by pk)
from t1;
select a from t1;
--error ER_SUBQUERY_NO_1_ROW
select pk, a, b,
ntile((select a from t1)) over (partition by b order by pk)
from t1;
drop table t1;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment