summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/partition.result20
-rw-r--r--mysql-test/t/partition.test20
-rw-r--r--sql/item.cc4
-rw-r--r--sql/sql_lex.cc1
-rw-r--r--sql/sql_lex.h8
-rw-r--r--sql/sql_partition.cc7
6 files changed, 59 insertions, 1 deletions
diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result
index 5d985d053fc..7120e3ea9e6 100644
--- a/mysql-test/r/partition.result
+++ b/mysql-test/r/partition.result
@@ -1267,4 +1267,24 @@ ALTER TABLE general_log PARTITION BY RANGE (TO_DAYS(event_time))
ERROR HY000: Incorrect usage of PARTITION and log table
ALTER TABLE general_log ENGINE = CSV;
SET GLOBAL general_log = default;
+use test;
+create table t2 (b int);
+create table t1 (b int)
+PARTITION BY RANGE (t2.b) (
+PARTITION p1 VALUES LESS THAN (10),
+PARTITION p2 VALUES LESS THAN (20)
+) select * from t2;
+ERROR 42S22: Unknown column 't2.b' in 'partition function'
+create table t1 (a int)
+PARTITION BY RANGE (b) (
+PARTITION p1 VALUES LESS THAN (10),
+PARTITION p2 VALUES LESS THAN (20)
+) select * from t2;
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (b) (PARTITION p1 VALUES LESS THAN (10) ENGINE = MyISAM, PARTITION p2 VALUES LESS THAN (20) ENGINE = MyISAM) */
+drop table t1, t2;
End of 5.1 tests
diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test
index 42db23dadef..2be2ab83c88 100644
--- a/mysql-test/t/partition.test
+++ b/mysql-test/t/partition.test
@@ -1493,10 +1493,30 @@ ALTER TABLE general_log PARTITION BY RANGE (TO_DAYS(event_time))
(PARTITION p0 VALUES LESS THAN (733144), PARTITION p1 VALUES LESS THAN (3000000));
ALTER TABLE general_log ENGINE = CSV;
SET GLOBAL general_log = default;
+use test;
#
# Bug #27084 partitioning by list seems failing when using case
# BUG #18198: Case no longer supported, test case removed
#
+#
+# Bug #29444: crash with partition refering to table in create-select
+#
+
+create table t2 (b int);
+--error 1054
+create table t1 (b int)
+PARTITION BY RANGE (t2.b) (
+ PARTITION p1 VALUES LESS THAN (10),
+ PARTITION p2 VALUES LESS THAN (20)
+) select * from t2;
+create table t1 (a int)
+PARTITION BY RANGE (b) (
+ PARTITION p1 VALUES LESS THAN (10),
+ PARTITION p2 VALUES LESS THAN (20)
+) select * from t2;
+show create table t1;
+drop table t1, t2;
+
--echo End of 5.1 tests
diff --git a/sql/item.cc b/sql/item.cc
index dc94615c6e6..3b592633ad0 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -3860,7 +3860,9 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
context->first_name_resolution_table,
context->last_name_resolution_table,
reference,
- IGNORE_EXCEPT_NON_UNIQUE,
+ thd->lex->use_only_table_context ?
+ REPORT_ALL_ERRORS :
+ IGNORE_EXCEPT_NON_UNIQUE,
!any_privileges,
TRUE)) ==
not_found_field)
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 0a5f83af400..4ee66cb1e8d 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -338,6 +338,7 @@ void lex_start(THD *thd)
lex->query_tables= 0;
lex->reset_query_tables_list(FALSE);
lex->expr_allows_subselect= TRUE;
+ lex->use_only_table_context= FALSE;
lex->name.str= 0;
lex->name.length= 0;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 08104769704..50211f6b3f9 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1693,6 +1693,14 @@ typedef struct st_lex : public Query_tables_list
*/
const char *fname_start;
const char *fname_end;
+
+ /**
+ During name resolution search only in the table list given by
+ Name_resolution_context::first_name_resolution_table and
+ Name_resolution_context::last_name_resolution_table
+ (see Item_field::fix_fields()).
+ */
+ bool use_only_table_context;
LEX_STRING view_body_utf8;
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index 8a8a03cb4e4..0cc2cac2a1a 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -902,6 +902,7 @@ bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
const char *save_where;
char* db_name;
char db_name_string[FN_REFLEN];
+ bool save_use_only_table_context;
DBUG_ENTER("fix_fields_part_func");
if (part_info->fixed)
@@ -958,8 +959,14 @@ bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
This is a tricky call to prepare for since it can have a large number
of interesting side effects, both desirable and undesirable.
*/
+
+ save_use_only_table_context= thd->lex->use_only_table_context;
+ thd->lex->use_only_table_context= TRUE;
+
error= func_expr->fix_fields(thd, (Item**)0);
+ thd->lex->use_only_table_context= save_use_only_table_context;
+
context->table_list= save_table_list;
context->first_name_resolution_table= save_first_table;
context->last_name_resolution_table= save_last_table;