Commit 39109dd4 authored by Vicențiu Ciorbaru's avatar Vicențiu Ciorbaru

WIP -> just for backup

parent aa164035
......@@ -137,6 +137,7 @@ fetch next rows with ties;
--echo #
--echo # Include offset before fetch clause.
--echo #
select * from t1
order by a
offset 2
......@@ -148,10 +149,12 @@ offset 2
fetch first rows with ties;
select * from t1
order by a
offset 2
fetch next row with ties;
select * from t1
order by a
offset 2
fetch next rows with ties;
......@@ -159,6 +162,12 @@ fetch next rows with ties;
--echo #
--echo # Include offset after fetch clause.
--echo #
--error ER_WITH_TIES_NEEDS_ORDER
select * from t1
fetch first row with ties
offset 2;
select * from t1
order by a
fetch first row with ties
......@@ -279,6 +288,12 @@ fetch next 3 rows with ties;
--echo #
--echo # Include offset before fetch clause.
--echo #
--error ER_WITH_TIES_NEEDS_ORDER
select * from t1
offset 2
fetch first row with ties;
select * from t1
order by a
offset 2
......@@ -290,10 +305,12 @@ offset 2
fetch first 3 rows with ties;
select * from t1
order by a
offset 2
fetch next 3 row with ties;
select * from t1
order by a
offset 2
fetch next 3 rows with ties;
......@@ -301,6 +318,12 @@ fetch next 3 rows with ties;
--echo #
--echo # Include offset after fetch clause.
--echo #
--error ER_WITH_TIES_NEEDS_ORDER
select * from t1
fetch first row with ties
offset 2;
select * from t1
order by a
fetch first 3 row with ties
......@@ -321,73 +344,214 @@ order by a
fetch next 3 rows with ties
offset 2;
select @@optimizer_switch;
explain format=json select * from t1
order by a
FETCH FIRST 3 ROWS WITH TIES;
drop table t1;
drop table t_keyword;
--echo #
--echo # Test behaviour with a simple select.
--echo #
create table t1 (id int, first_name varchar(100), last_name varchar(100), score double);
insert into t1 values
(1, 'Alice', 'Fowler', 5),
(2, 'John', 'Doe', 6),
(3, 'John', 'Smith', 6),
(4, 'John', 'Smith', 6),
(5, 'John', 'Smith', 7),
(6, 'John', 'Elton', 8.1),
(7, 'Bob', 'Trasc', 9),
(8, 'Silvia', 'Ganush', 10);
create table t2
(id int,
location varchar(100),
fk int,
constraint `fk_t1`
FOREIGN KEY (fk) REFERENCES t1 (id)
ON DELETE CASCADE
ON UPDATE RESTRICT);
insert into t2 values
(1, 'L1', 1),
(2, 'L2', 2),
(3, 'L3', 3),
(4, 'L3', 4),
(5, 'L4', 5),
(6, 'L4', 6),
(7, 'L4', 7),
(7, null, 8);
select * from t1
order by id
fetch first 3 rows only;
select * from t1
order by id
fetch first 3 rows with ties;
select * from t1
order by a
FETCH FIRST 3 ROWS WITH TIES;
order by first_name
fetch first 3 rows only;
select * from t1
order by first_name
fetch first 3 rows with ties;
--echo #
--echo # Test multi-part order by.
--echo #
select * from t1
order by first_name, last_name
fetch first 3 rows with ties;
select * from t1
order by a
FETCH FIRST 2 ROWS ONLY
OFFSET 1;
order by first_name, last_name
fetch first 4 rows with ties;
select * from t1
order by a
OFFSET 1
FETCH FIRST 2 ROWS ONLY;
order by first_name, last_name
offset 1
fetch first 3 rows with ties;
select * from t1
order by a
OFFSET 1
FETCH FIRST 2 ROWS WITH TIES;
order by first_name, last_name
offset 1
fetch first 3 rows only;
select * from t1
order by a
OFFSET 1
FETCH FIRST 2 ROWS ONLY;
order by first_name, last_name
fetch first 3 rows with ties
offset 1;
select * from t1
order by a
limit 1;
order by first_name, last_name
offset 2
fetch first 3 rows only;
select * from t1
order by a
FETCH FIRST 2 ROWS WITH TIES;
order by first_name, last_name
offset 2
fetch first 3 rows with ties;
select * from t1
FETCH FIRST 2 ROWS ONLY;
order by first_name, last_name
offset 3
fetch first 3 rows only;
--error ER_WITH_TIES_NEEDS_ORDER
select * from t1
FETCH FIRST 2 ROWS WITH TIES;
order by first_name, last_name
offset 3
fetch first 3 rows with ties;
select * from t1
order by a
FETCH FIRST 2 ROWS WITH TIES
OFFSET 2;
order by first_name, last_name
offset 4
fetch first 3 rows only;
select * from t1
order by a
FETCH FIRST 3 ROWS WITH TIES;
order by first_name, last_name
offset 4
fetch first 3 rows with ties;
--echo #
--echo # Test offset crossing into a new peer-group.
--echo #
select * from t1
order by first_name, last_name
offset 5
fetch first 3 rows with ties;
(select * from t1
order by a
fetch first 3 rows with ties
offset 1)
union all
select * from t1
order by a;
order by first_name, last_name
offset 5
fetch first 3 rows only;
--echo #
--echo # Simple join with 2 tables, order by without columns in the
--echo # second table and also with columns in the second table.
--echo #
--echo # Cover both only and with ties.
--echo #
select t1.id, t1.first_name, t1.last_name, t1.score, t2.location
from t1 inner join t2 on t1.id = t2.fk
order by t1.first_name, t1.last_name
fetch first 3 rows only;
select t1.id, t1.first_name, t1.last_name, t1.score, t2.location
from t1 inner join t2 on t1.id = t2.fk
order by t2.location, t1.first_name, t1.last_name
fetch first 3 rows only;
select t1.id, t1.first_name, t1.last_name, t1.score, t2.location
from t1 inner join t2 on t1.id = t2.fk
order by t1.first_name, t1.last_name
fetch first 3 rows with ties;
select t1.id, t1.first_name, t1.last_name, t1.score, t2.location
from t1 inner join t2 on t1.id = t2.fk
order by t2.location, t1.first_name, t1.last_name
fetch first 3 rows with ties;
--echo #
--echo # Test descending order by.
--echo #
select t1.id, t1.first_name, t1.last_name, t1.score, t2.location
from t1 inner join t2 on t1.id = t2.fk
order by t2.location desc, t1.first_name, t1.last_name
fetch first 3 rows only;
--sorted_result
select * from t2
order by t2.location desc
fetch first 2 rows with ties;
--sorted_result
select * from t2
order by t2.location desc
offset 1
fetch first 2 rows with ties;
--sorted_result
select * from t2
order by t2.location desc
offset 2
fetch first 2 rows with ties;
--echo #
--echo # Test a join with descending order by.
--echo #
select t1.id, t1.first_name, t1.last_name, t1.score, t2.location
from t1 inner join t2 on t1.id = t2.fk
order by t2.location desc, t1.first_name, t1.last_name
fetch first 3 rows with ties;
--echo #
--echo # Test subqueries.
--echo #
select * from (
select * from t2
order by t2.location desc
offset 2
fetch first 2 rows with ties
) temp;
drop table t1;
drop table t2;
#(select * from t1
#order by a
#fetch first 3 rows with ties
#offset 1)
#union all
#select * from t1
#order by a;
# Test variables referenced.
# Subqueries
# Aggregation
# views
......@@ -399,3 +563,4 @@ drop table t1;
# In stored functions.
# With indexes / without indexes
# With sequences?
# Replication
......@@ -3813,6 +3813,7 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields,
}
else
{
//DBUG_ASSERT(0);
if (make_sum_func_list(all_fields, fields_list, false))
goto err;
if (prepare_sum_aggregators(sum_funcs,
......@@ -3826,6 +3827,14 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields,
{
DBUG_PRINT("info",("Sorting for order"));
THD_STAGE_INFO(thd, stage_sorting_for_order);
//DBUG_ASSERT(0);
if (select_lex->limit_params.with_ties)
{
// TODO see when this thing happens!
DBUG_ASSERT(0);
if (alloc_order_fields(this, order))
goto err;
}
if (ordered_index_usage != ordered_index_order_by &&
!only_const_tables() &&
......
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