diff options
author | unknown <knielsen@ymer.(none)> | 2007-12-18 13:40:35 +0100 |
---|---|---|
committer | unknown <knielsen@ymer.(none)> | 2007-12-18 13:40:35 +0100 |
commit | c7dc182db9e7295224f6ca9b0238969962d78375 (patch) | |
tree | 0606f3bcc34143047ea5f432572fbf924b2de6a3 /storage/ndb | |
parent | ff1474765c0dbe2ad2d1574f2550eb43ad88e304 (diff) | |
download | mariadb-git-c7dc182db9e7295224f6ca9b0238969962d78375.tar.gz |
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:
Test case.
mysql-test/suite/ndb/r/ndb_partition_range.result:
Test case.
mysql-test/suite/ndb/t/ndb_partition_key.test:
Test case.
mysql-test/suite/ndb/t/ndb_partition_range.test:
Test case.
storage/ndb/src/ndbapi/NdbScanOperation.cpp:
Even if ordered scan not requested (no need to merge-sorts scans of
each partition), we still need to honor the descending flag.
Diffstat (limited to 'storage/ndb')
-rw-r--r-- | storage/ndb/src/ndbapi/NdbScanOperation.cpp | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/storage/ndb/src/ndbapi/NdbScanOperation.cpp b/storage/ndb/src/ndbapi/NdbScanOperation.cpp index afbec070ac8..96a3ce4332e 100644 --- a/storage/ndb/src/ndbapi/NdbScanOperation.cpp +++ b/storage/ndb/src/ndbapi/NdbScanOperation.cpp @@ -1340,29 +1340,41 @@ NdbIndexScanOperation::readTuples(LockMode lm, 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; i<cnt; i++){ - const NdbColumnImpl* key = m_accessTable->m_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; i<cnt; i++){ + const NdbColumnImpl* key = m_accessTable->m_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; |