Skip to content

Commit

Permalink
Merge branch '10.0' into 10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sanja-byelkin committed Mar 1, 2019
2 parents e39d6e0 + 2d34713 commit f2e1451
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 60 deletions.
50 changes: 50 additions & 0 deletions mysql-test/r/loaddata.result
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,53 @@ SELECT HEX(a) FROM t1;
HEX(a)
C3A4
DROP TABLE t1;
#
# MDEV-15744: Assertion `derived->table' failed in mysql_derived_merge_for_insert
#
create table t1 (a int, b int);
CREATE OR REPLACE VIEW t2 AS SELECT * FROM t1;
CREATE VIEW v2 AS SELECT * FROM t2;
LOAD DATA INFILE '../../std_data/loaddata7.dat' INTO TABLE v2
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n';
select * from v2;
a b
2 2
3 3
4 4
5 5
6 6
select * from t2;
a b
2 2
3 3
4 4
5 5
6 6
DROP VIEW IF EXISTS v2,t2;
DROP TABLE IF EXISTS t1;
#
# MDEV-15950: LOAD DATA INTO compex_view crashed
#
create table t1 (a int, b int);
create table t0 (x int, y int);
CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1,t0;
CREATE VIEW v2 AS SELECT * FROM v1;
LOAD DATA INFILE '../../std_data/loaddata7.dat' INTO TABLE v1
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n';
ERROR HY000: Incorrect usage of Multi-table VIEW and LOAD
LOAD DATA INFILE '../../std_data/loaddata7.dat' INTO TABLE v2
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n';
ERROR HY000: Incorrect usage of Multi-table VIEW and LOAD
DROP VIEW IF EXISTS v2,v1;
DROP TABLE IF EXISTS t1,t0;
CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), UNIQUE(b));
INSERT INTO t1 VALUES (1,1);
CREATE TABLE t2 (c INT);
CREATE VIEW v AS SELECT t1.* FROM t1 JOIN t2;
SELECT a, b FROM t1 INTO OUTFILE '15645.data';
LOAD DATA INFILE '15645.data' IGNORE INTO TABLE v (a,b);
ERROR HY000: Incorrect usage of Multi-table VIEW and LOAD
LOAD DATA INFILE '15645.data' REPLACE INTO TABLE v (a,b);
ERROR HY000: Incorrect usage of Multi-table VIEW and LOAD
drop table t1,t2;
drop view v;
33 changes: 33 additions & 0 deletions mysql-test/r/sp.result
Original file line number Diff line number Diff line change
Expand Up @@ -7918,6 +7918,39 @@ CALL sp;
c a b a b
DROP PROCEDURE sp;
DROP TABLE t1;
#
# MDEV-17055: Server crashes in find_order_in_list upon
# 2nd (3rd) execution of SP with UPDATE
#
CREATE TABLE t1 (a INT);
CREATE VIEW v1 AS SELECT * FROM t1;
CREATE TABLE t2 (c INT);
CREATE PROCEDURE sp() UPDATE v1 SET a = 1 ORDER BY a, b LIMIT 1;
LOCK TABLE t2 READ;
CALL sp;
ERROR HY000: Table 'v1' was not locked with LOCK TABLES
UNLOCK TABLES;
CALL sp;
ERROR 42S22: Unknown column 'b' in 'order clause'
CALL sp;
ERROR 42S22: Unknown column 'b' in 'order clause'
CALL sp;
ERROR 42S22: Unknown column 'b' in 'order clause'
DROP PROCEDURE sp;
CREATE PROCEDURE sp() UPDATE v1 SET a = 1 WHERE a=1 and b=2;
LOCK TABLE t2 READ;
CALL sp;
ERROR HY000: Table 'v1' was not locked with LOCK TABLES
UNLOCK TABLES;
CALL sp;
ERROR 42S22: Unknown column 'b' in 'where clause'
CALL sp;
ERROR 42S22: Unknown column 'b' in 'where clause'
CALL sp;
ERROR 42S22: Unknown column 'b' in 'where clause'
DROP PROCEDURE sp;
DROP VIEW v1;
DROP TABLE t1, t2;
# End of 5.5 test
#
# MDEV-7040: Crash in field_conv, memcpy_field_possible, part#2
Expand Down
45 changes: 45 additions & 0 deletions mysql-test/t/loaddata.test
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,48 @@ CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8);
LOAD DATA INFILE '../../std_data/loaddata/mdev-11631.txt' INTO TABLE t1 CHARACTER SET utf8;
SELECT HEX(a) FROM t1;
DROP TABLE t1;

