Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/10.3' into bb-10.3-cc
Browse files Browse the repository at this point in the history
  • Loading branch information
vaintroub committed May 19, 2018
2 parents 0d4df3c + e4e0aea commit 3a50a13
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 15 deletions.
30 changes: 30 additions & 0 deletions mysql-test/main/custom_aggregate_functions.result
Original file line number Diff line number Diff line change
Expand Up @@ -1123,3 +1123,33 @@ t1 CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
DROP FUNCTION f1;
#
# MDEV-14520: Custom aggregate functions work incorrectly with WITH ROLLUP clause
#
create aggregate function agg_sum(x INT) returns INT
begin
declare z int default 0;
declare continue handler for not found return z;
loop
fetch group next row;
set z= z+x;
end loop;
end|
create table t1 (i int);
insert into t1 values (1),(2),(2),(3);
select i, agg_sum(i) from t1 group by i with rollup;
i agg_sum(i)
1 1
2 4
3 3
NULL 8
#
# Compare with
select i, sum(i) from t1 group by i with rollup;
i sum(i)
1 1
2 4
3 3
NULL 8
drop function agg_sum;
drop table t1;
26 changes: 26 additions & 0 deletions mysql-test/main/custom_aggregate_functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -939,3 +939,29 @@ SHOW CREATE TABLE t1;
DROP TABLE t1;
DROP FUNCTION f1;

--echo #
--echo # MDEV-14520: Custom aggregate functions work incorrectly with WITH ROLLUP clause
--echo #

--delimiter |
create aggregate function agg_sum(x INT) returns INT
begin
declare z int default 0;
declare continue handler for not found return z;
loop
fetch group next row;
set z= z+x;
end loop;
end|
--delimiter ;

create table t1 (i int);
insert into t1 values (1),(2),(2),(3);
select i, agg_sum(i) from t1 group by i with rollup;
--echo #
--echo # Compare with
select i, sum(i) from t1 group by i with rollup;

# Cleanup
drop function agg_sum;
drop table t1;
21 changes: 21 additions & 0 deletions mysql-test/main/sp-code.result
Original file line number Diff line number Diff line change
Expand Up @@ -1301,3 +1301,24 @@ Pos Instruction
28 jump 4
29 cpop 1
DROP PROCEDURE p1;
#
# MDEV-14623: Output of show function code does not show FETCH GROUP NEXT ROW
# for custom aggregates
#
create aggregate function f1(x INT) returns int
begin
declare continue handler for not found return 0;
loop
fetch group next row;
insert into t2 (sal) values (x);
end loop;
end|
show function code f1;
Pos Instruction
0 hpush_jump 2 1 CONTINUE
1 freturn int 0
2 agg_cfetch
3 stmt 5 "insert into t2 (sal) values (x)"
4 jump 2
5 hpop 1
drop function f1;
19 changes: 19 additions & 0 deletions mysql-test/main/sp-code.test
Original file line number Diff line number Diff line change
Expand Up @@ -927,3 +927,22 @@ $$
DELIMITER ;$$
SHOW PROCEDURE CODE p1;
DROP PROCEDURE p1;

--echo #
--echo # MDEV-14623: Output of show function code does not show FETCH GROUP NEXT ROW
--echo # for custom aggregates
--echo #

delimiter |;
create aggregate function f1(x INT) returns int
begin
declare continue handler for not found return 0;
loop
fetch group next row;
insert into t2 (sal) values (x);
end loop;
end|

