diff options
author | unknown <gshchepa/uchum@host.loc> | 2008-04-26 02:45:58 +0500 |
---|---|---|
committer | unknown <gshchepa/uchum@host.loc> | 2008-04-26 02:45:58 +0500 |
commit | 5b8cdbf4a652e3a39aa2bd894c43293fb007a694 (patch) | |
tree | 168fdf05aa71e4176ac8753ebb98afdbd5b05dca | |
parent | 304c4381e69647aac38c7304bc0c3e4592f487dd (diff) | |
download | mariadb-git-5b8cdbf4a652e3a39aa2bd894c43293fb007a694.tar.gz |
Fixed bug#36006: Optimizer does table scan for SELECT COUNT(*)
for ENGINE=MRG_MYISAM (should be optimized out).
Before WL#3281 MERGE engine had the HA_NOT_EXACT_COUNT flag
unset, and it worked with COUNT optimization as desired.
After the removal of the HA_NOT_EXACT_COUNT flag neither
HA_STATS_RECORDS_IS_EXACT (opposite to former HA_NOT_EXACT_COUNT
flag) nor modern HA_HAS_RECORDS flag were not added to MERGE
table flag mask.
1. The HA_HAS_RECORDS table flag has been set.
2. The ha_myisammrg::records method has been overridden to
calculate total number of records in underlying tables.
storage/myisammrg/myrg_records.c:
Fixed bug#36006: Optimizer does table scan for select count(*).
The myrg_records function has been added to calculate total number
of records in underlying tables.
include/myisammrg.h:
Fixed bug#36006: Optimizer does table scan for select count(*).
The myrg_records function declaration has been added.
mysql-test/r/merge.result:
Added test case for bug#36006.
mysql-test/t/merge.test:
Added test case for bug#36006.
storage/myisammrg/CMakeLists.txt:
Fixed bug#36006: Optimizer does table scan for select count(*).
New myrg_records.c file has been added.
storage/myisammrg/Makefile.am:
Fixed bug#36006: Optimizer does table scan for select count(*).
New myrg_records.c file has been added.
storage/myisammrg/ha_myisammrg.cc:
Fixed bug#36006: Optimizer does table scan for select count(*).
The ha_myisammrg::records method has been overridden.
storage/myisammrg/ha_myisammrg.h:
Fixed bug#36006: Optimizer does table scan for select count(*).
1. The HA_HAS_RECORDS table flag has been set.
2. The ha_myisammrg::records method has been overridden.
-rw-r--r-- | include/myisammrg.h | 1 | ||||
-rw-r--r-- | mysql-test/r/merge.result | 16 | ||||
-rw-r--r-- | mysql-test/t/merge.test | 16 | ||||
-rwxr-xr-x | storage/myisammrg/CMakeLists.txt | 2 | ||||
-rw-r--r-- | storage/myisammrg/Makefile.am | 2 | ||||
-rw-r--r-- | storage/myisammrg/ha_myisammrg.cc | 6 | ||||
-rw-r--r-- | storage/myisammrg/ha_myisammrg.h | 2 | ||||
-rw-r--r-- | storage/myisammrg/myrg_records.c | 27 |
8 files changed, 70 insertions, 2 deletions
diff --git a/include/myisammrg.h b/include/myisammrg.h index cc6e6aac6cd..dafae157ee0 100644 --- a/include/myisammrg.h +++ b/include/myisammrg.h @@ -112,6 +112,7 @@ extern int myrg_reset(MYRG_INFO *info); extern void myrg_extrafunc(MYRG_INFO *info,invalidator_by_filename inv); extern ha_rows myrg_records_in_range(MYRG_INFO *info, int inx, key_range *min_key, key_range *max_key); +extern ha_rows myrg_records(MYRG_INFO *info); extern ulonglong myrg_position(MYRG_INFO *info); #ifdef __cplusplus diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result index 4c05000573c..ef623b343e9 100644 --- a/mysql-test/r/merge.result +++ b/mysql-test/r/merge.result @@ -2006,3 +2006,19 @@ test.t1 optimize status OK FLUSH TABLES m1, t1; UNLOCK TABLES; DROP TABLE t1, m1; +CREATE TABLE t1(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) ENGINE=MYISAM; +CREATE TABLE t2(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) ENGINE=MYISAM; +CREATE TABLE t3(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) ENGINE=MYISAM; +CREATE TABLE t4(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) +ENGINE=MRG_MYISAM UNION=(t1, t2, t3); +INSERT INTO t1 VALUES (1,1), (1,2),(1,3), (1,4); +INSERT INTO t2 VALUES (2,1), (2,2),(2,3), (2,4); +INSERT INTO t3 VALUES (3,1), (3,2),(3,3), (3,4); +EXPLAIN SELECT COUNT(*) FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +EXPLAIN SELECT COUNT(*) FROM t4; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +DROP TABLE t1, t2, t3, t4; +End of 5.1 tests diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index a4602a3b82a..76e746db037 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -1394,3 +1394,19 @@ FLUSH TABLES m1, t1; UNLOCK TABLES; DROP TABLE t1, m1; +# +# Bug#36006 - Optimizer does table scan for select count(*) +# +CREATE TABLE t1(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) ENGINE=MYISAM; +CREATE TABLE t2(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) ENGINE=MYISAM; +CREATE TABLE t3(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) ENGINE=MYISAM; +CREATE TABLE t4(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) + ENGINE=MRG_MYISAM UNION=(t1, t2, t3); +INSERT INTO t1 VALUES (1,1), (1,2),(1,3), (1,4); +INSERT INTO t2 VALUES (2,1), (2,2),(2,3), (2,4); +INSERT INTO t3 VALUES (3,1), (3,2),(3,3), (3,4); +EXPLAIN SELECT COUNT(*) FROM t1; +EXPLAIN SELECT COUNT(*) FROM t4; +DROP TABLE t1, t2, t3, t4; + +--echo End of 5.1 tests diff --git a/storage/myisammrg/CMakeLists.txt b/storage/myisammrg/CMakeLists.txt index 403ca6c2776..1c94e2bd50c 100755 --- a/storage/myisammrg/CMakeLists.txt +++ b/storage/myisammrg/CMakeLists.txt @@ -26,7 +26,7 @@ SET(MYISAMMRG_SOURCES myrg_close.c myrg_create.c myrg_delete.c myrg_extra.c myr myrg_locking.c myrg_open.c myrg_panic.c myrg_queue.c myrg_range.c myrg_rfirst.c myrg_rkey.c myrg_rlast.c myrg_rnext.c myrg_rnext_same.c myrg_rprev.c myrg_rrnd.c myrg_rsame.c myrg_static.c myrg_update.c - myrg_write.c) + myrg_write.c myrg_records.c) IF(NOT SOURCE_SUBLIBS) ADD_LIBRARY(myisammrg ${MYISAMMRG_SOURCES}) diff --git a/storage/myisammrg/Makefile.am b/storage/myisammrg/Makefile.am index e058dfdbb5e..1ca51bc9d03 100644 --- a/storage/myisammrg/Makefile.am +++ b/storage/myisammrg/Makefile.am @@ -35,7 +35,7 @@ libmyisammrg_a_SOURCES = myrg_open.c myrg_extra.c myrg_info.c myrg_locking.c \ myrg_rkey.c myrg_rfirst.c myrg_rlast.c myrg_rnext.c \ myrg_rprev.c myrg_queue.c myrg_write.c myrg_range.c \ ha_myisammrg.cc \ - myrg_rnext_same.c + myrg_rnext_same.c myrg_records.c EXTRA_DIST = CMakeLists.txt plug.in diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index ea7021325e3..956f0e421cc 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -1154,6 +1154,12 @@ int ha_myisammrg::check(THD* thd, HA_CHECK_OPT* check_opt) } +ha_rows ha_myisammrg::records() +{ + return myrg_records(file); +} + + extern int myrg_panic(enum ha_panic_function flag); int myisammrg_panic(handlerton *hton, ha_panic_function flag) { diff --git a/storage/myisammrg/ha_myisammrg.h b/storage/myisammrg/ha_myisammrg.h index 977c45d1435..4e7ddebb836 100644 --- a/storage/myisammrg/ha_myisammrg.h +++ b/storage/myisammrg/ha_myisammrg.h @@ -42,6 +42,7 @@ class ha_myisammrg: public handler HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE | HA_NULL_IN_KEY | HA_CAN_INDEX_BLOBS | HA_FILE_BASED | HA_ANY_INDEX_MAY_BE_UNIQUE | HA_CAN_BIT_FIELD | + HA_HAS_RECORDS | HA_NO_COPY_ON_ALTER); } ulong index_flags(uint inx, uint part, bool all_parts) const @@ -94,4 +95,5 @@ class ha_myisammrg: public handler TABLE *table_ptr() { return table; } bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes); int check(THD* thd, HA_CHECK_OPT* check_opt); + ha_rows records(); }; diff --git a/storage/myisammrg/myrg_records.c b/storage/myisammrg/myrg_records.c new file mode 100644 index 00000000000..03815d934a8 --- /dev/null +++ b/storage/myisammrg/myrg_records.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2008 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include "myrg_def.h" + +ha_rows myrg_records(MYRG_INFO *info) +{ + ha_rows records=0; + MYRG_TABLE *file; + DBUG_ENTER("myrg_records"); + + for (file=info->open_tables ; file != info->end_table ; file++) + records+= file->table->s->state.state.records; + DBUG_RETURN(records); +} |