From: Mattias Jonsson Date: May 8 2012 7:21pm Subject: bzr push into mysql-trunk branch (mattias.jonsson:3798 to 3799) WL#4443 List-Archive: http://lists.mysql.com/commits/143770 Message-Id: <201205081921.q48JLHrw001809@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3799 Mattias Jonsson 2012-05-08 WL#4443 Avoid creating SEL_TREE when not needed in prune_partitions(). modified: mysql-test/r/partition_pruning.result sql/opt_range.cc sql/partition_info.cc sql/partition_info.h 3798 Mattias Jonsson 2012-05-08 [merge] WL#4443 Merge into latest mysql-trunk added: mysql-test/collections/mysql-trunk-wl4443.push mysql-test/r/partition_locking.result mysql-test/t/partition_locking.test modified: include/my_bitmap.h mysql-test/include/commit.inc mysql-test/r/commit_1innodb.result mysql-test/r/explain.result mysql-test/r/func_if.result mysql-test/r/grant_cache_no_prot.result mysql-test/r/innodb_explain_json_non_select_all.result mysql-test/r/innodb_explain_json_non_select_none.result mysql-test/r/innodb_explain_non_select_all.result mysql-test/r/innodb_explain_non_select_none.result mysql-test/r/myisam_explain_json_non_select_all.result mysql-test/r/myisam_explain_json_non_select_none.result mysql-test/r/myisam_explain_non_select_all.result mysql-test/r/myisam_explain_non_select_none.result mysql-test/r/partition_binlog.result mysql-test/r/partition_datatype.result mysql-test/r/partition_error.result mysql-test/r/partition_explicit_prune.result mysql-test/r/partition_pruning.result mysql-test/r/partition_truncate.result mysql-test/r/type_date.result mysql-test/suite/binlog/r/binlog_unsafe.result mysql-test/suite/opt_trace/r/bugs_no_prot_all.result mysql-test/suite/opt_trace/r/bugs_no_prot_none.result mysql-test/suite/opt_trace/r/bugs_ps_prot_all.result mysql-test/suite/opt_trace/r/bugs_ps_prot_none.result mysql-test/suite/parts/inc/partition-dml-1-9.inc mysql-test/suite/parts/r/partition-dml-1-9-innodb.result mysql-test/suite/parts/r/partition-dml-1-9-myisam.result mysql-test/suite/perfschema/r/part_table_io.result mysql-test/suite/perfschema/r/stage_mdl_function.result mysql-test/t/explain.test mysql-test/t/partition_binlog.test mysql-test/t/partition_explicit_prune.test mysql-test/t/partition_pruning.test mysql-test/t/partition_truncate.test mysql-test/t/type_date.test mysys/my_bitmap.c sql/ha_partition.cc sql/ha_partition.h sql/handler.cc sql/handler.h sql/item.cc sql/item.h sql/item_cmpfunc.cc sql/item_func.cc sql/item_func.h sql/item_strfunc.h sql/item_subselect.cc sql/log_event.cc sql/opt_explain.cc sql/opt_range.cc sql/opt_range.h sql/partition_info.cc sql/partition_info.h sql/rpl_info_table_access.cc sql/share/errmsg-utf8.txt sql/sql_base.cc sql/sql_base.h sql/sql_cache.h sql/sql_class.cc sql/sql_class.h sql/sql_delete.cc sql/sql_executor.cc sql/sql_insert.cc sql/sql_insert.h sql/sql_join_buffer.cc sql/sql_lex.cc sql/sql_lex.h sql/sql_optimizer.cc sql/sql_parse.cc sql/sql_parse.h sql/sql_partition.cc sql/sql_partition_admin.cc sql/sql_prepare.cc sql/sql_resolver.cc sql/sql_select.cc sql/sql_select.h sql/sql_show.cc sql/sql_union.cc sql/sql_update.cc sql/sql_view.cc sql/table.cc sql/table.h unittest/gunit/my_bitmap-t.cc === modified file 'mysql-test/r/partition_pruning.result' --- a/mysql-test/r/partition_pruning.result revid:mattias.jonsson@stripped +++ b/mysql-test/r/partition_pruning.result revid:mattias.jonsson@stripped @@ -2238,7 +2238,6 @@ id select_type table partitions type pos 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: Warning 1292 Incorrect datetime value: '2009-04-99' -Warning 1292 Incorrect datetime value: '2009-04-99' DROP TABLE t1; CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT, === modified file 'sql/opt_range.cc' --- a/sql/opt_range.cc revid:mattias.jonsson@stripped +++ b/sql/opt_range.cc revid:mattias.jonsson@stripped @@ -3041,6 +3041,7 @@ static void dbug_print_singlepoint_range @param thd Thread handle @param table Table to perform partition pruning for @param pprune_cond Condition to use for partition pruning + @param is_prepare Is prepare stage @note This function assumes that lock_partitions are setup when it is invoked. The function analyzes the condition, finds partitions that @@ -3073,23 +3074,24 @@ bool prune_partitions(THD *thd, TABLE *t DBUG_RETURN(FALSE); } + /* No need to continue pruning if there is no more partitions to prune! */ + if (bitmap_is_clear_all(&part_info->lock_partitions)) + bitmap_clear_all(&part_info->read_partitions); + if (bitmap_is_clear_all(&part_info->read_partitions)) + { + table->all_partitions_pruned_away= true; + DBUG_RETURN(false); + } + /* - If only constant items and no subqueries are used, it is no use of running - prune_partitions() twice on the same statement. - It is cheeper to run in the JOIN::optimize than in the JOIN::prepare - step since in the optimize step there are already cached items. - But there are greater gains if done before before the optimize step, - since this can also prune away calls to store_lock, external_lock and - start_stmt. - - So if we are in the optimize step and have only constant items - and no subqueries, simply return. Since it will not be able to prune - anything more than the previous call from the prepare step. + If the prepare stage only had constant items and no subqueries are used, + it is no use of running prune_partitions() twice on the same statement. + Since it will not be able to prune anything more than the previous call + from the prepare step. */ - if (!is_prepare && - pprune_cond->const_item() && + if (part_info->is_const_pruned() && !pprune_cond->has_subquery()) - DBUG_RETURN(FALSE); + DBUG_RETURN(false); PART_PRUNE_PARAM prune_param; MEM_ROOT alloc; @@ -3221,6 +3223,7 @@ end: } if (bitmap_is_clear_all(&(prune_param.part_info->read_partitions))) table->all_partitions_pruned_away= true; + part_info->set_prune_state(is_prepare, pprune_cond->const_item()); DBUG_RETURN(false); } === modified file 'sql/partition_info.cc' --- a/sql/partition_info.cc revid:mattias.jonsson@stripped +++ b/sql/partition_info.cc revid:mattias.jonsson@stripped @@ -223,6 +223,7 @@ bool partition_info::set_partition_bitma DBUG_ASSERT(bitmaps_are_initialized); DBUG_ASSERT(table); + prune_state= NOT_PRUNED; if (!bitmaps_are_initialized) DBUG_RETURN(TRUE); @@ -2732,6 +2733,39 @@ bool partition_info::fix_parser_data(THD } +/** + Is the table pruned when cond->const_item() was true. +*/ + +bool partition_info::is_const_pruned() const +{ + if (prune_state >= PREPARE_CONST_PRUNED) + return true; + return false; +} + + +/** + Set prune_state. + + @param is_prepare Is in prepare stage. + @param is_const Is the pruning condition const_item. +*/ + +void partition_info::set_prune_state(bool is_prepare, bool is_const) +{ + if (is_prepare) + { + if (is_const) + prune_state= PREPARE_CONST_PRUNED; + else + prune_state= PREPARE_PRUNED; + } + else + prune_state= OPTIMIZE_PRUNED; +} + + void partition_info::print_debug(const char *str, uint *value) { DBUG_ENTER("print_debug"); === modified file 'sql/partition_info.h' --- a/sql/partition_info.h revid:mattias.jonsson@stripped +++ b/sql/partition_info.h revid:mattias.jonsson@stripped @@ -223,6 +223,9 @@ public: bool from_openfrm; bool has_null_value; bool column_list; // COLUMNS PARTITIONING, 5.5+ + enum enum_prune_state { NOT_PRUNED= 0, PREPARE_PRUNED, PREPARE_CONST_PRUNED, + OPTIMIZE_PRUNED }; + enum_prune_state prune_state; partition_info() : get_partition_id(NULL), get_part_partition_id(NULL), @@ -255,7 +258,7 @@ public: list_of_part_fields(FALSE), list_of_subpart_fields(FALSE), linear_hash_ind(FALSE), fixed(FALSE), is_auto_partitioned(FALSE), from_openfrm(FALSE), - has_null_value(FALSE), column_list(FALSE) + has_null_value(FALSE), column_list(FALSE), prune_state(NOT_PRUNED) { partitions.empty(); temp_partitions.empty(); @@ -329,6 +332,8 @@ public: List &fields, bool empty_values, bool *prune_needs_default_values); + bool is_const_pruned() const; + void set_prune_state(bool is_prepare, bool is_const); private: static int list_part_cmp(const void* a, const void* b); bool set_up_default_partitions(handler *file, HA_CREATE_INFO *info, No bundle (reason: useless for push emails).