--echo #
--echo # MDEV-15744: Assertion `derived->table' failed in mysql_derived_merge_for_insert
--echo #

create table t1 (a int, b int);
CREATE OR REPLACE VIEW t2 AS SELECT * FROM t1;
CREATE VIEW v2 AS SELECT * FROM t2;
LOAD DATA INFILE '../../std_data/loaddata7.dat' INTO TABLE v2
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n';
select * from v2;
select * from t2;
DROP VIEW IF EXISTS v2,t2;
DROP TABLE IF EXISTS t1;

--echo #
--echo # MDEV-15950: LOAD DATA INTO compex_view crashed
--echo #
create table t1 (a int, b int);
create table t0 (x int, y int);
CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1,t0;
CREATE VIEW v2 AS SELECT * FROM v1;

--error ER_WRONG_USAGE
LOAD DATA INFILE '../../std_data/loaddata7.dat' INTO TABLE v1
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n';

--error ER_WRONG_USAGE
LOAD DATA INFILE '../../std_data/loaddata7.dat' INTO TABLE v2
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n';

DROP VIEW IF EXISTS v2,v1;
DROP TABLE IF EXISTS t1,t0;

CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), UNIQUE(b));
INSERT INTO t1 VALUES (1,1);
CREATE TABLE t2 (c INT);
CREATE VIEW v AS SELECT t1.* FROM t1 JOIN t2;
SELECT a, b FROM t1 INTO OUTFILE '15645.data';
--error ER_WRONG_USAGE
LOAD DATA INFILE '15645.data' IGNORE INTO TABLE v (a,b);
--error ER_WRONG_USAGE
LOAD DATA INFILE '15645.data' REPLACE INTO TABLE v (a,b);
drop table t1,t2;
drop view v;
41 changes: 41 additions & 0 deletions mysql-test/t/sp.test
Original file line number Diff line number Diff line change
Expand Up @@ -9369,6 +9369,47 @@ CALL sp;
DROP PROCEDURE sp;
DROP TABLE t1;

--echo #
--echo # MDEV-17055: Server crashes in find_order_in_list upon
--echo # 2nd (3rd) execution of SP with UPDATE
--echo #

CREATE TABLE t1 (a INT);
CREATE VIEW v1 AS SELECT * FROM t1;
CREATE TABLE t2 (c INT);

CREATE PROCEDURE sp() UPDATE v1 SET a = 1 ORDER BY a, b LIMIT 1;
LOCK TABLE t2 READ;
--error ER_TABLE_NOT_LOCKED
CALL sp;
UNLOCK TABLES;
--error ER_BAD_FIELD_ERROR
CALL sp;
--error ER_BAD_FIELD_ERROR
CALL sp;
--error ER_BAD_FIELD_ERROR
CALL sp;

# Cleanup
DROP PROCEDURE sp;

CREATE PROCEDURE sp() UPDATE v1 SET a = 1 WHERE a=1 and b=2;
LOCK TABLE t2 READ;
--error ER_TABLE_NOT_LOCKED
CALL sp;
UNLOCK TABLES;
--error ER_BAD_FIELD_ERROR
CALL sp;
--error ER_BAD_FIELD_ERROR
CALL sp;
--error ER_BAD_FIELD_ERROR
CALL sp;

# Cleanup
DROP PROCEDURE sp;

DROP VIEW v1;
DROP TABLE t1, t2;

--echo # End of 5.5 test

Expand Down
6 changes: 3 additions & 3 deletions sql/sql_delete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "sql_statistics.h"
#include "transaction.h"
#include "records.h" // init_read_record,
#include "sql_derived.h" // mysql_handle_list_of_derived
#include "sql_derived.h" // mysql_handle_derived
// end_read_record
#include "sql_partition.h" // make_used_partitions_str

