From: Date: December 18 2007 1:40pm Subject: bk commit into 5.1 tree (knielsen:1.2645) BUG#33061 List-Archive: http://lists.mysql.com/commits/40132 X-Bug: 33061 Message-Id: <1197981656.0@ymer> Below is the list of changes that have just been committed into a local 5.1 repository of knielsen. When knielsen does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-12-18 13:40:35+01:00, knielsen@ymer.(none) +5 -0 Bug #33061: ORDER BY DESC becomes ASC in NDB partition pruning to one partition When partition pruning resulted in an ordered index scan spanning only one partition, any descending flag for the scan was wrongly discarded, turning ORDER BY DESC into ORDER BY ASC, and similar problems. Fixed by correctly passing descending flag in SCAN_TABREQ signal sent to data nodes. mysql-test/suite/ndb/r/ndb_partition_key.result@stripped, 2007-12-18 13:40:26+01:00, knielsen@ymer.(none) +17 -0 Test case. mysql-test/suite/ndb/r/ndb_partition_range.result@stripped, 2007-12-18 13:40:26+01:00, knielsen@ymer.(none) +8 -0 Test case. mysql-test/suite/ndb/t/ndb_partition_key.test@stripped, 2007-12-18 13:40:26+01:00, knielsen@ymer.(none) +4 -0 Test case. mysql-test/suite/ndb/t/ndb_partition_range.test@stripped, 2007-12-18 13:40:27+01:00, knielsen@ymer.(none) +5 -0 Test case. storage/ndb/src/ndbapi/NdbScanOperation.cpp@stripped, 2007-12-18 13:40:27+01:00, knielsen@ymer.(none) +27 -15 Even if ordered scan not requested (no need to merge-sorts scans of each partition), we still need to honor the descending flag. diff -Nrup a/mysql-test/suite/ndb/r/ndb_partition_key.result b/mysql-test/suite/ndb/r/ndb_partition_key.result --- a/mysql-test/suite/ndb/r/ndb_partition_key.result 2007-06-27 14:27:31 +02:00 +++ b/mysql-test/suite/ndb/r/ndb_partition_key.result 2007-12-18 13:40:26 +01:00 @@ -38,6 +38,23 @@ a b c 1 10 3 1 11 3 1 12 3 +select max(b) from t1 where a = 1; +max(b) +12 +select b from t1 where a = 1 order by b desc; +b +12 +11 +10 +9 +8 +7 +6 +5 +4 +3 +2 +1 DROP TABLE t1; CREATE TABLE t1 (a INT, b CHAR(10) COLLATE latin1_bin, c INT, d INT, PRIMARY KEY (a,b,c) USING HASH) diff -Nrup a/mysql-test/suite/ndb/r/ndb_partition_range.result b/mysql-test/suite/ndb/r/ndb_partition_range.result --- a/mysql-test/suite/ndb/r/ndb_partition_range.result 2007-06-27 14:27:24 +02:00 +++ b/mysql-test/suite/ndb/r/ndb_partition_range.result 2007-12-18 13:40:26 +01:00 @@ -46,6 +46,14 @@ a b c 1 1 1 6 1 1 10 1 1 +INSERT into t1 values (1, 2, 2); +select max(b) from t1 where a = 1; +max(b) +2 +select b from t1 where a = 1 order by b desc; +b +2 +1 drop table t1; CREATE TABLE t1 ( a int not null, diff -Nrup a/mysql-test/suite/ndb/t/ndb_partition_key.test b/mysql-test/suite/ndb/t/ndb_partition_key.test --- a/mysql-test/suite/ndb/t/ndb_partition_key.test 2007-07-04 22:06:24 +02:00 +++ b/mysql-test/suite/ndb/t/ndb_partition_key.test 2007-12-18 13:40:26 +01:00 @@ -38,6 +38,10 @@ insert into t1 values select * from t1 order by b; +# BUG#33061: ORDER BY DESC becomes ASC in NDB partition pruning to one partition +select max(b) from t1 where a = 1; +select b from t1 where a = 1 order by b desc; + DROP TABLE t1; # diff -Nrup a/mysql-test/suite/ndb/t/ndb_partition_range.test b/mysql-test/suite/ndb/t/ndb_partition_range.test --- a/mysql-test/suite/ndb/t/ndb_partition_range.test 2007-07-04 22:06:24 +02:00 +++ b/mysql-test/suite/ndb/t/ndb_partition_range.test 2007-12-18 13:40:27 +01:00 @@ -48,6 +48,11 @@ select * from t1 where a=21 order by a; select * from t1 where a in (1,6,10,21) order by a; select * from t1 where b=1 and a in (1,6,10,21) order by a; +# BUG#33061: ORDER BY DESC becomes ASC in NDB partition pruning to one partition +INSERT into t1 values (1, 2, 2); +select max(b) from t1 where a = 1; +select b from t1 where a = 1 order by b desc; + drop table t1; # diff -Nrup a/storage/ndb/src/ndbapi/NdbScanOperation.cpp b/storage/ndb/src/ndbapi/NdbScanOperation.cpp --- a/storage/ndb/src/ndbapi/NdbScanOperation.cpp 2007-10-15 09:10:10 +02:00 +++ b/storage/ndb/src/ndbapi/NdbScanOperation.cpp 2007-12-18 13:40:27 +01:00 @@ -1340,29 +1340,41 @@ NdbIndexScanOperation::readTuples(LockMo if(insertATTRINFO(word) == -1) res = -1; } - if(!res && order_by){ - m_ordered = true; + if (!res) + { + /** + * Note that it is valid to have order_desc true and order_by false. + * + * This means that there will be no merge sort among partitions, but + * each partition will still be returned in descending sort order. + * + * This is useful eg. if it is known that the scan spans only one + * partition. + */ if (order_desc) { m_descending = true; ScanTabReq * req = CAST_PTR(ScanTabReq, theSCAN_TABREQ->getDataPtrSend()); ScanTabReq::setDescendingFlag(req->requestInfo, true); } - Uint32 cnt = m_accessTable->getNoOfColumns() - 1; - m_sort_columns = cnt; // -1 for NDB$NODE - m_current_api_receiver = m_sent_receivers_count; - m_api_receivers_count = m_sent_receivers_count; + if (order_by) { + m_ordered = true; + Uint32 cnt = m_accessTable->getNoOfColumns() - 1; + m_sort_columns = cnt; // -1 for NDB$NODE + m_current_api_receiver = m_sent_receivers_count; + m_api_receivers_count = m_sent_receivers_count; - m_sort_columns = cnt; - for(Uint32 i = 0; im_index->m_columns[i]; - const NdbColumnImpl* col = m_currentTable->getColumn(key->m_keyInfoPos); - NdbRecAttr* tmp = NdbScanOperation::getValue_impl(col, (char*)-1); - UintPtr newVal = UintPtr(tmp); - theTupleKeyDefined[i][0] = FAKE_PTR; - theTupleKeyDefined[i][1] = (newVal & 0xFFFFFFFF); + m_sort_columns = cnt; + for(Uint32 i = 0; im_index->m_columns[i]; + const NdbColumnImpl* col = m_currentTable->getColumn(key->m_keyInfoPos); + NdbRecAttr* tmp = NdbScanOperation::getValue_impl(col, (char*)-1); + UintPtr newVal = UintPtr(tmp); + theTupleKeyDefined[i][0] = FAKE_PTR; + theTupleKeyDefined[i][1] = (newVal & 0xFFFFFFFF); #if (SIZEOF_CHARP == 8) - theTupleKeyDefined[i][2] = (newVal >> 32); + theTupleKeyDefined[i][2] = (newVal >> 32); #endif + } } } m_this_bound_start = 0;