Commit 4434ff13 authored by evgen@moonbone.local's avatar evgen@moonbone.local

Merge moonbone.local:/mnt/gentoo64/work/bk-trees/mysql-5.0-opt

into  moonbone.local:/mnt/gentoo64/work/bk-trees/mysql-5.1-opt
parents bfac9ea6 6c5d17ef
......@@ -2325,4 +2325,73 @@ abc
SELECT INSERT('abc', 6, 3, '1234');
INSERT('abc', 6, 3, '1234')
abc
CREATE TABLE t1 (a INT);
CREATE VIEW v1 AS SELECT CRC32(a) AS C FROM t1;
INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
SELECT CRC32(a), COUNT(*) FROM t1 GROUP BY 1;
CRC32(a) COUNT(*)
450215437 1
498629140 1
1790921346 1
1842515611 1
2212294583 1
2226203566 1
2366072709 1
2707236321 1
4088798008 1
4194326291 1
SELECT CRC32(a), COUNT(*) FROM t1 GROUP BY 1 ORDER BY 1;
CRC32(a) COUNT(*)
450215437 1
498629140 1
1790921346 1
1842515611 1
2212294583 1
2226203566 1
2366072709 1
2707236321 1
4088798008 1
4194326291 1
SELECT * FROM (SELECT CRC32(a) FROM t1) t2;
CRC32(a)
2212294583
450215437
1842515611
4088798008
2226203566
498629140
1790921346
4194326291
2366072709
2707236321
CREATE TABLE t2 SELECT CRC32(a) FROM t1;
desc t2;
Field Type Null Key Default Extra
CRC32(a) int(10) unsigned YES NULL
SELECT * FROM v1;
C
2212294583
450215437
1842515611
4088798008
2226203566
498629140
1790921346
4194326291
2366072709
2707236321
SELECT * FROM (SELECT * FROM v1) x;
C
2212294583
450215437
1842515611
4088798008
2226203566
498629140
1790921346
4194326291
2366072709
2707236321
DROP TABLE t1, t2;
DROP VIEW v1;
End of 5.0 tests
......@@ -193,6 +193,103 @@ SELECT ROW(2,1) IN (ROW(21,2),ROW(ROW(1,1,3),0));
ERROR 21000: Operand should contain 1 column(s)
SELECT ROW(2,1) IN (ROW(ROW(1,1,3),0),ROW(21,2));
ERROR 21000: Operand should contain 1 column(s)
CREATE TABLE t1(a int, b int, c int);
INSERT INTO t1 VALUES (1, 2, 3),
(NULL, 2, 3 ), (1, NULL, 3 ), (1, 2, NULL),
(NULL, 2, 3+1), (1, NULL, 3+1), (1, 2+1, NULL),
(NULL, 2, 3-1), (1, NULL, 3-1), (1, 2-1, NULL);
SELECT (1,2,3) = (1, NULL, 3);
(1,2,3) = (1, NULL, 3)
NULL
SELECT (1,2,3) = (1+1, NULL, 3);
(1,2,3) = (1+1, NULL, 3)
0
SELECT (1,2,3) = (1, NULL, 3+1);
(1,2,3) = (1, NULL, 3+1)
0
SELECT * FROM t1 WHERE (a,b,c) = (1,2,3);
a b c
1 2 3
SELECT (1,2,3) <> (1, NULL, 3);
(1,2,3) <> (1, NULL, 3)
NULL
SELECT (1,2,3) <> (1+1, NULL, 3);
(1,2,3) <> (1+1, NULL, 3)
1
SELECT (1,2,3) <> (1, NULL, 3+1);
(1,2,3) <> (1, NULL, 3+1)
1
SELECT * FROM t1 WHERE (a,b,c) <> (1,2,3);
a b c
NULL 2 4
1 NULL 4
1 3 NULL
NULL 2 2
1 NULL 2
1 1 NULL
SELECT (1,2,3) < (NULL, 2, 3);
(1,2,3) < (NULL, 2, 3)
NULL
SELECT (1,2,3) < (1, NULL, 3);
(1,2,3) < (1, NULL, 3)
NULL
SELECT (1,2,3) < (1-1, NULL, 3);
(1,2,3) < (1-1, NULL, 3)
0
SELECT (1,2,3) < (1+1, NULL, 3);
(1,2,3) < (1+1, NULL, 3)
1
SELECT * FROM t1 WHERE (a,b,c) < (1,2,3);
a b c
1 1 NULL
SELECT (1,2,3) <= (NULL, 2, 3);
(1,2,3) <= (NULL, 2, 3)
NULL
SELECT (1,2,3) <= (1, NULL, 3);
(1,2,3) <= (1, NULL, 3)
NULL
SELECT (1,2,3) <= (1-1, NULL, 3);
(1,2,3) <= (1-1, NULL, 3)
0
SELECT (1,2,3) <= (1+1, NULL, 3);
(1,2,3) <= (1+1, NULL, 3)
1
SELECT * FROM t1 WHERE (a,b,c) <= (1,2,3);
a b c
1 2 3
1 1 NULL
SELECT (1,2,3) > (NULL, 2, 3);
(1,2,3) > (NULL, 2, 3)
NULL
SELECT (1,2,3) > (1, NULL, 3);
(1,2,3) > (1, NULL, 3)
NULL
SELECT (1,2,3) > (1-1, NULL, 3);
(1,2,3) > (1-1, NULL, 3)
1
SELECT (1,2,3) > (1+1, NULL, 3);
(1,2,3) > (1+1, NULL, 3)
0
SELECT * FROM t1 WHERE (a,b,c) > (1,2,3);
a b c
1 3 NULL
SELECT (1,2,3) >= (NULL, 2, 3);
(1,2,3) >= (NULL, 2, 3)
NULL
SELECT (1,2,3) >= (1, NULL, 3);
(1,2,3) >= (1, NULL, 3)
NULL
SELECT (1,2,3) >= (1-1, NULL, 3);
(1,2,3) >= (1-1, NULL, 3)
1
SELECT (1,2,3) >= (1+1, NULL, 3);
(1,2,3) >= (1+1, NULL, 3)
0
SELECT * FROM t1 WHERE (a,b,c) >= (1,2,3);
a b c
1 2 3
1 3 NULL
DROP TABLE t1;
SELECT ROW(1,1,1) = ROW(1,1,1) as `1`, ROW(1,1,1) = ROW(1,2,1) as `0`, ROW(1,NULL,1) = ROW(2,2,1) as `0`, ROW(1,NULL,1) = ROW(1,2,2) as `0`, ROW(1,NULL,1) = ROW(1,2,1) as `null` ;
1 0 0 0 null
1 0 0 0 NULL
......
......@@ -692,3 +692,22 @@ a MAX(b) test
2 3 h
3 4 i
DROP TABLE t1, t2;
CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int, PRIMARY KEY(b));
INSERT INTO t1 VALUES (1), (NULL), (4);
INSERT INTO t2 VALUES (3), (1),(2), (5), (4), (7), (6);
EXPLAIN EXTENDED
SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using index
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (not(<in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t1` where ((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`)) having <is_not_null_test>(`test`.`t1`.`a`))))))
SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1));
a
SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1 WHERE a > 4));
a
1
4
DROP TABLE t1,t2;
......@@ -3311,6 +3311,41 @@ lgid clid
2 YES
DROP VIEW v1;
DROP table t1,t2;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2),(3);
CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a;
SELECT * FROM t1 UNION SELECT * FROM v1;
a
1
2
3
EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
2 UNION t1 ALL NULL NULL NULL NULL 3
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
SELECT * FROM v1 UNION SELECT * FROM t1;
a
1
2
3
EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
2 UNION t1 ALL NULL NULL NULL NULL 3
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
a
1
2
3
EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
2 UNION t1 ALL NULL NULL NULL NULL 3
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL Using filesort
DROP VIEW v1;
DROP TABLE t1;
End of 5.0 tests.
DROP DATABASE IF EXISTS `d-1`;
CREATE DATABASE `d-1`;
......
......@@ -1165,4 +1165,22 @@ SELECT INSERT('abc', 4, 3, '1234');
SELECT INSERT('abc', 5, 3, '1234');
SELECT INSERT('abc', 6, 3, '1234');
#
# Bug #27530: Grouping on crc32, or create table select crc32
#
CREATE TABLE t1 (a INT);
CREATE VIEW v1 AS SELECT CRC32(a) AS C FROM t1;
INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
SELECT CRC32(a), COUNT(*) FROM t1 GROUP BY 1;
SELECT CRC32(a), COUNT(*) FROM t1 GROUP BY 1 ORDER BY 1;
SELECT * FROM (SELECT CRC32(a) FROM t1) t2;
CREATE TABLE t2 SELECT CRC32(a) FROM t1;
desc t2;
SELECT * FROM v1;
SELECT * FROM (SELECT * FROM v1) x;
DROP TABLE t1, t2;
DROP VIEW v1;
--echo End of 5.0 tests
......@@ -110,6 +110,51 @@ SELECT ROW(2,1) IN (ROW(21,2),ROW(ROW(1,1,3),0));
--error 1241
SELECT ROW(2,1) IN (ROW(ROW(1,1,3),0),ROW(21,2));
#
# Bug#27704: erroneous comparison of rows with NULL components
#
CREATE TABLE t1(a int, b int, c int);
INSERT INTO t1 VALUES (1, 2, 3),
(NULL, 2, 3 ), (1, NULL, 3 ), (1, 2, NULL),
(NULL, 2, 3+1), (1, NULL, 3+1), (1, 2+1, NULL),
(NULL, 2, 3-1), (1, NULL, 3-1), (1, 2-1, NULL);
SELECT (1,2,3) = (1, NULL, 3);
SELECT (1,2,3) = (1+1, NULL, 3);
SELECT (1,2,3) = (1, NULL, 3+1);
SELECT * FROM t1 WHERE (a,b,c) = (1,2,3);
SELECT (1,2,3) <> (1, NULL, 3);
SELECT (1,2,3) <> (1+1, NULL, 3);
SELECT (1,2,3) <> (1, NULL, 3+1);
SELECT * FROM t1 WHERE (a,b,c) <> (1,2,3);
SELECT (1,2,3) < (NULL, 2, 3);
SELECT (1,2,3) < (1, NULL, 3);
SELECT (1,2,3) < (1-1, NULL, 3);
SELECT (1,2,3) < (1+1, NULL, 3);
SELECT * FROM t1 WHERE (a,b,c) < (1,2,3);
SELECT (1,2,3) <= (NULL, 2, 3);
SELECT (1,2,3) <= (1, NULL, 3);
SELECT (1,2,3) <= (1-1, NULL, 3);
SELECT (1,2,3) <= (1+1, NULL, 3);
SELECT * FROM t1 WHERE (a,b,c) <= (1,2,3);
SELECT (1,2,3) > (NULL, 2, 3);
SELECT (1,2,3) > (1, NULL, 3);
SELECT (1,2,3) > (1-1, NULL, 3);
SELECT (1,2,3) > (1+1, NULL, 3);
SELECT * FROM t1 WHERE (a,b,c) > (1,2,3);
SELECT (1,2,3) >= (NULL, 2, 3);
SELECT (1,2,3) >= (1, NULL, 3);
SELECT (1,2,3) >= (1-1, NULL, 3);
SELECT (1,2,3) >= (1+1, NULL, 3);
SELECT * FROM t1 WHERE (a,b,c) >= (1,2,3);
DROP TABLE t1;
# End of 4.1 tests
#
......
......@@ -528,3 +528,21 @@ SELECT a, MAX(b),
DROP TABLE t1, t2;
#
# Bug #27870: crash of an equijoin query with WHERE condition containing
# a subquery predicate of the form <join attr> NOT IN (SELECT ...)
#
CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int, PRIMARY KEY(b));
INSERT INTO t1 VALUES (1), (NULL), (4);
INSERT INTO t2 VALUES (3), (1),(2), (5), (4), (7), (6);
EXPLAIN EXTENDED
SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1));
SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1));
SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1 WHERE a > 4));
DROP TABLE t1,t2;
......@@ -3197,6 +3197,22 @@ SELECT * FROM v1;
DROP VIEW v1;
DROP table t1,t2;
#
# Bug#27786: Inconsistent Operation Performing UNION On View With ORDER BY
#
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1),(2),(3);
CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a;
SELECT * FROM t1 UNION SELECT * FROM v1;
EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1;
SELECT * FROM v1 UNION SELECT * FROM t1;
EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1;
SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
DROP VIEW v1;
DROP TABLE t1;
--echo End of 5.0 tests.
#
......
......@@ -864,8 +864,18 @@ int Arg_comparator::compare_row()
if (owner->null_value)
{
// NULL was compared
if (owner->abort_on_null)
return -1; // We do not need correct NULL returning
switch (owner->functype()) {
case Item_func::NE_FUNC:
break; // NE never aborts on NULL even if abort_on_null is set
case Item_func::LT_FUNC:
case Item_func::LE_FUNC:
case Item_func::GT_FUNC:
case Item_func::GE_FUNC:
return -1; // <, <=, > and >= always fail on NULL
default: // EQ_FUNC
if (owner->abort_on_null)
return -1; // We do not need correct NULL returning
}
was_null= 1;
owner->null_value= 0;
res= 0; // continue comparison (maybe we will meet explicit difference)
......@@ -876,8 +886,8 @@ int Arg_comparator::compare_row()
if (was_null)
{
/*
There was NULL(s) in comparison in some parts, but there was not
explicit difference in other parts, so we have to return NULL
There was NULL(s) in comparison in some parts, but there was no
explicit difference in other parts, so we have to return NULL.
*/
owner->null_value= 1;
return -1;
......
......@@ -333,7 +333,7 @@ public:
bool is_bool_func() { return 1; }
CHARSET_INFO *compare_collation() { return cmp.cmp_collation.collation; }
uint decimal_precision() const { return 1; }
void top_level_item() { abort_on_null=1; }
void top_level_item() { abort_on_null= TRUE; }
friend class Arg_comparator;
};
......
......@@ -790,7 +790,7 @@ class Item_func_crc32 :public Item_int_func
{
String value;
public:
Item_func_crc32(Item *a) :Item_int_func(a) {}
Item_func_crc32(Item *a) :Item_int_func(a) { unsigned_flag= 1; }
const char *func_name() const { return "crc32"; }
void fix_length_and_dec() { max_length=10; }
longlong val_int();
......
......@@ -277,7 +277,11 @@ public:
{
return pushed_cond_guards ? pushed_cond_guards + i : NULL;
}
void set_cond_guard_var(int i, bool v) { pushed_cond_guards[i]= v; }
void set_cond_guard_var(int i, bool v)
{
if ( pushed_cond_guards)
pushed_cond_guards[i]= v;
}
bool have_guarded_conds() { return test(pushed_cond_guards); }
Item_func_not_all *upper_item; // point on NOT/NOP before ALL/SOME subquery
......
......@@ -541,6 +541,7 @@ public:
bool change_result(select_subselect *result, select_subselect *old_result);
void set_limit(st_select_lex *values);
void set_thd(THD *thd_arg) { thd= thd_arg; }
inline bool is_union ();
friend void lex_start(THD *thd, const char *buf, uint length);
friend int subselect_union_engine::exec();
......@@ -795,6 +796,13 @@ private:
};
typedef class st_select_lex SELECT_LEX;
inline bool st_select_lex_unit::is_union ()
{
return first_select()->next_select() &&
first_select()->next_select()->linkage == UNION_TYPE;
}
#define ALTER_ADD_COLUMN (1L << 0)
#define ALTER_DROP_COLUMN (1L << 1)
#define ALTER_CHANGE_COLUMN (1L << 2)
......
......@@ -2733,18 +2733,32 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
res= open_normal_and_derived_tables(thd, show_table_list,
MYSQL_LOCK_IGNORE_FLUSH);
lex->sql_command= save_sql_command;
/*
We should use show_table_list->alias instead of
show_table_list->table_name because table_name
could be changed during opening of I_S tables. It's safe
to use alias because alias contains original table name
in this case.
/*
They can drop table after table names list creation and
before table opening. We open non existing table and
get ER_NO_SUCH_TABLE error. In this case we do not store
the record into I_S table and clear error.
*/
res= schema_table->process_table(thd, show_table_list, table,
res, orig_base_name,
show_table_list->alias);
close_tables_for_reopen(thd, &show_table_list);
DBUG_ASSERT(!lex->query_tables_own_last);
if (thd->net.last_errno == ER_NO_SUCH_TABLE)
{
res= 0;
thd->clear_error();
}
else
{
/*
We should use show_table_list->alias instead of
show_table_list->table_name because table_name
could be changed during opening of I_S tables. It's safe
to use alias because alias contains original table name
in this case.
*/
res= schema_table->process_table(thd, show_table_list, table,
res, orig_base_name,
show_table_list->alias);
close_tables_for_reopen(thd, &show_table_list);
DBUG_ASSERT(!lex->query_tables_own_last);
}
if (res)
goto err;
}
......
......@@ -1270,13 +1270,18 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
unit->slave= save_slave; // fix include_down initialisation
}
/*
We can safely ignore the VIEW's ORDER BY if we merge into union
branch, as order is not important there.
*/
if (!table->select_lex->master_unit()->is_union())
table->select_lex->order_list.push_back(&lex->select_lex.order_list);
/*
This SELECT_LEX will be linked in global SELECT_LEX list
to make it processed by mysql_handle_derived(),
but it will not be included to SELECT_LEX tree, because it
will not be executed
*/
table->select_lex->order_list.push_back(&lex->select_lex.order_list);
*/
goto ok;
}
......
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