Commit cdc302fd authored by knielsen@loke.(none)'s avatar knielsen@loke.(none)

Merge bk-internal:/home/bk/mysql-5.1-new-ndb

into  loke.(none):/home/knielsen/devel/mysql-5.1-new-ndb-bug33061
parents 33721fd4 0ae0c133
...@@ -38,6 +38,23 @@ a b c ...@@ -38,6 +38,23 @@ a b c
1 10 3 1 10 3
1 11 3 1 11 3
1 12 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; DROP TABLE t1;
CREATE TABLE t1 (a INT, b CHAR(10) COLLATE latin1_bin, c INT, d INT, CREATE TABLE t1 (a INT, b CHAR(10) COLLATE latin1_bin, c INT, d INT,
PRIMARY KEY (a,b,c) USING HASH) PRIMARY KEY (a,b,c) USING HASH)
......
...@@ -46,6 +46,14 @@ a b c ...@@ -46,6 +46,14 @@ a b c
1 1 1 1 1 1
6 1 1 6 1 1
10 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; drop table t1;
CREATE TABLE t1 ( CREATE TABLE t1 (
a int not null, a int not null,
......
...@@ -38,6 +38,10 @@ insert into t1 values ...@@ -38,6 +38,10 @@ insert into t1 values
select * from t1 order by b; 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; DROP TABLE t1;
# #
......
...@@ -48,6 +48,11 @@ select * from t1 where a=21 order by a; ...@@ -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 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; 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; drop table t1;
# #
......
...@@ -1340,29 +1340,41 @@ NdbIndexScanOperation::readTuples(LockMode lm, ...@@ -1340,29 +1340,41 @@ NdbIndexScanOperation::readTuples(LockMode lm,
if(insertATTRINFO(word) == -1) if(insertATTRINFO(word) == -1)
res = -1; res = -1;
} }
if(!res && order_by){ if (!res)
m_ordered = true; {
/**
* 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) { if (order_desc) {
m_descending = true; m_descending = true;
ScanTabReq * req = CAST_PTR(ScanTabReq, theSCAN_TABREQ->getDataPtrSend()); ScanTabReq * req = CAST_PTR(ScanTabReq, theSCAN_TABREQ->getDataPtrSend());
ScanTabReq::setDescendingFlag(req->requestInfo, true); ScanTabReq::setDescendingFlag(req->requestInfo, true);
} }
Uint32 cnt = m_accessTable->getNoOfColumns() - 1; if (order_by) {
m_sort_columns = cnt; // -1 for NDB$NODE m_ordered = true;
m_current_api_receiver = m_sent_receivers_count; Uint32 cnt = m_accessTable->getNoOfColumns() - 1;
m_api_receivers_count = m_sent_receivers_count; 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; m_sort_columns = cnt;
for(Uint32 i = 0; i<cnt; i++){ for(Uint32 i = 0; i<cnt; i++){
const NdbColumnImpl* key = m_accessTable->m_index->m_columns[i]; const NdbColumnImpl* key = m_accessTable->m_index->m_columns[i];
const NdbColumnImpl* col = m_currentTable->getColumn(key->m_keyInfoPos); const NdbColumnImpl* col = m_currentTable->getColumn(key->m_keyInfoPos);
NdbRecAttr* tmp = NdbScanOperation::getValue_impl(col, (char*)-1); NdbRecAttr* tmp = NdbScanOperation::getValue_impl(col, (char*)-1);
UintPtr newVal = UintPtr(tmp); UintPtr newVal = UintPtr(tmp);
theTupleKeyDefined[i][0] = FAKE_PTR; theTupleKeyDefined[i][0] = FAKE_PTR;
theTupleKeyDefined[i][1] = (newVal & 0xFFFFFFFF); theTupleKeyDefined[i][1] = (newVal & 0xFFFFFFFF);
#if (SIZEOF_CHARP == 8) #if (SIZEOF_CHARP == 8)
theTupleKeyDefined[i][2] = (newVal >> 32); theTupleKeyDefined[i][2] = (newVal >> 32);
#endif #endif
}
} }
} }
m_this_bound_start = 0; m_this_bound_start = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment