Commit c370208a authored by unknown's avatar unknown

Merge moonlight.intranet:/home/tomash/src/mysql_ab/mysql-5.0-bug21354

into  moonlight.intranet:/home/tomash/src/mysql_ab/mysql-5.1-bug21354


mysql-test/t/func_gconcat.test:
  Auto merged
sql/item_sum.cc:
  Auto merged
sql/item_sum.h:
  Auto merged
mysql-test/r/ps.result:
  Manual merge.
mysql-test/t/ps.test:
  Manual merge.
parents a7f8da29 e32f277c
...@@ -1064,6 +1064,243 @@ select @@max_prepared_stmt_count, @@prepared_stmt_count; ...@@ -1064,6 +1064,243 @@ select @@max_prepared_stmt_count, @@prepared_stmt_count;
@@max_prepared_stmt_count @@prepared_stmt_count @@max_prepared_stmt_count @@prepared_stmt_count
3 0 3 0
set global max_prepared_stmt_count= @old_max_prepared_stmt_count; set global max_prepared_stmt_count= @old_max_prepared_stmt_count;
drop table if exists t1;
create temporary table if not exists t1 (a1 int);
prepare stmt from "delete t1 from t1 where (cast(a1/3 as unsigned) * 3) = a1";
drop temporary table t1;
create temporary table if not exists t1 (a1 int);
execute stmt;
drop temporary table t1;
create temporary table if not exists t1 (a1 int);
execute stmt;
drop temporary table t1;
create temporary table if not exists t1 (a1 int);
execute stmt;
drop temporary table t1;
deallocate prepare stmt;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (i INT, INDEX(i));
INSERT INTO t1 VALUES (1);
PREPARE stmt FROM "SELECT (COUNT(i) = 1), COUNT(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
(COUNT(i) = 1) COUNT(i)
0 0
SET @a = 1;
EXECUTE stmt USING @a;
(COUNT(i) = 1) COUNT(i)
1 1
SET @a = 0;
EXECUTE stmt USING @a;
(COUNT(i) = 1) COUNT(i)
0 0
PREPARE stmt FROM "SELECT (AVG(i) = 1), AVG(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
(AVG(i) = 1) AVG(i)
NULL NULL
SET @a = 1;
EXECUTE stmt USING @a;
(AVG(i) = 1) AVG(i)
1 1.0000
SET @a = 0;
EXECUTE stmt USING @a;
(AVG(i) = 1) AVG(i)
NULL NULL
PREPARE stmt FROM "SELECT (VARIANCE(i) = 1), VARIANCE(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
(VARIANCE(i) = 1) VARIANCE(i)
NULL NULL
SET @a = 1;
EXECUTE stmt USING @a;
(VARIANCE(i) = 1) VARIANCE(i)
0 0.0000
SET @a = 0;
EXECUTE stmt USING @a;
(VARIANCE(i) = 1) VARIANCE(i)
NULL NULL
PREPARE stmt FROM "SELECT (STDDEV(i) = 1), STDDEV(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
(STDDEV(i) = 1) STDDEV(i)
NULL NULL
SET @a = 1;
EXECUTE stmt USING @a;
(STDDEV(i) = 1) STDDEV(i)
0 0.0000
SET @a = 0;
EXECUTE stmt USING @a;
(STDDEV(i) = 1) STDDEV(i)
NULL NULL
PREPARE stmt FROM "SELECT (BIT_OR(i) = 1), BIT_OR(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
(BIT_OR(i) = 1) BIT_OR(i)
0 0
SET @a = 1;
EXECUTE stmt USING @a;
(BIT_OR(i) = 1) BIT_OR(i)
1 1
SET @a = 0;
EXECUTE stmt USING @a;
(BIT_OR(i) = 1) BIT_OR(i)
0 0
PREPARE stmt FROM "SELECT (BIT_AND(i) = 1), BIT_AND(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
(BIT_AND(i) = 1) BIT_AND(i)
0 18446744073709551615
SET @a = 1;
EXECUTE stmt USING @a;
(BIT_AND(i) = 1) BIT_AND(i)
1 1
SET @a = 0;
EXECUTE stmt USING @a;
(BIT_AND(i) = 1) BIT_AND(i)
0 18446744073709551615
PREPARE stmt FROM "SELECT (BIT_XOR(i) = 1), BIT_XOR(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
(BIT_XOR(i) = 1) BIT_XOR(i)
0 0
SET @a = 1;
EXECUTE stmt USING @a;
(BIT_XOR(i) = 1) BIT_XOR(i)
1 1
SET @a = 0;
EXECUTE stmt USING @a;
(BIT_XOR(i) = 1) BIT_XOR(i)
0 0
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
End of 4.1 tests.
create table t1 (a varchar(20));
insert into t1 values ('foo');
prepare stmt FROM 'SELECT char_length (a) FROM t1';
ERROR 42000: FUNCTION test.char_length does not exist
drop table t1;
create table t1 (a char(3) not null, b char(3) not null,
c char(3) not null, primary key (a, b, c));
create table t2 like t1;
prepare stmt from
"select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b)
where t1.a=1";
execute stmt;
a
execute stmt;
a
execute stmt;
a
prepare stmt from
"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from
(t1 left outer join t2 on t2.a=? and t1.b=t2.b)
left outer join t2 t3 on t3.a=? where t1.a=?";
set @a:=1, @b:=1, @c:=1;
execute stmt using @a, @b, @c;
a b c a b c
execute stmt using @a, @b, @c;
a b c a b c
execute stmt using @a, @b, @c;
a b c a b c
deallocate prepare stmt;
drop table t1,t2;
SET @aux= "SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS A,
INFORMATION_SCHEMA.COLUMNS B
WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA
AND A.TABLE_NAME = B.TABLE_NAME
AND A.COLUMN_NAME = B.COLUMN_NAME AND
A.TABLE_NAME = 'user'";
prepare my_stmt from @aux;
execute my_stmt;
COUNT(*)
37
execute my_stmt;
COUNT(*)
37
execute my_stmt;
COUNT(*)
37
deallocate prepare my_stmt;
drop procedure if exists p1|
drop table if exists t1|
create table t1 (id int)|
insert into t1 values(1)|
create procedure p1(a int, b int)
begin
declare c int;
select max(id)+1 into c from t1;
insert into t1 select a+b;
insert into t1 select a-b;
insert into t1 select a-c;
end|
set @a= 3, @b= 4|
prepare stmt from "call p1(?, ?)"|
execute stmt using @a, @b|
execute stmt using @a, @b|
select * from t1|
id
1
7
-1
1
7
-1
-5
deallocate prepare stmt|
drop procedure p1|
drop table t1|
create table t1 (a int);
insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
prepare stmt from "select * from t1 limit ?, ?";
set @offset=0, @limit=1;
execute stmt using @offset, @limit;
a
1
select * from t1 limit 0, 1;
a
1
set @offset=3, @limit=2;
execute stmt using @offset, @limit;
a
4
5
select * from t1 limit 3, 2;
a
4
5
prepare stmt from "select * from t1 limit ?";
execute stmt using @limit;
a
1
2
prepare stmt from "select * from t1 where a in (select a from t1 limit ?)";
ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
prepare stmt from "select * from t1 union all select * from t1 limit ?, ?";
set @offset=9;
set @limit=2;
execute stmt using @offset, @limit;
a
10
1
prepare stmt from "(select * from t1 limit ?, ?) union all
(select * from t1 limit ?, ?) order by a limit ?";
execute stmt using @offset, @limit, @offset, @limit, @limit;
a
10
10
drop table t1;
deallocate prepare stmt;
CREATE TABLE b12651_T1(a int) ENGINE=MYISAM;
CREATE TABLE b12651_T2(b int) ENGINE=MYISAM;
CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2;
PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)';
EXECUTE b12651;
1
DROP VIEW b12651_V1;
DROP TABLE b12651_T1, b12651_T2;
DEALLOCATE PREPARE b12651;
create table t1 (id int); create table t1 (id int);
prepare ins_call from "insert into t1 (id) values (1)"; prepare ins_call from "insert into t1 (id) values (1)";
execute ins_call; execute ins_call;
......
...@@ -99,7 +99,7 @@ select ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'withou ...@@ -99,7 +99,7 @@ select ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'withou
select distinct ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'with distinct: cutoff at length of shortname' from t1; select distinct ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'with distinct: cutoff at length of shortname' from t1;
drop table t1; drop table t1;
# check zero rows # check zero rows (bug#836)
create table t1(id int); create table t1(id int);
create table t2(id int); create table t2(id int);
insert into t1 values(0),(1); insert into t1 values(0),(1);
......
...@@ -1040,7 +1040,80 @@ EXECUTE STMT USING @id,@id; ...@@ -1040,7 +1040,80 @@ EXECUTE STMT USING @id,@id;
DEALLOCATE PREPARE STMT; DEALLOCATE PREPARE STMT;
DROP TABLE t1; DROP TABLE t1;
--echo End of 4.1 tests #
# BUG#21354: (COUNT(*) = 1) not working in SELECT inside prepared
# statement
#
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (i INT, INDEX(i));
INSERT INTO t1 VALUES (1);
PREPARE stmt FROM "SELECT (COUNT(i) = 1), COUNT(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
SET @a = 1;
EXECUTE stmt USING @a;
SET @a = 0;
EXECUTE stmt USING @a;
PREPARE stmt FROM "SELECT (AVG(i) = 1), AVG(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
SET @a = 1;
EXECUTE stmt USING @a;
SET @a = 0;
EXECUTE stmt USING @a;
PREPARE stmt FROM "SELECT (VARIANCE(i) = 1), VARIANCE(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
SET @a = 1;
EXECUTE stmt USING @a;
SET @a = 0;
EXECUTE stmt USING @a;
PREPARE stmt FROM "SELECT (STDDEV(i) = 1), STDDEV(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
SET @a = 1;
EXECUTE stmt USING @a;
SET @a = 0;
EXECUTE stmt USING @a;
PREPARE stmt FROM "SELECT (BIT_OR(i) = 1), BIT_OR(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
SET @a = 1;
EXECUTE stmt USING @a;
SET @a = 0;
EXECUTE stmt USING @a;
PREPARE stmt FROM "SELECT (BIT_AND(i) = 1), BIT_AND(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
SET @a = 1;
EXECUTE stmt USING @a;
SET @a = 0;
EXECUTE stmt USING @a;
PREPARE stmt FROM "SELECT (BIT_XOR(i) = 1), BIT_XOR(i) FROM t1 WHERE i = ?";
SET @a = 0;
EXECUTE stmt USING @a;
SET @a = 1;
EXECUTE stmt USING @a;
SET @a = 0;
EXECUTE stmt USING @a;
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
--echo End of 4.1 tests.
############################# 5.0 tests start ################################ ############################# 5.0 tests start ################################
# #
# #
......
...@@ -1065,6 +1065,7 @@ longlong Item_sum_count::val_int() ...@@ -1065,6 +1065,7 @@ longlong Item_sum_count::val_int()
void Item_sum_count::cleanup() void Item_sum_count::cleanup()
{ {
DBUG_ENTER("Item_sum_count::cleanup"); DBUG_ENTER("Item_sum_count::cleanup");
clear();
Item_sum_int::cleanup(); Item_sum_int::cleanup();
used_table_cache= ~(table_map) 0; used_table_cache= ~(table_map) 0;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
......
...@@ -260,9 +260,30 @@ public: ...@@ -260,9 +260,30 @@ public:
Item_sum(THD *thd, Item_sum *item); Item_sum(THD *thd, Item_sum *item);
enum Type type() const { return SUM_FUNC_ITEM; } enum Type type() const { return SUM_FUNC_ITEM; }
virtual enum Sumfunctype sum_func () const=0; virtual enum Sumfunctype sum_func () const=0;
/*
This method is similar to add(), but it is called when the current
aggregation group changes. Thus it performs a combination of
clear() and add().
*/
inline bool reset() { clear(); return add(); }; inline bool reset() { clear(); return add(); };
/*
Prepare this item for evaluation of an aggregate value. This is
called by reset() when a group changes, or, for correlated
subqueries, between subquery executions. E.g. for COUNT(), this
method should set count= 0;
*/
virtual void clear()= 0; virtual void clear()= 0;
/*
This method is called for the next row in the same group. Its
purpose is to aggregate the new value to the previous values in
the group (i.e. since clear() was called last time). For example,
for COUNT(), do count++.
*/
virtual bool add()=0; virtual bool add()=0;
/* /*
Called when new group is started and results are being saved in Called when new group is started and results are being saved in
a temporary table. Similar to reset(), but must also store value in a temporary table. Similar to reset(), but must also store value in
...@@ -306,7 +327,17 @@ public: ...@@ -306,7 +327,17 @@ public:
void make_field(Send_field *field); void make_field(Send_field *field);
void print(String *str); void print(String *str);
void fix_num_length_and_dec(); void fix_num_length_and_dec();
void no_rows_in_result() { reset(); }
/*
This function is called by the execution engine to assign 'NO ROWS
FOUND' value to an aggregate item, when the underlying result set
has no rows. Such value, in a general case, may be different from
the default value of the item after 'clear()': e.g. a numeric item
may be initialized to 0 by clear() and to NULL by
no_rows_in_result().
*/
void no_rows_in_result() { clear(); }
virtual bool setup(THD *thd) {return 0;} virtual bool setup(THD *thd) {return 0;}
virtual void make_unique() {} virtual void make_unique() {}
Item *get_tmp_table_item(THD *thd); Item *get_tmp_table_item(THD *thd);
...@@ -610,6 +641,11 @@ public: ...@@ -610,6 +641,11 @@ public:
const char *func_name() const { return "avg("; } const char *func_name() const { return "avg("; }
Item *copy_or_same(THD* thd); Item *copy_or_same(THD* thd);
Field *create_tmp_field(bool group, TABLE *table, uint convert_blob_length); Field *create_tmp_field(bool group, TABLE *table, uint convert_blob_length);
void cleanup()
{
clear();
Item_sum_num::cleanup();
}
}; };
class Item_sum_variance; class Item_sum_variance;
...@@ -689,6 +725,11 @@ public: ...@@ -689,6 +725,11 @@ public:
Item *copy_or_same(THD* thd); Item *copy_or_same(THD* thd);
Field *create_tmp_field(bool group, TABLE *table, uint convert_blob_length); Field *create_tmp_field(bool group, TABLE *table, uint convert_blob_length);
enum Item_result result_type () const { return REAL_RESULT; } enum Item_result result_type () const { return REAL_RESULT; }
void cleanup()
{
clear();
Item_sum_num::cleanup();
}
}; };
class Item_sum_std; class Item_sum_std;
...@@ -819,6 +860,11 @@ public: ...@@ -819,6 +860,11 @@ public:
void update_field(); void update_field();
void fix_length_and_dec() void fix_length_and_dec()
{ decimals= 0; max_length=21; unsigned_flag= 1; maybe_null= null_value= 0; } { decimals= 0; max_length=21; unsigned_flag= 1; maybe_null= null_value= 0; }
void cleanup()
{
clear();
Item_sum_int::cleanup();
}
}; };
......
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