Commit 44a6af65 authored by Vicențiu Ciorbaru's avatar Vicențiu Ciorbaru

MDEV-25430: ROW | ROWS should be a required keyword after OFFSET start

Implemented according to standard OFFSET start { ROW | ROWS},
ROW and ROWS is mandatory after OFFSET.
parent 299b9353
This diff is collapsed.
...@@ -18,11 +18,12 @@ insert into t_keyword values (1), (1), (2), (3), (2); ...@@ -18,11 +18,12 @@ insert into t_keyword values (1), (1), (2), (3), (2);
--echo # --echo #
select * from t1 select * from t1
order by a order by a
offset 2; offset 2 rows;
--sorted_result --sorted_result
select * from t1 select * from t1
offset 2; offset 2 rows;
--echo # --echo #
...@@ -55,24 +56,48 @@ select * from t1 ...@@ -55,24 +56,48 @@ select * from t1
fetch next rows only; fetch next rows only;
--echo # --echo #
--echo # Include offset before fetch clause. --echo # Row / rows are mandatory after offset <n>
--echo # --echo #
--error 1064
select * from t1 select * from t1
order by a order by a
offset 2 offset 2
fetch first row only; fetch first row only;
--error 1064
select * from t1
order by a
offset 2;
select * from t1 select * from t1
order by a order by a
offset 2 offset 2 row
fetch first row only;
select * from t1
order by a
offset 2 rows
fetch first row only;
--echo #
--echo # Include offset before fetch clause.
--echo #
select * from t1
order by a
offset 2 rows
fetch first row only;
select * from t1
order by a
offset 2 rows
fetch first rows only; fetch first rows only;
select * from t1 select * from t1
offset 2 offset 2 rows
fetch next row only; fetch next row only;
select * from t1 select * from t1
offset 2 offset 2 rows
fetch next rows only; fetch next rows only;
...@@ -119,22 +144,22 @@ fetch next rows with ties; ...@@ -119,22 +144,22 @@ fetch next rows with ties;
select * from t1 select * from t1
order by a order by a
offset 2 offset 2 rows
fetch first row with ties; fetch first row with ties;
select * from t1 select * from t1
order by a order by a
offset 2 offset 2 rows
fetch first rows with ties; fetch first rows with ties;
select * from t1 select * from t1
order by a order by a
offset 2 offset 2 rows
fetch next row with ties; fetch next row with ties;
select * from t1 select * from t1
order by a order by a
offset 2 offset 2 rows
fetch next rows with ties; fetch next rows with ties;
...@@ -158,20 +183,20 @@ fetch next 3 rows only; ...@@ -158,20 +183,20 @@ fetch next 3 rows only;
--echo # --echo #
select * from t1 select * from t1
order by a order by a
offset 2 offset 2 rows
fetch first 3 row only; fetch first 3 row only;
select * from t1 select * from t1
order by a order by a
offset 2 offset 2 rows
fetch first 3 rows only; fetch first 3 rows only;
select * from t1 select * from t1
offset 2 offset 2 rows
fetch next 3 row only; fetch next 3 row only;
select * from t1 select * from t1
offset 2 offset 2 rows
fetch next 3 rows only; fetch next 3 rows only;
...@@ -218,27 +243,27 @@ fetch next 3 rows with ties; ...@@ -218,27 +243,27 @@ fetch next 3 rows with ties;
--error ER_WITH_TIES_NEEDS_ORDER --error ER_WITH_TIES_NEEDS_ORDER
select * from t1 select * from t1
offset 2 offset 2 rows
fetch first row with ties; fetch first row with ties;
select * from t1 select * from t1
order by a order by a
offset 2 offset 2 rows
fetch first 3 row with ties; fetch first 3 row with ties;
select * from t1 select * from t1
order by a order by a
offset 2 offset 2 rows
fetch first 3 rows with ties; fetch first 3 rows with ties;
select * from t1 select * from t1
order by a order by a
offset 2 offset 2 rows
fetch next 3 row with ties; fetch next 3 row with ties;
select * from t1 select * from t1
order by a order by a
offset 2 offset 2 rows
fetch next 3 rows with ties; fetch next 3 rows with ties;
...@@ -309,47 +334,47 @@ fetch first 4 rows with ties; ...@@ -309,47 +334,47 @@ fetch first 4 rows with ties;
select * from t1 select * from t1
order by first_name, last_name order by first_name, last_name
offset 1 offset 1 rows
fetch first 3 rows with ties; fetch first 3 rows with ties;
select * from t1 select * from t1
order by first_name, last_name order by first_name, last_name
offset 1 offset 1 rows
fetch first 3 rows only; fetch first 3 rows only;
select * from t1 select * from t1
order by first_name, last_name order by first_name, last_name
offset 1 offset 1 rows
fetch first 3 rows with ties; fetch first 3 rows with ties;
select * from t1 select * from t1
order by first_name, last_name order by first_name, last_name
offset 2 offset 2 rows
fetch first 3 rows only; fetch first 3 rows only;
select * from t1 select * from t1
order by first_name, last_name order by first_name, last_name
offset 2 offset 2 rows
fetch first 3 rows with ties; fetch first 3 rows with ties;
select * from t1 select * from t1
order by first_name, last_name order by first_name, last_name
offset 3 offset 3 rows
fetch first 3 rows only; fetch first 3 rows only;
select * from t1 select * from t1
order by first_name, last_name order by first_name, last_name
offset 3 offset 3 rows
fetch first 3 rows with ties; fetch first 3 rows with ties;
select * from t1 select * from t1
order by first_name, last_name order by first_name, last_name
offset 4 offset 4 rows
fetch first 3 rows only; fetch first 3 rows only;
select * from t1 select * from t1
order by first_name, last_name order by first_name, last_name
offset 4 offset 4 rows
fetch first 3 rows with ties; fetch first 3 rows with ties;
--echo # --echo #
...@@ -357,12 +382,12 @@ fetch first 3 rows with ties; ...@@ -357,12 +382,12 @@ fetch first 3 rows with ties;
--echo # --echo #
select * from t1 select * from t1
order by first_name, last_name order by first_name, last_name
offset 5 offset 5 rows
fetch first 3 rows with ties; fetch first 3 rows with ties;
select * from t1 select * from t1
order by first_name, last_name order by first_name, last_name
offset 5 offset 5 rows
fetch first 3 rows only; fetch first 3 rows only;
--echo # --echo #
...@@ -407,13 +432,13 @@ fetch first 2 rows with ties; ...@@ -407,13 +432,13 @@ fetch first 2 rows with ties;
--sorted_result --sorted_result
select * from t2 select * from t2
order by t2.location desc order by t2.location desc
offset 1 offset 1 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
--sorted_result --sorted_result
select * from t2 select * from t2
order by t2.location desc order by t2.location desc
offset 2 offset 2 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
--echo # --echo #
...@@ -430,34 +455,34 @@ fetch first 3 rows with ties; ...@@ -430,34 +455,34 @@ fetch first 3 rows with ties;
select * from ( select * from (
select * from t2 select * from t2
order by t2.location desc order by t2.location desc
offset 2 offset 2 rows
fetch first 2 rows with ties fetch first 2 rows with ties
) temp; ) temp;
select * from t2 select * from t2
order by t2.location desc order by t2.location desc
offset 0 offset 0 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
create view v1 as ( create view v1 as (
select * from t2 select * from t2
order by t2.location desc order by t2.location desc
offset 0 offset 0 rows
fetch first 2 rows with ties fetch first 2 rows with ties
); );
create view v2 as ( create view v2 as (
select * from t2 select * from t2
order by t2.location desc order by t2.location desc
offset 1 offset 1 rows
fetch first 2 rows with ties fetch first 2 rows with ties
); );
create view v3 as ( create view v3 as (
select * from t2 select * from t2
order by t2.location desc order by t2.location desc
offset 2 offset 2 rows
fetch first row with ties fetch first row with ties
); );
...@@ -479,7 +504,7 @@ show create view v3; ...@@ -479,7 +504,7 @@ show create view v3;
select * select *
from t1 inner join v1 on t1.id = v1.fk from t1 inner join v1 on t1.id = v1.fk
order by v1.location desc, t1.first_name order by v1.location desc, t1.first_name
offset 1 offset 1 rows
fetch first 1 rows with ties; fetch first 1 rows with ties;
select first_name, last_name, sum(score) select first_name, last_name, sum(score)
...@@ -497,7 +522,7 @@ select first_name, last_name, sum(score) ...@@ -497,7 +522,7 @@ select first_name, last_name, sum(score)
from t1 from t1
group by first_name, last_name group by first_name, last_name
order by first_name order by first_name
offset 1 offset 1 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
--sorted_result --sorted_result
...@@ -505,7 +530,7 @@ select first_name, last_name, sum(score) ...@@ -505,7 +530,7 @@ select first_name, last_name, sum(score)
from t1 from t1
group by first_name, last_name group by first_name, last_name
order by first_name order by first_name
offset 1 offset 1 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
...@@ -536,7 +561,7 @@ insert into t1 values ...@@ -536,7 +561,7 @@ insert into t1 values
explain select first_name, last_name explain select first_name, last_name
from t1 from t1
order by first_name order by first_name
offset 1 offset 1 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
explain select first_name, last_name explain select first_name, last_name
...@@ -548,7 +573,7 @@ fetch first 2 rows with ties; ...@@ -548,7 +573,7 @@ fetch first 2 rows with ties;
select first_name, last_name select first_name, last_name
from t1 from t1
order by first_name order by first_name
offset 1 offset 1 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
select first_name, last_name select first_name, last_name
...@@ -560,19 +585,19 @@ fetch first 2 rows with ties; ...@@ -560,19 +585,19 @@ fetch first 2 rows with ties;
select first_name, last_name select first_name, last_name
from t1 from t1
order by first_name desc order by first_name desc
offset 1 offset 1 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
select first_name, last_name select first_name, last_name
from t1 from t1
order by first_name desc order by first_name desc
offset 4 offset 4 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
select first_name, last_name select first_name, last_name
from t1 from t1
order by first_name desc order by first_name desc
offset 4 offset 4 rows
fetch first 3 rows with ties; fetch first 3 rows with ties;
explain select first_name, last_name explain select first_name, last_name
...@@ -654,20 +679,20 @@ with temp_table as ( ...@@ -654,20 +679,20 @@ with temp_table as (
) )
select * from temp_table select * from temp_table
order by first_name order by first_name
offset 1 offset 1 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
select first_name, row_number() over () rn select first_name, row_number() over () rn
from t1 from t1
order by rn order by rn
offset 1 offset 1 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
select first_name, row_number() over () rn select first_name, row_number() over () rn
from t1 from t1
order by rn desc order by rn desc
offset 1 offset 1 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
select first_name, score, rank() over (ORDER BY score) select first_name, score, rank() over (ORDER BY score)
...@@ -678,7 +703,7 @@ fetch first 3 rows with ties; ...@@ -678,7 +703,7 @@ fetch first 3 rows with ties;
select first_name, score, rank() over (ORDER BY score) select first_name, score, rank() over (ORDER BY score)
from t1 from t1
order by rank() over (ORDER BY score) order by rank() over (ORDER BY score)
offset 1 offset 1 rows
fetch first 2 rows with ties; fetch first 2 rows with ties;
select first_name, score, rank() over (ORDER BY score) select first_name, score, rank() over (ORDER BY score)
...@@ -732,7 +757,7 @@ fetch first 3 row with ties; ...@@ -732,7 +757,7 @@ fetch first 3 row with ties;
select * select *
from t1 left join t2 on t1.id = t2.fk from t1 left join t2 on t1.id = t2.fk
order by t2.location order by t2.location
offset 2 offset 2 rows
fetch first 1 row with ties; fetch first 1 row with ties;
...@@ -761,7 +786,7 @@ fetch first 1 row with ties; ...@@ -761,7 +786,7 @@ fetch first 1 row with ties;
except except
(select * from t1 order by first_name desc fetch first 3 rows with ties) (select * from t1 order by first_name desc fetch first 3 rows with ties)
order by first_name order by first_name
offset 1 offset 1 rows
fetch first 1 row with ties; fetch first 1 row with ties;
--sorted_result --sorted_result
...@@ -827,7 +852,7 @@ set @a=-1; ...@@ -827,7 +852,7 @@ set @a=-1;
--error ER_WRONG_ARGUMENTS --error ER_WRONG_ARGUMENTS
execute s using @a; execute s using @a;
prepare s2 from "select a, b from t1 order by a offset ? fetch first ? rows with ties"; prepare s2 from "select a, b from t1 order by a offset ? rows fetch first ? rows with ties";
set @offset=1; set @offset=1;
set @limit_count= 2; set @limit_count= 2;
execute s2 using @offset, @limit_count; execute s2 using @offset, @limit_count;
......
...@@ -3789,6 +3789,7 @@ void st_select_lex::print_limit(THD *thd, ...@@ -3789,6 +3789,7 @@ void st_select_lex::print_limit(THD *thd,
{ {
str->append(STRING_WITH_LEN(" offset ")); str->append(STRING_WITH_LEN(" offset "));
limit_params.offset_limit->print(str, query_type); limit_params.offset_limit->print(str, query_type);
str->append(STRING_WITH_LEN(" rows "));
} }
str->append(STRING_WITH_LEN(" fetch first ")); str->append(STRING_WITH_LEN(" fetch first "));
limit_params.select_limit->print(str, query_type); limit_params.select_limit->print(str, query_type);
......
...@@ -12507,7 +12507,7 @@ fetch_first_clause: ...@@ -12507,7 +12507,7 @@ fetch_first_clause:
$$.explicit_limit= true; $$.explicit_limit= true;
$$.with_ties= $4; $$.with_ties= $4;
} }
| OFFSET_SYM limit_option | OFFSET_SYM limit_option row_or_rows
FETCH_SYM first_or_next row_or_rows only_or_with_ties FETCH_SYM first_or_next row_or_rows only_or_with_ties
{ {
Item *one= new (thd->mem_root) Item_int(thd, (int32) 1); Item *one= new (thd->mem_root) Item_int(thd, (int32) 1);
...@@ -12516,7 +12516,7 @@ fetch_first_clause: ...@@ -12516,7 +12516,7 @@ fetch_first_clause:
$$.select_limit= one; $$.select_limit= one;
$$.offset_limit= $2; $$.offset_limit= $2;
$$.explicit_limit= true; $$.explicit_limit= true;
$$.with_ties= $6; $$.with_ties= $7;
} }
| FETCH_SYM first_or_next limit_option row_or_rows only_or_with_ties | FETCH_SYM first_or_next limit_option row_or_rows only_or_with_ties
{ {
...@@ -12525,15 +12525,15 @@ fetch_first_clause: ...@@ -12525,15 +12525,15 @@ fetch_first_clause:
$$.explicit_limit= true; $$.explicit_limit= true;
$$.with_ties= $5; $$.with_ties= $5;
} }
| OFFSET_SYM limit_option | OFFSET_SYM limit_option row_or_rows
FETCH_SYM first_or_next limit_option row_or_rows only_or_with_ties FETCH_SYM first_or_next limit_option row_or_rows only_or_with_ties
{ {
$$.select_limit= $5; $$.select_limit= $6;
$$.offset_limit= $2; $$.offset_limit= $2;
$$.explicit_limit= true; $$.explicit_limit= true;
$$.with_ties= $7; $$.with_ties= $8;
} }
| OFFSET_SYM limit_option | OFFSET_SYM limit_option row_or_rows
{ {
$$.select_limit= 0; $$.select_limit= 0;
$$.offset_limit= $2; $$.offset_limit= $2;
...@@ -12546,6 +12546,7 @@ first_or_next: ...@@ -12546,6 +12546,7 @@ first_or_next:
FIRST_SYM FIRST_SYM
| NEXT_SYM | NEXT_SYM
; ;
row_or_rows: row_or_rows:
ROW_SYM ROW_SYM
| ROWS_SYM | ROWS_SYM
......
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