delimiter ;|
show function code f1;
drop function f1;
4 changes: 0 additions & 4 deletions mysql-test/suite/storage_engine/parts/repair_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ a b
15 o
Warnings:
Error 145 Table './test/t1#P#p0' is marked as crashed and should be repaired
Error 1194 Table 't1' is marked as crashed and should be repaired
Error 1034 Number of rows changed from 3 to 2
# Statement ended with one of expected results (0,ER_NOT_KEYFILE,144).
# If you got a difference in error message, just add it to rdiff file
Expand All @@ -152,7 +151,6 @@ a b
15 o
Warnings:
Error 145 Table './test/t1#P#p0' is marked as crashed and should be repaired
Error 1194 Table 't1' is marked as crashed and should be repaired
Error 1034 Number of rows changed from 2 to 3
# Statement ended with one of expected results (0,ER_NOT_KEYFILE,144).
# If you got a difference in error message, just add it to rdiff file
Expand All @@ -177,7 +175,6 @@ a b
15 o
Warnings:
Error 145 Table './test/t1#P#p1' is marked as crashed and should be repaired
Error 1194 Table 't1' is marked as crashed and should be repaired
Error 1034 Number of rows changed from 4 to 3
# Statement ended with one of expected results (0,ER_NOT_KEYFILE,144).
# If you got a difference in error message, just add it to rdiff file
Expand Down Expand Up @@ -206,7 +203,6 @@ a b
15 o
Warnings:
Error 145 Table './test/t1#P#p1' is marked as crashed and should be repaired
Error 1194 Table 't1' is marked as crashed and should be repaired
Error 1034 Number of rows changed from 3 to 4
# Statement ended with one of expected results (0,ER_NOT_KEYFILE,144).
# If you got a difference in error message, just add it to rdiff file
Expand Down
11 changes: 11 additions & 0 deletions sql/item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2802,6 +2802,17 @@ Item_sp::Item_sp(THD *thd, Name_resolution_context *context_arg,
memset(&sp_mem_root, 0, sizeof(sp_mem_root));
}

Item_sp::Item_sp(THD *thd, Item_sp *item):
context(item->context), m_name(item->m_name),
m_sp(item->m_sp), func_ctx(NULL), sp_result_field(NULL)
{
dummy_table= (TABLE*) thd->calloc(sizeof(TABLE)+ sizeof(TABLE_SHARE) +
sizeof(Query_arena));
dummy_table->s= (TABLE_SHARE*) (dummy_table+1);
sp_query_arena= (Query_arena *) (dummy_table->s + 1);
memset(&sp_mem_root, 0, sizeof(sp_mem_root));
}

const char *
Item_sp::func_name(THD *thd) const
{
Expand Down
1 change: 1 addition & 0 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -4658,6 +4658,7 @@ class Item_sp
*/
Field *sp_result_field;
Item_sp(THD *thd, Name_resolution_context *context_arg, sp_name *name_arg);
Item_sp(THD *thd, Item_sp *item);
const char *func_name(THD *thd) const;
void cleanup();
bool sp_check_access(THD *thd);
Expand Down
14 changes: 14 additions & 0 deletions sql/item_sum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,12 @@ Item_sum_sp::Item_sum_sp(THD *thd, Name_resolution_context *context_arg,
m_sp= sp;
}

Item_sum_sp::Item_sum_sp(THD *thd, Item_sum_sp *item):
Item_sum(thd, item), Item_sp(thd, item)
{
maybe_null= item->maybe_null;
quick_group= item->quick_group;
}

bool
Item_sum_sp::fix_fields(THD *thd, Item **ref)
Expand Down Expand Up @@ -1400,6 +1406,14 @@ Item_sum_sp::func_name() const
return Item_sp::func_name(thd);
}

Item* Item_sum_sp::copy_or_same(THD *thd)
{
Item_sum_sp *copy_item= new (thd->mem_root) Item_sum_sp(thd, this);
copy_item->init_result_field(thd, max_length, maybe_null,
&copy_item->null_value, &copy_item->name);
return copy_item;
}

