From aebb1038aab6cadc3408fc194d1d9331d2b673ff Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 23 Nov 2016 12:54:59 +0100 Subject: bugfix: multi-UPDATE, vcols, const tables multi-update was setting up read_set/vcol_set in multi_update::initialize_tables() that is invoked after the optimizer (JOIN::optimize_inner()). But some rows - if they're from const tables - will be read already in the optimizer, and these rows will not have all necessary column/vcol values. * multi_update::initialize_tables() uses results from the optimizer and cannot be moved to be called earlier. * multi_update::prepare() is called before the optimizer, but it cannot set up read_set/vcol_set, because the optimizer might reset them (see SELECT_LEX::update_used_tables()). As a fix I've added a new method, select_result::prepare_to_read_rows(), it's called from inside the optimizer just before make_join_statistics(). --- sql/sql_lex.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'sql/sql_lex.cc') diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index bea3b14e607..634b6d1a3b8 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -4122,6 +4122,15 @@ void SELECT_LEX::update_used_tables() TABLE *tab= tl->table; tab->covering_keys= tab->s->keys_for_keyread; tab->covering_keys.intersect(tab->keys_in_use_for_query); + /* + View/derived was merged. Need to recalculate read_set/vcol_set + bitmaps here. For example: + CREATE VIEW v1 AS SELECT f1,f2,f3 FROM t1; + SELECT f1 FROM v1; + Initially, the view definition will put all f1,f2,f3 in the + read_set for t1. But after the view is merged, only f1 should + be in the read_set. + */ bitmap_clear_all(tab->read_set); if (tab->vcol_set) bitmap_clear_all(tab->vcol_set); -- cgit v1.2.1