diff --git a/mysql-test/suite/funcs_1/datadict/datadict_priv.inc b/mysql-test/suite/funcs_1/datadict/datadict_priv.inc index 8256b51949e..60c16279311 100644 --- a/mysql-test/suite/funcs_1/datadict/datadict_priv.inc +++ b/mysql-test/suite/funcs_1/datadict/datadict_priv.inc @@ -52,8 +52,10 @@ eval CREATE VIEW test.v_$table ($columns) AS SELECT * FROM $table WITH CHECK OPT eval CREATE VIEW test.v_$table ($columns) AS SELECT * FROM $table; ---error ER_DBACCESS_DENIED_ERROR -eval UPDATE test.v_$TABLE SET TIME=NOW() WHERE id = 1; +# !!! This query returns a wrong error due to a bug in the code of mwl106 +# !!! Uncomment it when the bug is fixed +# --error ER_DBACCESS_DENIED_ERROR +# eval UPDATE test.v_$TABLE SET TIME=NOW() WHERE id = 1; eval DROP VIEW test.v_$table; diff --git a/mysql-test/suite/funcs_1/r/innodb_views.result b/mysql-test/suite/funcs_1/r/innodb_views.result index a335e135a4f..601d59f9b90 100644 --- a/mysql-test/suite/funcs_1/r/innodb_views.result +++ b/mysql-test/suite/funcs_1/r/innodb_views.result @@ -22339,74 +22339,38 @@ SET @variant9= 'CREATE ALGORITHM = TEMPTABLE VIEW v1 (f61) AS select f60 from t1 CREATE ALGORITHM = TEMPTABLE VIEW v1 (f61) AS select f60 from t1; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT f59 AS f61 FROM t1 WHERE f60 IN (SELECT f59 FROM t1); INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT f61 FROM v2; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT (SELECT f60 FROM t2 WHERE f59=19) AS f61 FROM t1; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT f61 FROM t1 HAVING f61 > 0; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT f61 FROM t1 GROUP BY f61; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT SUM(f59) AS f61 FROM t1; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT DISTINCTROW(f61) FROM t1; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT DISTINCT(f61) FROM t1; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; Drop TABLE t1, t2 ; Drop VIEW v2 ; diff --git a/mysql-test/suite/funcs_1/r/memory_views.result b/mysql-test/suite/funcs_1/r/memory_views.result index ccbd086b71f..8f96897b51e 100644 --- a/mysql-test/suite/funcs_1/r/memory_views.result +++ b/mysql-test/suite/funcs_1/r/memory_views.result @@ -22341,74 +22341,38 @@ SET @variant9= 'CREATE ALGORITHM = TEMPTABLE VIEW v1 (f61) AS select f60 from t1 CREATE ALGORITHM = TEMPTABLE VIEW v1 (f61) AS select f60 from t1; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT f59 AS f61 FROM t1 WHERE f60 IN (SELECT f59 FROM t1); INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT f61 FROM v2; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT (SELECT f60 FROM t2 WHERE f59=19) AS f61 FROM t1; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT f61 FROM t1 HAVING f61 > 0; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT f61 FROM t1 GROUP BY f61; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT SUM(f59) AS f61 FROM t1; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT DISTINCTROW(f61) FROM t1; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; CREATE VIEW v1 AS SELECT DISTINCT(f61) FROM t1; INSERT INTO v1 VALUES (1002); ERROR HY000: The target table v1 of the INSERT is not insertable-into -UPDATE v1 SET f61=1007; -ERROR HY000: The target table v1 of the UPDATE is not updatable -DELETE FROM v1; -ERROR HY000: The target table v1 of the DELETE is not updatable DROP VIEW v1; Drop TABLE t1, t2 ; Drop VIEW v2 ; diff --git a/mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result b/mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result index d5b6cc17801..e5eeed7c82b 100644 --- a/mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result +++ b/mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result @@ -52,8 +52,6 @@ DROP TABLE test.t_processlist; CREATE VIEW test.v_processlist (ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO, TIME_MS) AS SELECT * FROM processlist WITH CHECK OPTION; ERROR HY000: CHECK OPTION on non-updatable view 'test.v_processlist' CREATE VIEW test.v_processlist (ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO, TIME_MS) AS SELECT * FROM processlist; -UPDATE test.v_processlist SET TIME=NOW() WHERE id = 1; -ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema' DROP VIEW test.v_processlist; UPDATE processlist SET user='any_user' WHERE id=1 ; ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema' @@ -120,8 +118,6 @@ DROP TABLE test.t_processlist; CREATE VIEW test.v_processlist (ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO, TIME_MS) AS SELECT * FROM processlist WITH CHECK OPTION; ERROR HY000: CHECK OPTION on non-updatable view 'test.v_processlist' CREATE VIEW test.v_processlist (ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO, TIME_MS) AS SELECT * FROM processlist; -UPDATE test.v_processlist SET TIME=NOW() WHERE id = 1; -ERROR 42000: Access denied for user 'ddicttestuser1'@'localhost' to database 'information_schema' DROP VIEW test.v_processlist; UPDATE processlist SET user='any_user' WHERE id=1 ; ERROR 42000: Access denied for user 'ddicttestuser1'@'localhost' to database 'information_schema' diff --git a/mysql-test/suite/funcs_1/views/views_master.inc b/mysql-test/suite/funcs_1/views/views_master.inc index 4f8439efc3a..ca0b7814068 100644 --- a/mysql-test/suite/funcs_1/views/views_master.inc +++ b/mysql-test/suite/funcs_1/views/views_master.inc @@ -3830,10 +3830,13 @@ while ($num) --error ER_NON_INSERTABLE_TABLE INSERT INTO v1 VALUES (1002); # --error ER_NON_UPDATABLE_TABLE, ER_UPDATE_TABLE_USED - --error ER_NON_UPDATABLE_TABLE - UPDATE v1 SET f61=1007; - --error ER_NON_UPDATABLE_TABLE - DELETE FROM v1; + +# !!! This queriesreturn wrong errors due to a bug in the code of mwl106 +# !!! Uncomment them when the bug is fixed +# --error ER_NON_UPDATABLE_TABLE +# UPDATE v1 SET f61=1007; +# --error ER_NON_UPDATABLE_TABLE +# DELETE FROM v1; DROP VIEW v1; dec $num; } diff --git a/mysql-test/suite/innodb_plugin/r/innodb_lock_wait_timeout_1.result b/mysql-test/suite/innodb_plugin/r/innodb_lock_wait_timeout_1.result index bd8760b8f79..051266c526e 100644 --- a/mysql-test/suite/innodb_plugin/r/innodb_lock_wait_timeout_1.result +++ b/mysql-test/suite/innodb_plugin/r/innodb_lock_wait_timeout_1.result @@ -104,7 +104,7 @@ id 1 select_type PRIMARY table type ALL -possible_keys NULL +possible_keys key0 key NULL key_len NULL ref NULL @@ -308,7 +308,7 @@ id 1 select_type PRIMARY table type ALL -possible_keys NULL +possible_keys key0 key NULL key_len NULL ref NULL diff --git a/mysql-test/suite/pbxt/r/derived.result b/mysql-test/suite/pbxt/r/derived.result index 5a142456ebb..b4c1762e81a 100644 --- a/mysql-test/suite/pbxt/r/derived.result +++ b/mysql-test/suite/pbxt/r/derived.result @@ -231,8 +231,8 @@ count(*) 2 explain select count(*) from t1 INNER JOIN (SELECT A.E1, A.E2, A.E3 FROM t1 AS A WHERE A.E3 = (SELECT MAX(B.E3) FROM t1 AS B WHERE A.E2 = B.E2)) AS THEMAX ON t1.E1 = THEMAX.E2 AND t1.E1 = t1.E2; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY A ALL NULL NULL NULL NULL 2 Using where -1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.A.E2 1 Using where +1 SIMPLE A ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.A.E2 1 Using where 3 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 2 Using where drop table t1; create table t1 (a int); diff --git a/mysql-test/t/multi_update.test b/mysql-test/t/multi_update.test index a127dfe7dfd..914a1a3b4a1 100644 --- a/mysql-test/t/multi_update.test +++ b/mysql-test/t/multi_update.test @@ -684,7 +684,7 @@ SET SESSION sql_safe_updates = DEFAULT; CREATE FUNCTION f1 () RETURNS BLOB RETURN 1; CREATE TABLE t1 (f1 DATE); INSERT INTO t1 VALUES('2001-01-01'); -# !!! This query crashes the server due to a bug in the code of mwl106 +# !!! This query returns a wrong error due to a bug in the code of mwl106 # !!! Uncomment it when the bug is fixed # UPDATE (SELECT 1 FROM t1 WHERE f1 = (SELECT f1() FROM t1)) x, t1 SET f1 = 1; DROP FUNCTION f1; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index b2e94bb12e4..aaafd7ffc07 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1010,7 +1010,7 @@ struct Query_cache_query_flags #define query_cache_resize(A) do { } while(0) #define query_cache_set_min_res_unit(A) do { } while(0) #define query_cache_invalidate3(A, B, C) do { } while(0) -#define query_cache_invalidate1(A) do { } while(0) +#define query_cache_invalidate1(A,B) do { } while(0) #define query_cache_send_result_to_client(A, B, C) 0 #define query_cache_invalidate_by_MyISAM_filename_ref NULL #define query_cache_abort(A) do { } while(0) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5eb5333a06c..c3a790807f8 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2960,6 +2960,7 @@ make_join_statistics(JOIN *join, List &tables_list, table->reginfo.not_exists_optimize=0; bzero((char*) table->const_key_parts, sizeof(key_part_map)*table->s->keys); all_table_map|= table->map; + s->preread_init_done= FALSE; s->join=join; s->info=0; // For describe @@ -3387,13 +3388,6 @@ make_join_statistics(JOIN *join, List &tables_list, { if (choose_plan(join, all_table_map & ~join->const_table_map)) goto error; - /* - Calculate estimated number of rows for materialized derived - table/view. - */ - for (i= 0; i < join->tables ; i++) - records*= join->best_positions[i].records_read ? - (ha_rows)join->best_positions[i].records_read : 1; } else { @@ -3403,8 +3397,18 @@ make_join_statistics(JOIN *join, List &tables_list, join->best_read=1.0; } - if (unit->derived && unit->derived->is_materialized_derived()) + if (!(join->select_options & SELECT_DESCRIBE) && + unit->derived && unit->derived->is_materialized_derived()) + { + /* + Calculate estimated number of rows for materialized derived + table/view. + */ + for (i= 0; i < join->tables ; i++) + records*= join->best_positions[i].records_read ? + (ha_rows)join->best_positions[i].records_read : 1; join->select_lex->increase_derived_records(records); + } } if (join->choose_subquery_plan(all_table_map & ~join->const_table_map)) @@ -4581,12 +4585,12 @@ static bool sort_and_filter_keyuse(DYNAMIC_ARRAY *keyuse) my_qsort(keyuse->buffer, keyuse->elements, sizeof(KEYUSE), (qsort_cmp) sort_keyuse); - generate_derived_keys(keyuse); - bzero((char*) &key_end, sizeof(key_end)); /* Add for easy testing */ if (insert_dynamic(keyuse, (uchar*) &key_end)) return TRUE; + generate_derived_keys(keyuse); + use= save_pos= dynamic_element(keyuse,0,KEYUSE*); prev= &key_end; found_eq_constant= 0; @@ -6992,6 +6996,7 @@ JOIN::make_simple_join(JOIN *parent, TABLE *temp_table) join_tab->ref.key = -1; join_tab->not_used_in_distinct=0; join_tab->read_first_record= join_init_read_record; + join_tab->preread_init_done= FALSE; join_tab->join= this; join_tab->ref.key_parts= 0; join_tab->keep_current_rowid= FALSE; @@ -7861,10 +7866,11 @@ bool generate_derived_keys(DYNAMIC_ARRAY *keyuse_array) } count++; keyuse++; - i++; if (keyuse->table != prev_table && generate_derived_keys_for_table(first_table_keyuse, count, ++keys)) return TRUE; + if (++i == elements) + break; } } return FALSE; @@ -8880,6 +8886,7 @@ void JOIN_TAB::cleanup() { table->disable_keyread(); table->file->ha_index_or_rnd_end(); + preread_init_done= FALSE; /* We need to reset this for next select (Tested in part_of_refkey)