/***********************************************************************
** reset and add of sum_func
***********************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions sql/item_sum.h
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ class Item_sum_sp :public Item_sum,

Item_sum_sp(THD *thd, Name_resolution_context *context_arg, sp_name *name,
sp_head *sp, List<Item> &list);
Item_sum_sp(THD *thd, Item_sum_sp *item);

enum Sumfunctype sum_func () const
{
Expand Down Expand Up @@ -1361,6 +1362,7 @@ class Item_sum_sp :public Item_sum,
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_sum_sp>(thd, this); }
Item *copy_or_same(THD *thd);
};

/* Items to get the value of a stored sum function */
Expand Down
11 changes: 10 additions & 1 deletion sql/sp_head.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4409,7 +4409,7 @@ sp_instr_cfetch::print(String *str)
int
sp_instr_agg_cfetch::execute(THD *thd, uint *nextp)
{
DBUG_ENTER("sp_instr_cfetch::execute");
DBUG_ENTER("sp_instr_agg_cfetch::execute");
int res= 0;
if (!thd->spcont->instr_ptr)
{
Expand All @@ -4434,7 +4434,16 @@ sp_instr_agg_cfetch::execute(THD *thd, uint *nextp)
DBUG_RETURN(res);
}

void
sp_instr_agg_cfetch::print(String *str)
{

uint rsrv= SP_INSTR_UINT_MAXLEN+11;

if (str->reserve(rsrv))
return;
str->qs_append(STRING_WITH_LEN("agg_cfetch"));
}

/*
sp_instr_cursor_copy_struct class functions
Expand Down
2 changes: 1 addition & 1 deletion sql/sp_head.h
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ class sp_instr_agg_cfetch : public sp_instr

virtual int execute(THD *thd, uint *nextp);

virtual void print(String *str){};
virtual void print(String *str);
}; // class sp_instr_agg_cfetch : public sp_instr


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
call mtr.add_suppression("Found 2 prepared XA transactions");
FLUSH TABLES;
DROP TABLE IF EXISTS t1;
@@ -18,12 +24,18 @@
@@ -18,12 +24,17 @@
connection default;
XA RECOVER;
formatID gtrid_length bqual_length data
Expand All @@ -28,6 +28,5 @@
4
+Warnings:
+Error 145 Table './test/t1' is marked as crashed and should be repaired
+Error 1194 Table 't1' is marked as crashed and should be repaired
+Error 1034 1 client is using or hasn't closed the table properly
DROP TABLE t1;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- suite/storage_engine/parts/repair_table.result 2017-08-28 19:29:20.491633306 +0300
+++ suite/storage_engine/parts/repair_table.reject 2017-08-28 19:34:41.723633059 +0300
@@ -1,236 +1,116 @@
@@ -1,232 +1,116 @@
call mtr.add_suppression("Table '.*t1.*' is marked as crashed and should be repaired");
DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS> PARTITION BY HASH(a) PARTITIONS 2;
Expand Down Expand Up @@ -192,7 +192,6 @@
-15 o
-Warnings:
-Error 145 Table './test/t1#P#p0' is marked as crashed and should be repaired
-Error 1194 Table 't1' is marked as crashed and should be repaired
-Error 1034 Number of rows changed from 3 to 2
-# Statement ended with one of expected results (0,ER_NOT_KEYFILE,144).
-# If you got a difference in error message, just add it to rdiff file
Expand All @@ -218,7 +217,6 @@
-15 o
-Warnings:
-Error 145 Table './test/t1#P#p0' is marked as crashed and should be repaired
-Error 1194 Table 't1' is marked as crashed and should be repaired
-Error 1034 Number of rows changed from 2 to 3
-# Statement ended with one of expected results (0,ER_NOT_KEYFILE,144).
-# If you got a difference in error message, just add it to rdiff file
Expand All @@ -243,7 +241,6 @@
-15 o
-Warnings:
-Error 145 Table './test/t1#P#p1' is marked as crashed and should be repaired
-Error 1194 Table 't1' is marked as crashed and should be repaired
-Error 1034 Number of rows changed from 4 to 3
-# Statement ended with one of expected results (0,ER_NOT_KEYFILE,144).
-# If you got a difference in error message, just add it to rdiff file
Expand Down Expand Up @@ -272,7 +269,6 @@
-15 o
-Warnings:
-Error 145 Table './test/t1#P#p1' is marked as crashed and should be repaired
-Error 1194 Table 't1' is marked as crashed and should be repaired
-Error 1034 Number of rows changed from 3 to 4
-# Statement ended with one of expected results (0,ER_NOT_KEYFILE,144).
-# If you got a difference in error message, just add it to rdiff file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
call mtr.add_suppression("Found 2 prepared XA transactions");
FLUSH TABLES;
DROP TABLE IF EXISTS t1;
@@ -18,12 +24,18 @@
@@ -18,12 +24,17 @@
connection default;
XA RECOVER;
formatID gtrid_length bqual_length data
Expand All @@ -28,6 +28,5 @@
4
+Warnings:
+Error 145 Table './mrg/t1' is marked as crashed and should be repaired
+Error 1194 Table 't1' is marked as crashed and should be repaired
+Error 1034 1 client is using or hasn't closed the table properly
DROP TABLE t1;

0 comments on commit 3a50a13

Please sign in to comment.