From: Pekka Nousiainen Date: September 2 2011 6:45am Subject: bzr push into mysql-5.1-telco-7.0-wl4124-new3 branch (pekka.nousiainen:4492 to 4494) WL#4124 List-Archive: http://lists.mysql.com/commits/140892 Message-Id: <20110902064510.F31575587A@sama.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 4494 Pekka Nousiainen 2011-09-02 wl#4124 g04_rir.diff remove "1.0+" from rule b3.3 modified: mysql-test/suite/ndb/r/ndb_index_stat.result mysql-test/suite/ndb/r/ndb_statistics1.result mysql-test/suite/ndb/t/ndb_index_stat.test sql/ha_ndb_index_stat.cc storage/ndb/src/ndbapi/NdbIndexStatImpl.cpp 4493 Pekka Nousiainen 2011-09-02 wl#4124 g03_rir.diff NdbIndexStatImpl: more cache validation modified: storage/ndb/src/ndbapi/NdbIndexStatImpl.cpp storage/ndb/src/ndbapi/ndberror.c 4492 Pekka Nousiainen 2011-08-31 wl#4124 g02_rir.diff optimizer RIR sets weird HA_READ_KEY_EXACT modified: mysql-test/suite/ndb/r/ndb_statistics1.result sql/ha_ndb_index_stat.cc sql/ha_ndb_index_stat.h sql/ha_ndbcluster.cc sql/ha_ndbcluster.h storage/ndb/src/ndbapi/NdbIndexStat.cpp === modified file 'mysql-test/suite/ndb/r/ndb_index_stat.result' --- a/mysql-test/suite/ndb/r/ndb_index_stat.result 2011-08-28 13:29:22 +0000 +++ b/mysql-test/suite/ndb/r/ndb_index_stat.result 2011-09-02 06:43:38 +0000 @@ -487,6 +487,67 @@ id select_type table type possible_keys 1 SIMPLE t1 ref PRIMARY,a1 a1 5 const 2 # 1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.b1 50 # drop table t1, t2; +CREATE TABLE t1( +K INT NOT NULL AUTO_INCREMENT, +I INT, +J INT, +L INT, +PRIMARY KEY(K), +KEY(I,J), +KEY(L) +) ENGINE=ndbcluster +partition by key (K) partitions 1; +INSERT INTO t1(I,J,L) VALUES +(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5), +(6,6,6),(7,7,7),(8,8,8),(9,9,9),(0,0,0); +INSERT INTO t1(I,J,L) SELECT I,1,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,2,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,3,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,4,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,5,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,6,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,7,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,8,I FROM t1; +select i, count(*) from t1 group by 1 order by 1; +i count(*) +0 256 +1 256 +2 256 +3 256 +4 256 +5 256 +6 256 +7 256 +8 256 +9 256 +select l, count(*) from t1 group by 1 order by 1; +l count(*) +0 256 +1 256 +2 256 +3 256 +4 256 +5 256 +6 256 +7 256 +8 256 +9 256 +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +explain SELECT count(*) as Count FROM t1 WHERE I = 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref I I 5 const 256 Using where with pushed condition +SELECT count(*) as Count FROM t1 WHERE I = 5; +Count +256 +explain SELECT count(*) as Count FROM t1 WHERE L = 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref L L 5 const 256 Using where with pushed condition +SELECT count(*) as Count FROM t1 WHERE L = 5; +Count +256 +drop table t1; set @is_enable = @is_enable_default; set @is_enable = NULL; # is_enable_on=0 is_enable_off=1 === modified file 'mysql-test/suite/ndb/r/ndb_statistics1.result' --- a/mysql-test/suite/ndb/r/ndb_statistics1.result 2011-08-31 10:53:27 +0000 +++ b/mysql-test/suite/ndb/r/ndb_statistics1.result 2011-09-02 06:43:38 +0000 @@ -63,11 +63,11 @@ id select_type table type possible_keys EXPLAIN SELECT * FROM t10000 WHERE k BETWEEN 42 AND 10000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t10000 range PRIMARY PRIMARY 4 NULL 9958 Using where with pushed condition +1 SIMPLE t10000 range PRIMARY PRIMARY 4 NULL 9959 Using where with pushed condition EXPLAIN SELECT * FROM t10000 WHERE k < 42; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t10000 range PRIMARY PRIMARY 4 NULL 42 Using where with pushed condition +1 SIMPLE t10000 range PRIMARY PRIMARY 4 NULL 41 Using where with pushed condition EXPLAIN SELECT * FROM t10000 WHERE k > 42; id select_type table type possible_keys key key_len ref rows Extra @@ -81,7 +81,7 @@ id select_type table type possible_keys EXPLAIN SELECT * FROM t100 WHERE k < 42; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t100 range PRIMARY PRIMARY 4 NULL 42 Using where with pushed condition +1 SIMPLE t100 range PRIMARY PRIMARY 4 NULL 41 Using where with pushed condition EXPLAIN SELECT * FROM t100 WHERE k > 42; id select_type table type possible_keys key key_len ref rows Extra @@ -89,7 +89,7 @@ id select_type table type possible_keys EXPLAIN SELECT * FROM t10000 WHERE k < 42; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t10000 range PRIMARY PRIMARY 4 NULL 42 Using where with pushed condition +1 SIMPLE t10000 range PRIMARY PRIMARY 4 NULL 41 Using where with pushed condition EXPLAIN SELECT * FROM t10000 WHERE k > 42; id select_type table type possible_keys key key_len ref rows Extra @@ -97,11 +97,11 @@ id select_type table type possible_keys EXPLAIN SELECT * FROM t100 WHERE k BETWEEN 42 AND 10000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t100 range PRIMARY PRIMARY 4 NULL 58 Using where with pushed condition +1 SIMPLE t100 range PRIMARY PRIMARY 4 NULL 59 Using where with pushed condition EXPLAIN SELECT * FROM t10000 WHERE k BETWEEN 42 AND 10000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t10000 range PRIMARY PRIMARY 4 NULL 9958 Using where with pushed condition +1 SIMPLE t10000 range PRIMARY PRIMARY 4 NULL 9959 Using where with pushed condition EXPLAIN SELECT * FROM t10000 WHERE I = 0; id select_type table type possible_keys key key_len ref rows Extra === modified file 'mysql-test/suite/ndb/t/ndb_index_stat.test' --- a/mysql-test/suite/ndb/t/ndb_index_stat.test 2011-08-28 13:29:22 +0000 +++ b/mysql-test/suite/ndb/t/ndb_index_stat.test 2011-09-02 06:43:38 +0000 @@ -334,5 +334,45 @@ explain select * from t1, t2 where b2 = drop table t1, t2; +# bugXXXXX rule b3.3 fix + +CREATE TABLE t1( + K INT NOT NULL AUTO_INCREMENT, + I INT, + J INT, + L INT, + PRIMARY KEY(K), + KEY(I,J), + KEY(L) +) ENGINE=ndbcluster + partition by key (K) partitions 1; + +INSERT INTO t1(I,J,L) VALUES +(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5), +(6,6,6),(7,7,7),(8,8,8),(9,9,9),(0,0,0); + +INSERT INTO t1(I,J,L) SELECT I,1,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,2,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,3,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,4,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,5,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,6,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,7,I FROM t1; +INSERT INTO t1(I,J,L) SELECT I,8,I FROM t1; + +select i, count(*) from t1 group by 1 order by 1; +select l, count(*) from t1 group by 1 order by 1; + +ANALYZE TABLE t1; + +explain SELECT count(*) as Count FROM t1 WHERE I = 5; +SELECT count(*) as Count FROM t1 WHERE I = 5; + +# before fix rows was 128 instead of 256 +explain SELECT count(*) as Count FROM t1 WHERE L = 5; +SELECT count(*) as Count FROM t1 WHERE L = 5; + +drop table t1; + set @is_enable = @is_enable_default; source ndb_index_stat_enable.inc; === modified file 'sql/ha_ndb_index_stat.cc' --- a/sql/ha_ndb_index_stat.cc 2011-08-31 10:53:27 +0000 +++ b/sql/ha_ndb_index_stat.cc 2011-09-02 06:43:38 +0000 @@ -2107,7 +2107,11 @@ ha_ndbcluster::ndb_index_stat_get_rir(ui if (rows == 0) rows= 1; *rows_out= rows; - DBUG_PRINT("index_stat", ("rir: %u", (uint)rows)); +#ifndef DBUG_OFF + char rule[NdbIndexStat::RuleBufferBytes]; + NdbIndexStat::get_rule(stat, rule); +#endif + DBUG_PRINT("index_stat", ("rir: %u rule: %s", (uint)rows, rule)); DBUG_RETURN(0); } DBUG_RETURN(err); @@ -2135,7 +2139,11 @@ ha_ndbcluster::ndb_index_stat_set_rpk(ui NdbIndexStat::get_rpk(stat, k, &rpk); ulonglong recs= ndb_index_stat_round(rpk); key_info->rec_per_key[k]= (ulong)recs; - DBUG_PRINT("index_stat", ("rpk[%u]: %u", k, (uint)recs)); +#ifndef DBUG_OFF + char rule[NdbIndexStat::RuleBufferBytes]; + NdbIndexStat::get_rule(stat, rule); +#endif + DBUG_PRINT("index_stat", ("rpk[%u]: %u rule: %s", k, (uint)recs, rule)); } DBUG_RETURN(0); } === modified file 'storage/ndb/src/ndbapi/NdbIndexStatImpl.cpp' --- a/storage/ndb/src/ndbapi/NdbIndexStatImpl.cpp 2011-08-12 05:16:41 +0000 +++ b/storage/ndb/src/ndbapi/NdbIndexStatImpl.cpp 2011-09-02 06:43:38 +0000 @@ -1506,16 +1506,32 @@ NdbIndexStatImpl::cache_insert(Con& con) const Uint8* rir_ptr = &cacheValuePtr[0]; Uint32 rir; memcpy(&rir, rir_ptr, 4); - assert(rir != 0); + if (!(rir != 0)) + { + setError(InvalidCache, __LINE__); + return -1; + } Uint32 unq_prev = 0; for (uint k = 0; k < c.m_keyAttrs; k++) { Uint8* unq_ptr = &cacheValuePtr[4 + k * 4]; Uint32 unq; memcpy(&unq, unq_ptr, 4); - assert(unq != 0); - assert(rir >= unq); - assert(unq >= unq_prev); + if (!(unq != 0)) + { + setError(InvalidCache, __LINE__); + return -1; + } + if (!(rir >= unq)) + { + setError(InvalidCache, __LINE__); + return -1; + } + if (!(unq >= unq_prev)) + { + setError(InvalidCache, __LINE__); + return -1; + } unq_prev = unq; } } @@ -1713,6 +1729,34 @@ NdbIndexStatImpl::cache_verify(const Cac setError(InvalidCache, __LINE__); return -1; } + const Uint8* ptr1 = c.get_valueptr(pos1); + const Uint8* ptr2 = c.get_valueptr(pos2); + Uint32 rir1; + Uint32 rir2; + memcpy(&rir1, &ptr1[0], 4); + memcpy(&rir2, &ptr2[0], 4); + if (!(rir1 < rir2)) + { + setError(InvalidCache, __LINE__); + return -1; + } + for (uint k = 0; k < c.m_keyAttrs; k++) + { + Uint32 unq1; + Uint32 unq2; + memcpy(&unq1, &ptr1[4 + k * 4], 4); + memcpy(&unq2, &ptr2[4 + k * 4], 4); + if (!(unq1 <= unq2)) + { + setError(InvalidCache, __LINE__); + return -1; + } + if (k == c.m_keyAttrs - 1 && !(unq1 < unq2)) + { + setError(InvalidCache, __LINE__); + return -1; + } + } } } return 0; @@ -2196,7 +2240,7 @@ NdbIndexStatImpl::query_interpolate(cons cnt == stat.m_numEqH && side == -1) { stat.m_rule = "b3.3"; - const double u = 1.0 + c.get_unq(posL, posH, keyAttrs - 1); + const double u = c.get_unq(posL, posH, keyAttrs - 1); const double wL = 1.0 / u; const double wH = 1.0 - wL; value.m_rir = wL * c.get_rir(posL) + wH * c.get_rir(posH); === modified file 'storage/ndb/src/ndbapi/ndberror.c' --- a/storage/ndb/src/ndbapi/ndberror.c 2011-07-04 13:37:56 +0000 +++ b/storage/ndb/src/ndbapi/ndberror.c 2011-09-02 06:05:23 +0000 @@ -546,7 +546,7 @@ ErrorBundle ErrorCodes[] = { { 4715, DMEC, AE, "Index stats for specified index do not exist" }, { 4716, DMEC, AE, "Index stats methods usage error" }, { 4717, DMEC, AE, "Index stats cannot allocate memory" }, - { 4718, DMEC, IE, "Index stats memory cache is corrupted" }, + { 4718, DMEC, IE, "Index stats samples data or memory cache is invalid" }, { 4719, DMEC, IE, "Index stats internal error" }, { 4720, DMEC, AE, "Index stats sys tables " NDB_INDEX_STAT_PREFIX " partly missing or invalid" }, No bundle (reason: useless for push emails).