Expand Down Expand Up @@ -248,9 +248,9 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
if (open_and_lock_tables(thd, table_list, TRUE, 0))
DBUG_RETURN(TRUE);

if (mysql_handle_list_of_derived(thd->lex, table_list, DT_MERGE_FOR_INSERT))
if (thd->lex->handle_list_of_derived(table_list, DT_MERGE_FOR_INSERT))
DBUG_RETURN(TRUE);
if (mysql_handle_list_of_derived(thd->lex, table_list, DT_PREPARE))
if (thd->lex->handle_list_of_derived(table_list, DT_PREPARE))
DBUG_RETURN(TRUE);

if (!table_list->single_table_updatable())
Expand Down
31 changes: 1 addition & 30 deletions sql/sql_derived.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ mysql_handle_derived(LEX *lex, uint phases)
sl= sl->next_select_in_list())
{
TABLE_LIST *cursor= sl->get_table_list();
sl->changed_elements|= TOUCHED_SEL_DERIVED;
/*
DT_MERGE_FOR_INSERT is not needed for views/derived tables inside
subqueries. Views and derived tables of subqueries should be
Expand Down Expand Up @@ -200,36 +201,6 @@ mysql_handle_single_derived(LEX *lex, TABLE_LIST *derived, uint phases)
}


/**
Run specified phases for derived tables/views in the given list
@param lex LEX for this thread
@param table_list list of derived tables/view to handle
@param phase_map phases to process tables/views through
@details
This function runs phases specified by the 'phases_map' on derived
tables/views found in the 'dt_list' with help of the
TABLE_LIST::handle_derived function.
'lex' is passed as an argument to the TABLE_LIST::handle_derived.
@return FALSE ok
@return TRUE error
*/

bool
mysql_handle_list_of_derived(LEX *lex, TABLE_LIST *table_list, uint phases)
{
for (TABLE_LIST *tl= table_list; tl; tl= tl->next_local)
{
if (tl->is_view_or_derived() &&
tl->handle_derived(lex, phases))
return TRUE;
}
return FALSE;
}


/**
Merge a derived table/view into the embedding select
Expand Down
1 change: 0 additions & 1 deletion sql/sql_derived.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ struct LEX;

bool mysql_handle_derived(LEX *lex, uint phases);
bool mysql_handle_single_derived(LEX *lex, TABLE_LIST *derived, uint phases);
bool mysql_handle_list_of_derived(LEX *lex, TABLE_LIST *dt_list, uint phases);
bool mysql_derived_reinit(THD *thd, LEX *lex, TABLE_LIST *derived);

/**
Expand Down
3 changes: 1 addition & 2 deletions sql/sql_insert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
DBUG_RETURN(TRUE);
if (table_list->handle_derived(thd->lex, DT_MERGE_FOR_INSERT))
DBUG_RETURN(TRUE);
if (mysql_handle_list_of_derived(thd->lex, table_list, DT_PREPARE))
if (thd->lex->handle_list_of_derived(table_list, DT_PREPARE))
DBUG_RETURN(TRUE);
/*
For subqueries in VALUES() we should not see the table in which we are
Expand Down Expand Up @@ -1557,7 +1557,6 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
DBUG_RETURN(TRUE);
}
select_lex->fix_prepare_information(thd, &fake_conds, &fake_conds);
select_lex->first_execution= 0;
}
/*
Only call prepare_for_posistion() if we are not performing a DELAYED
Expand Down
16 changes: 5 additions & 11 deletions sql/sql_lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ void st_select_lex::init_query()
n_child_sum_items= 0;
subquery_in_having= explicit_limit= 0;
is_item_list_lookup= 0;
first_execution= 1;
changed_elements= 0;
first_natural_join_processing= 1;
first_cond_optimization= 1;
parsing_place= NO_MATTER;
Expand Down Expand Up @@ -3597,9 +3597,10 @@ void st_select_lex::fix_prepare_information(THD *thd, Item **conds,
Item **having_conds)
{
DBUG_ENTER("st_select_lex::fix_prepare_information");
if (!thd->stmt_arena->is_conventional() && first_execution)
if (!thd->stmt_arena->is_conventional() &&
!(changed_elements & TOUCHED_SEL_COND))
{
first_execution= 0;
changed_elements|= TOUCHED_SEL_COND;
if (group_list.first)
{
if (!group_list_ptrs)
Expand Down Expand Up @@ -3850,14 +3851,7 @@ bool st_select_lex::optimize_unflattened_subqueries(bool const_only)

bool st_select_lex::handle_derived(LEX *lex, uint phases)
{
for (TABLE_LIST *cursor= (TABLE_LIST*) table_list.first;
cursor;
cursor= cursor->next_local)
{
if (cursor->is_view_or_derived() && cursor->handle_derived(lex, phases))
return TRUE;
}
return FALSE;
return lex->handle_list_of_derived(table_list.first, phases);
}


Expand Down
32 changes: 31 additions & 1 deletion sql/sql_lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,10 @@ class st_select_lex_unit: public st_select_lex_node {

typedef class st_select_lex_unit SELECT_LEX_UNIT;


#define TOUCHED_SEL_COND 1/* WHERE/HAVING/ON should be reinited before use */
#define TOUCHED_SEL_DERIVED (1<<1)/* derived should be reinited before use */

/*
SELECT_LEX - store information of parsed SELECT statment
*/
Expand Down Expand Up @@ -875,7 +879,8 @@ class st_select_lex: public st_select_lex_node
subquery. Prepared statements work OK in that regard, as in
case of an error during prepare the PS is not created.
*/
bool first_execution;
uint8 changed_elements; // see TOUCHED_SEL_*
/* TODO: add foloowing first_* to bitmap above */
bool first_natural_join_processing;
bool first_cond_optimization;
/* do not wrap view fields with Item_ref */
Expand Down Expand Up @@ -2998,6 +3003,31 @@ struct LEX: public Query_tables_list
*/
bool tmp_table() const { return create_info.tmp_table(); }
bool if_exists() const { return create_info.if_exists(); }

/*
Run specified phases for derived tables/views in the given list
@param table_list - list of derived tables/view to handle
@param phase - phases to process tables/views through
@details
This method runs phases specified by the 'phases' on derived
tables/views found in the 'table_list' with help of the
TABLE_LIST::handle_derived function.
'this' is passed as an argument to the TABLE_LIST::handle_derived.
@return false - ok
@return true - error
*/
bool handle_list_of_derived(TABLE_LIST *table_list, uint phases)
{
for (TABLE_LIST *tl= table_list; tl; tl= tl->next_local)
{
if (tl->is_view_or_derived() && tl->handle_derived(this, phases))
return true;
}
return false;
}
};


Expand Down
10 changes: 8 additions & 2 deletions sql/sql_load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,9 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,

if (open_and_lock_tables(thd, table_list, TRUE, 0))
DBUG_RETURN(TRUE);
if (mysql_handle_single_derived(thd->lex, table_list, DT_MERGE_FOR_INSERT) ||
mysql_handle_single_derived(thd->lex, table_list, DT_PREPARE))
if (table_list->handle_derived(thd->lex, DT_MERGE_FOR_INSERT))
DBUG_RETURN(TRUE);
if (thd->lex->handle_list_of_derived(table_list, DT_PREPARE))
DBUG_RETURN(TRUE);
if (setup_tables_and_check_access(thd, &thd->lex->select_lex.context,
&thd->lex->select_lex.top_join_list,
Expand All @@ -310,6 +311,11 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "LOAD");
DBUG_RETURN(TRUE);
}
if (table_list->is_multitable())
{
my_error(ER_WRONG_USAGE, MYF(0), "Multi-table VIEW", "LOAD");
DBUG_RETURN(TRUE);
}
if (table_list->prepare_where(thd, 0, TRUE) ||
table_list->prepare_check_option(thd))
{
Expand Down
Loading

0 comments on commit f2e1451

Please sign in to comment.