List:Commits« Previous MessageNext Message »
From:jonas oreland Date:August 16 2011 10:00am
Subject:bzr push into mysql-5.1-telco-7.1 branch (jonas.oreland:4253 to 4255)
View as plain text  
 4255 jonas oreland	2011-08-16 [merge]
      ndb - merge 70 to 71

    modified:
      storage/ndb/src/kernel/vm/ndbd_malloc_impl.cpp
      storage/ndb/src/kernel/vm/ndbd_malloc_impl.hpp
      storage/ndb/src/ndbapi/NdbQueryOperation.cpp
      storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp
 4254 jonas oreland	2011-08-16 [merge]
      ndb - merge 7.1.15-a into 7.1

    modified:
      storage/ndb/src/kernel/blocks/dbtux/DbtuxNode.cpp
 4253 Craig L Russell	2011-08-02
      Support OpenJPA 1.2.0 and 2.1.0

    modified:
      storage/ndb/clusterj/clusterj-openjpa/src/main/java/com/mysql/clusterj/openjpa/NdbOpenJPABrokerFactory.java
      storage/ndb/clusterj/clusterj-openjpa/src/main/java/com/mysql/clusterj/openjpa/NdbOpenJPAConfigurationImpl.java
      storage/ndb/clusterj/clusterj-openjpa/src/main/java/com/mysql/clusterj/openjpa/NdbOpenJPADomainFieldHandlerImpl.java
      storage/ndb/clusterj/clusterj-openjpa/src/main/java/com/mysql/clusterj/openjpa/NdbOpenJPADomainTypeHandlerImpl.java
      storage/ndb/clusterj/clusterj-openjpa/src/main/java/com/mysql/clusterj/openjpa/NdbOpenJPAStoreManager.java
=== modified file 'storage/ndb/src/kernel/blocks/dbtux/DbtuxNode.cpp'
--- a/storage/ndb/src/kernel/blocks/dbtux/DbtuxNode.cpp	2011-06-30 15:59:25 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtux/DbtuxNode.cpp	2011-08-16 09:59:55 +0000
@@ -155,19 +155,26 @@ Dbtux::setNodePref(TuxCtx & ctx, NodeHan
 {
   const Frag& frag = node.m_frag;
   const Index& index = *c_indexPool.getPtr(frag.m_indexId);
-  KeyData prefKey(index.m_keySpec, false, 0);
-  prefKey.set_buf(node.getPref(), index.m_prefBytes);
+  /*
+   * bug#12873640
+   * Node prefix exists if it has non-zero number of attributes.  It is
+   * then a partial instance of KeyData.  If the prefix does not exist
+   * then set_buf() could overwrite m_pageId1 in first entry, causing
+   * random crash in TUP via readKeyAttrs().
+   */
   if (index.m_prefAttrs > 0) {
+    KeyData prefKey(index.m_keySpec, false, 0);
+    prefKey.set_buf(node.getPref(), index.m_prefBytes);
     jam();
     readKeyAttrs(ctx, frag, node.getEnt(0), prefKey, index.m_prefAttrs);
-  }
 #ifdef VM_TRACE
-  if (debugFlags & DebugMaint) {
-    debugOut << "setNodePref: " << node;
-    debugOut << " " << prefKey.print(ctx.c_debugBuffer, DebugBufferBytes);
-    debugOut << endl;
-  }
+    if (debugFlags & DebugMaint) {
+      debugOut << "setNodePref: " << node;
+      debugOut << " " << prefKey.print(ctx.c_debugBuffer, DebugBufferBytes);
+      debugOut << endl;
+    }
 #endif
+  }
 }
 
 // node operations

=== modified file 'storage/ndb/src/kernel/vm/ndbd_malloc_impl.cpp'
--- a/storage/ndb/src/kernel/vm/ndbd_malloc_impl.cpp	2011-02-01 23:27:25 +0000
+++ b/storage/ndb/src/kernel/vm/ndbd_malloc_impl.cpp	2011-08-16 08:27:14 +0000
@@ -39,6 +39,16 @@ static const char * f_method = "MSms";
 #endif
 #define MAX_CHUNKS 10
 
+#ifdef VM_TRACE
+#ifndef NDBD_RANDOM_START_PAGE
+#define NDBD_RANDOM_START_PAGE
+#endif
+#endif
+
+#ifdef NDBD_RANDOM_START_PAGE
+static Uint32 g_random_start_page_id = 0;
+#endif
+
 /*
  * For muti-threaded ndbd, these calls are used for locking around
  * memory allocation operations.
@@ -224,6 +234,16 @@ Ndbd_mem_manager::Ndbd_mem_manager()
   mt_mem_manager_init();
 }
 
+void*
+Ndbd_mem_manager::get_memroot() const
+{
+#ifdef NDBD_RANDOM_START_PAGE
+  return (void*)(m_base_page - g_random_start_page_id);
+#else
+  return (void*)m_base_page;
+#endif
+}
+
 /**
  *
  * resource 0 has following semantics:
@@ -359,6 +379,29 @@ Ndbd_mem_manager::init(Uint32 *watchCoun
   }
 #endif
 
+#ifdef NDBD_RANDOM_START_PAGE
+  /**
+   * In order to find bad-users of page-id's
+   *   we add a random offset to the page-id's returned
+   *   however, due to ZONE_LO that offset can't be that big
+   *   (since we at get_page don't know if it's a HI/LO page)
+   */
+  Uint32 max_rand_start = ZONE_LO_BOUND - 1;
+  if (max_rand_start > pages)
+  {
+    max_rand_start -= pages;
+    if (max_rand_start > 0x10000)
+      g_random_start_page_id = 0x10000 + (rand() % (max_rand_start - 0x10000));
+    else if (max_rand_start)
+      g_random_start_page_id = rand() % max_rand_start;
+
+    assert(Uint64(pages) + Uint64(g_random_start_page_id) <= 0xFFFFFFFF);
+
+    ndbout_c("using g_random_start_page_id: %u (%.8x)",
+             g_random_start_page_id, g_random_start_page_id);
+  }
+#endif
+
   /**
    * Do malloc
    */
@@ -670,7 +713,7 @@ Ndbd_mem_manager::alloc(AllocZone zone,
       return;
     * pages = save;
   }
-  
+
   alloc_impl(ZONE_LO, ret, pages, min);
 }
 
@@ -870,7 +913,12 @@ Ndbd_mem_manager::alloc_page(Uint32 type
 
       check_resource_limits(m_resource_limit);
       mt_mem_manager_unlock();
+#ifdef NDBD_RANDOM_START_PAGE
+      *i += g_random_start_page_id;
+      return m_base_page + *i - g_random_start_page_id;
+#else
       return m_base_page + *i;
+#endif
     }
   }
   mt_mem_manager_unlock();
@@ -885,7 +933,11 @@ Ndbd_mem_manager::release_page(Uint32 ty
   mt_mem_manager_lock();
   Resource_limit tot = m_resource_limit[0];
   Resource_limit rl = m_resource_limit[idx];
-  
+
+#ifdef NDBD_RANDOM_START_PAGE
+  i -= g_random_start_page_id;
+#endif
+
   Uint32 sub = (rl.m_curr <= rl.m_min) ? 1 : 0; // Over min ?
   release(i, 1);
   m_resource_limit[0].m_curr = tot.m_curr - 1;
@@ -954,10 +1006,16 @@ Ndbd_mem_manager::alloc_pages(Uint32 typ
     m_resource_limit[idx].m_curr = rl.m_curr + req;
     check_resource_limits(m_resource_limit);
     mt_mem_manager_unlock();
+#ifdef NDBD_RANDOM_START_PAGE
+    *i += g_random_start_page_id;
+#endif
     return ;
   }
   mt_mem_manager_unlock();
   * cnt = req;
+#ifdef NDBD_RANDOM_START_PAGE
+  *i += g_random_start_page_id;
+#endif
   return;
 }
 
@@ -969,7 +1027,11 @@ Ndbd_mem_manager::release_pages(Uint32 t
   mt_mem_manager_lock();
   Resource_limit tot = m_resource_limit[0];
   Resource_limit rl = m_resource_limit[idx];
-  
+
+#ifdef NDBD_RANDOM_START_PAGE
+  i -= g_random_start_page_id;
+#endif
+
   release(i, cnt);
 
   Uint32 currnew = rl.m_curr - cnt;

=== modified file 'storage/ndb/src/kernel/vm/ndbd_malloc_impl.hpp'
--- a/storage/ndb/src/kernel/vm/ndbd_malloc_impl.hpp	2011-06-30 15:59:25 +0000
+++ b/storage/ndb/src/kernel/vm/ndbd_malloc_impl.hpp	2011-08-16 08:27:14 +0000
@@ -68,7 +68,7 @@ public:
 
   bool init(Uint32 *watchCounter, bool allow_alloc_less_than_requested = true);
   void map(Uint32 * watchCounter, bool memlock = false, Uint32 resources[] = 0);
-  void* get_memroot() const { return (void*)m_base_page;}
+  void* get_memroot() const;
   
   void dump() const ;
   

=== modified file 'storage/ndb/src/ndbapi/NdbQueryOperation.cpp'
--- a/storage/ndb/src/ndbapi/NdbQueryOperation.cpp	2011-07-01 10:02:15 +0000
+++ b/storage/ndb/src/ndbapi/NdbQueryOperation.cpp	2011-08-16 08:04:43 +0000
@@ -148,6 +148,8 @@ public:
 
   explicit NdbRootFragment();
 
+  ~NdbRootFragment();
+
   /**
    * Initialize object.
    * @param query Enclosing query.
@@ -198,9 +200,14 @@ public:
    * @param operationNo The id of the operation.
    * @return The result stream for this root fragment.
    */
-  NdbResultStream& getResultStream(Uint32 operationNo) const
-  { return m_query->getQueryOperation(operationNo).getResultStream(m_fragNo); }
-  
+  NdbResultStream& getResultStream(Uint32 operationNo) const;
+
+  NdbResultStream& getResultStream(const NdbQueryOperationImpl& op) const
+  { return getResultStream(op.getQueryOperationDef().getQueryOperationIx()); }
+
+  Uint32 getReceiverId() const;
+  Uint32 getReceiverTcPtrI() const;
+
   /**
    * @return True if there are no more batches to be received for this fragment.
    */
@@ -212,6 +219,9 @@ public:
    */
   bool isEmpty() const;
 
+  /** Release resources after last row has been returned */
+  void postFetchRelease();
+
 private:
   STATIC_CONST( voidFragNo = 0xffffffff);
 
@@ -221,6 +231,9 @@ private:
   /** Number of the root operation fragment.*/
   Uint32 m_fragNo;
 
+  /** For processing results originating from this root fragment (Array of).*/
+  NdbResultStream* m_resultStreams;
+
   /**
    * The number of outstanding TCKEYREF or TRANSID_AI 
    * messages for the fragment. This includes both messages related to the
@@ -272,26 +285,19 @@ public:
    * @param operation The operation for which we will receive results.
    * @param rootFragNo 0..n-1 when the root operation reads from n fragments.
    */
-  explicit NdbResultStream(NdbQueryOperationImpl& operation, Uint32 rootFragNo);
+  explicit NdbResultStream(NdbQueryOperationImpl& operation,
+                           NdbRootFragment& rootFrag);
 
   ~NdbResultStream();
 
   /** 
    * Prepare for receiving first results. 
-   * @return possible error code. 
    */
-  int prepare();
+  void prepare();
 
   /** Prepare for receiving next batch of scan results. */
   void reset();
     
-  /**
-   * 0..n-1 if the root operation reads from n fragments. This stream holds data
-   * derived from one of those fragments.
-   */
-  Uint32 getRootFragNo() const
-  { return m_rootFragNo; }
-
   NdbReceiver& getReceiver()
   { return m_receiver; }
 
@@ -341,7 +347,7 @@ public:
   void setSubScanCompletion(bool complete)
   { 
     // Lookups should always be 'complete'
-    assert(complete || m_operation.getQueryOperationDef().isScanOperation());
+    assert(complete || isScanResult());
     m_subScanComplete = complete; 
   }
 
@@ -354,7 +360,7 @@ public:
   bool isSubScanComplete() const
   { 
     // Lookups should always be 'complete'
-    assert(m_subScanComplete || m_operation.getQueryOperationDef().isScanOperation());
+    assert(m_subScanComplete || isScanResult());
     return m_subScanComplete; 
   }
 
@@ -364,6 +370,15 @@ public:
    */
   bool isAllSubScansComplete() const;
 
+  bool isScanQuery() const
+  { return (m_properties & Is_Scan_Query); }
+
+  bool isScanResult() const
+  { return (m_properties & Is_Scan_Result); }
+
+  bool isInnerJoin() const
+  { return (m_properties & Is_Inner_Join); }
+
   /** For debugging.*/
   friend NdbOut& operator<<(NdbOut& out, const NdbResultStream&);
 
@@ -415,22 +430,34 @@ public:
   };
 
 private:
-  /** This stream handles results derived from the m_rootFragNo'th 
-   * fragment of the root operation.*/
-  const Uint32 m_rootFragNo;
+  /**
+   * This stream handles results derived from specified 
+   * m_rootFrag of the root operation.
+   */
+  const NdbRootFragment& m_rootFrag;
+ 
+  /** Operation to which this resultStream belong.*/
+  NdbQueryOperationImpl& m_operation;
+
+  /** ResultStream for my parent operation, or NULL if I am root */
+  NdbResultStream* const m_parent;
+
+  const enum properties
+  {
+    Is_Scan_Query = 0x01,
+    Is_Scan_Result = 0x02,
+    Is_Inner_Join = 0x10
+  } m_properties;
 
   /** The receiver object that unpacks transid_AI messages.*/
   NdbReceiver m_receiver;
 
-  /** Max #rows which this stream may recieve in its buffer structures */
-  Uint32 m_maxRows;
+  /** Used for checking if buffer overrun occurred. */
+  Uint32* m_batchOverflowCheck;
 
   /** The number of transid_AI messages received.*/
   Uint32 m_rowCount;
 
-  /** Operation to which this resultStream belong.*/
-  NdbQueryOperationImpl& m_operation;
-
   /** This is the state of the iterator used by firstResult(), nextResult().*/
   enum
   {
@@ -442,7 +469,10 @@ private:
     Iter_finished
   } m_iterState;
 
-  /** Tuple id of the current tuple, or 'tupleNotFound' if Iter_notStarted or Iter_finished. */
+  /**
+   * Tuple id of the current tuple, or 'tupleNotFound'
+   * if Iter_notStarted or Iter_finished. 
+   */
   Uint16 m_currentRow;
   
   /** 
@@ -453,6 +483,10 @@ private:
    */
   bool m_subScanComplete;
 
+  /** Max #rows which this stream may recieve in its TupleSet structures */
+  Uint32 m_maxRows;
+
+  /** TupleSet contains the correlation between parent/childs */
   TupleSet* m_tupleSet;
 
   void clearTupleSet();
@@ -525,15 +559,29 @@ void* NdbBulkAllocator::allocObjMem(Uint
 /////////  NdbResultStream methods ///////////
 //////////////////////////////////////////////
 
-NdbResultStream::NdbResultStream(NdbQueryOperationImpl& operation, Uint32 rootFragNo):
-  m_rootFragNo(rootFragNo),
+NdbResultStream::NdbResultStream(NdbQueryOperationImpl& operation,
+                                 NdbRootFragment& rootFrag)
+:
+  m_rootFrag(rootFrag),
+  m_operation(operation),
+  m_parent(operation.getParentOperation()
+        ? &rootFrag.getResultStream(*operation.getParentOperation())
+        : NULL),
+  m_properties(
+    (enum properties)
+     ((operation.getQueryDef().isScanQuery()
+       ? Is_Scan_Query : 0)
+     | (operation.getQueryOperationDef().isScanOperation()
+       ? Is_Scan_Result : 0)
+     | (operation.getQueryOperationDef().getMatchType() != NdbQueryOptions::MatchAll
+       ? Is_Inner_Join : 0))),
   m_receiver(operation.getQuery().getNdbTransaction().getNdb()),
-  m_maxRows(0),
+  m_batchOverflowCheck(NULL),
   m_rowCount(0),
-  m_operation(operation),
   m_iterState(Iter_notStarted),
   m_currentRow(tupleNotFound),
   m_subScanComplete(true),
+  m_maxRows(0),
   m_tupleSet(NULL)
 {};
 
@@ -545,19 +593,22 @@ NdbResultStream::~NdbResultStream()
   }
 }
 
-int  // Return 0 if ok, else errorcode
+void
 NdbResultStream::prepare()
 {
+  const Uint32 rowSize = m_operation.getRowSize();
+  NdbQueryImpl &query = m_operation.getQuery();
+
   /* Parent / child correlation is only relevant for scan type queries
    * Don't create m_parentTupleId[] and m_childTupleIdx[] for lookups!
    * Neither is these structures required for operations not having respective
    * child or parent operations.
    */
-  if (m_operation.getQueryDef().isScanQuery())
+  if (isScanQuery())
   {
     m_maxRows  = m_operation.getMaxBatchRows();
     m_tupleSet = 
-      new (m_operation.getQuery().getTupleSetAlloc().allocObjMem(m_maxRows)) 
+      new (query.getTupleSetAlloc().allocObjMem(m_maxRows)) 
       TupleSet[m_maxRows];
 
     clearTupleSet();
@@ -565,14 +616,30 @@ NdbResultStream::prepare()
   else
     m_maxRows = 1;
 
-  return 0;
-} //NdbResultStream::prepare
+  const int bufferSize = rowSize * m_maxRows;
+  NdbBulkAllocator& bufferAlloc = query.getRowBufferAlloc();
+  char* const rowBuf = reinterpret_cast<char*>(bufferAlloc
+                                               .allocObjMem(bufferSize));
 
+  // So that we can test for buffer overrun.
+  m_batchOverflowCheck = 
+    reinterpret_cast<Uint32*>(bufferAlloc.allocObjMem(sizeof(Uint32)));
+  *m_batchOverflowCheck = 0xacbd1234;
+
+  m_receiver.init(NdbReceiver::NDB_QUERY_OPERATION, false, &m_operation);
+  m_receiver.do_setup_ndbrecord(
+                          m_operation.getNdbRecord(),
+                          m_maxRows, 
+                          0 /*key_size*/, 
+                          0 /*read_range_no*/, 
+                          rowSize,
+                          rowBuf);
+} //NdbResultStream::prepare
 
 void
 NdbResultStream::reset()
 {
-  assert (m_operation.getQueryDef().isScanQuery());
+  assert (isScanQuery());
 
   // Root scan-operation need a ScanTabConf to complete
   m_rowCount = 0;
@@ -589,14 +656,14 @@ NdbResultStream::reset()
        childNo++)
   {
     NdbQueryOperationImpl& child = m_operation.getChildOperation(childNo);
-    child.getResultStream(getRootFragNo()).reset();
+    m_rootFrag.getResultStream(child).reset();
   }
 } //NdbResultStream::reset
 
 void
 NdbResultStream::clearTupleSet()
 {
-  assert (m_operation.getQueryDef().isScanQuery());
+  assert (isScanQuery());
   for (Uint32 i=0; i<m_maxRows; i++)
   {
     m_tupleSet[i].m_parentId = tupleNotFound;
@@ -611,7 +678,7 @@ bool
 NdbResultStream::isAllSubScansComplete() const
 { 
   // Lookups should always be 'complete'
-  assert(m_subScanComplete || m_operation.getQueryOperationDef().isScanOperation());
+  assert(m_subScanComplete || isScanResult());
 
   if (!m_subScanComplete)
     return false;
@@ -620,7 +687,7 @@ NdbResultStream::isAllSubScansComplete()
        childNo++)
   {
     const NdbQueryOperationImpl& child = m_operation.getChildOperation(childNo);
-    const NdbResultStream& childStream = child.getResultStream(getRootFragNo());
+    const NdbResultStream& childStream = m_rootFrag.getResultStream(child);
     if (!childStream.isAllSubScansComplete())
       return false;
   }
@@ -633,7 +700,7 @@ NdbResultStream::setParentChildMap(Uint1
                                    Uint16 tupleId, 
                                    Uint16 tupleNo)
 {
-  assert (m_operation.getQueryDef().isScanQuery());
+  assert (isScanQuery());
   assert (tupleNo < m_maxRows);
   assert (tupleId != tupleNotFound);
 
@@ -652,7 +719,7 @@ NdbResultStream::setParentChildMap(Uint1
      * possible to use ::findTupleWithParentId() and ::findNextTuple()
      * to navigate even the root operation.
      */
-    assert (m_operation.getParentOperation()==NULL);
+    assert (m_parent==NULL);
     /* Link into m_hash_next in order to let ::findNextTuple() navigate correctly */
     if (tupleNo==0)
       m_tupleSet[hash].m_hash_head  = 0;
@@ -678,7 +745,7 @@ NdbResultStream::setParentChildMap(Uint1
 Uint16
 NdbResultStream::findTupleWithParentId(Uint16 parentId) const
 {
-  assert ((parentId==tupleNotFound) == (m_operation.getParentOperation()==NULL));
+  assert ((parentId==tupleNotFound) == (m_parent==NULL));
 
   if (likely(m_rowCount>0))
   {
@@ -736,14 +803,10 @@ NdbResultStream::findNextTuple(Uint16 tu
 Uint16
 NdbResultStream::firstResult()
 {
-  NdbQueryOperationImpl* parent = m_operation.getParentOperation();
-
   Uint16 parentId = tupleNotFound;
-  if (parent!=NULL)
+  if (m_parent!=NULL)
   {
-    const NdbResultStream& parentStream = parent->getResultStream(m_rootFragNo);
-    parentId = parentStream.getCurrentTupleId();
-
+    parentId = m_parent->getCurrentTupleId();
     if (parentId == tupleNotFound)
     {
       m_currentRow = tupleNotFound;
@@ -784,12 +847,12 @@ void
 NdbResultStream::execTRANSID_AI(const Uint32 *ptr, Uint32 len)
 {
   assert(m_iterState == Iter_notStarted);
-  if (m_operation.getQueryDef().isScanQuery())
+  if (isScanQuery())
   {
     const CorrelationData correlData(ptr, len);
 
-    assert(m_operation.getRoot().getResultStream(m_rootFragNo)
-           .m_receiver.getId() == correlData.getRootReceiverId());
+    assert(m_rootFrag.getResultStream(0).m_receiver.getId() ==
+           correlData.getRootReceiverId());
 
     m_receiver.execTRANSID_AI(ptr, len - CorrelationData::wordCount);
 
@@ -799,7 +862,7 @@ NdbResultStream::execTRANSID_AI(const Ui
      * parent and child until all tuples (for this batch and 
      * root fragment) have arrived.
      */
-    setParentChildMap(m_operation.getParentOperation()==NULL
+    setParentChildMap(m_parent==NULL
                       ? tupleNotFound
                       : correlData.getParentTupleId(),
                       correlData.getTupleId(),
@@ -826,6 +889,9 @@ NdbResultStream::execTRANSID_AI(const Ui
 void 
 NdbResultStream::handleBatchComplete()
 {
+  // Buffer overrun check.
+  assert(m_batchOverflowCheck==NULL || *m_batchOverflowCheck==0xacbd1234);
+
   for (Uint32 tupleNo=0; tupleNo<getRowCount(); tupleNo++)
   {
     m_tupleSet[tupleNo].m_skip = false;
@@ -834,10 +900,10 @@ NdbResultStream::handleBatchComplete()
   for (Uint32 childNo=0; childNo < m_operation.getNoOfChildOperations(); childNo++)
   {
     const NdbQueryOperationImpl& child = m_operation.getChildOperation(childNo);
-    NdbResultStream& childStream = child.getResultStream(m_rootFragNo);
+    NdbResultStream& childStream = m_rootFrag.getResultStream(child);
     childStream.handleBatchComplete();
 
-    const bool isInnerJoin = child.getQueryOperationDef().getMatchType() != NdbQueryOptions::MatchAll;
+    const bool isInnerJoin = childStream.isInnerJoin();
     const bool allSubScansComplete = childStream.isAllSubScansComplete();
 
     for (Uint32 tupleNo=0; tupleNo<getRowCount(); tupleNo++)
@@ -876,8 +942,7 @@ void NdbRootFragment::buildReciverIdMap(
 {
   for(Uint32 fragNo = 0; fragNo < noOfFrags; fragNo++)
   {
-    const Uint32 receiverId = 
-      frags[fragNo].getResultStream(0).getReceiver().getId();
+    const Uint32 receiverId = frags[fragNo].getReceiverId();
     /** 
      * For reasons unknow, NdbObjectIdMap shifts ids two bits to the left,
      * so we must do the opposite to get a good hash distribution.
@@ -890,6 +955,7 @@ void NdbRootFragment::buildReciverIdMap(
   } 
 }
 
+//static
 NdbRootFragment* 
 NdbRootFragment::receiverIdLookup(NdbRootFragment* frags, 
                                   Uint32 noOfFrags, 
@@ -903,9 +969,7 @@ NdbRootFragment::receiverIdLookup(NdbRoo
   const int hash = (receiverId >> 2) % noOfFrags;
   int current = frags[hash].m_idMapHead;
   assert(current < static_cast<int>(noOfFrags));
-  while (current >= 0 && 
-         frags[current].getResultStream(0).getReceiver().getId() 
-         != receiverId)
+  while (current >= 0 && frags[current].getReceiverId() != receiverId)
   {
     current = frags[current].m_idMapNext;
     assert(current < static_cast<int>(noOfFrags));
@@ -924,6 +988,7 @@ NdbRootFragment::receiverIdLookup(NdbRoo
 NdbRootFragment::NdbRootFragment():
   m_query(NULL),
   m_fragNo(voidFragNo),
+  m_resultStreams(NULL),
   m_outstandingResults(0),
   m_confReceived(false),
   m_idMapHead(-1),
@@ -931,11 +996,56 @@ NdbRootFragment::NdbRootFragment():
 {
 }
 
+NdbRootFragment::~NdbRootFragment()
+{
+  assert(m_resultStreams==NULL);
+}
+
 void NdbRootFragment::init(NdbQueryImpl& query, Uint32 fragNo)
 {
   assert(m_fragNo==voidFragNo);
   m_query = &query;
   m_fragNo = fragNo;
+
+  m_resultStreams = reinterpret_cast<NdbResultStream*>
+     (query.getResultStreamAlloc().allocObjMem(query.getNoOfOperations()));
+  assert(m_resultStreams!=NULL);
+
+  for (unsigned opNo=0; opNo<query.getNoOfOperations(); opNo++) 
+  {
+    NdbQueryOperationImpl& op = query.getQueryOperation(opNo);
+    new (&m_resultStreams[opNo]) NdbResultStream(op,*this);
+    m_resultStreams[opNo].prepare();
+  }
+}
+
+/**
+ * Release what we want need anymore after last available row has been 
+ * returned from datanodes.
+ */ 
+void
+NdbRootFragment::postFetchRelease()
+{
+  if (m_resultStreams != NULL)
+  { 
+    for (unsigned opNo=0; opNo<m_query->getNoOfOperations(); opNo++) 
+    {
+      m_resultStreams[opNo].~NdbResultStream();
+    }
+  }
+  /**
+   * Don't 'delete' the object as it was in-place constructed from
+   * ResultStreamAlloc'ed memory. Memory is released by
+   * ResultStreamAlloc::reset().
+   */
+  m_resultStreams = NULL;
+}
+
+NdbResultStream&
+NdbRootFragment::getResultStream(Uint32 operationNo) const
+{
+  assert(m_resultStreams);
+  return m_resultStreams[operationNo];
 }
 
 void NdbRootFragment::reset()
@@ -958,14 +1068,31 @@ void NdbRootFragment::setConfReceived()
 
 bool NdbRootFragment::finalBatchReceived() const
 {
-  return getResultStream(0).getReceiver().m_tcPtrI==RNIL;
+  return getReceiverTcPtrI()==RNIL;
 }
 
-bool  NdbRootFragment::isEmpty() const
+bool NdbRootFragment::isEmpty() const
 { 
   return getResultStream(0).isEmpty();
 }
 
+/**
+ * SPJ requests are identified by the receiver-id of the
+ * *root* ResultStream for each RootFragment. Furthermore
+ * a NEXTREQ use the tcPtrI saved in this ResultStream to
+ * identify the 'cursor' to restart.
+ *
+ * We provide some convenient accessors for fetching this info 
+ */
+Uint32 NdbRootFragment::getReceiverId() const
+{
+  return getResultStream(0).getReceiver().getId();
+}
+
+Uint32 NdbRootFragment::getReceiverTcPtrI() const
+{
+  return getResultStream(0).getReceiver().m_tcPtrI;
+}
 
 ///////////////////////////////////////////
 /////////  NdbQuery API methods ///////////
@@ -1475,7 +1602,14 @@ NdbQueryImpl::~NdbQueryImpl()
 void
 NdbQueryImpl::postFetchRelease()
 {
-  if (m_operations != NULL) {
+  if (m_rootFrags != NULL)
+  {
+    for (unsigned i=0; i<m_rootFragCount; i++)
+    { m_rootFrags[i].postFetchRelease();
+    }
+  }
+  if (m_operations != NULL)
+  {
     for (unsigned i=0; i<m_countOperations; i++)
     { m_operations[i].postFetchRelease();
     }
@@ -2070,10 +2204,11 @@ NdbQueryImpl::awaitMoreResults(bool forc
   returns: 'true' when application thread should be resumed.
 */
 bool 
-NdbQueryImpl::handleBatchComplete(Uint32 fragNo)
+NdbQueryImpl::handleBatchComplete(NdbRootFragment& rootFrag)
 {
   if (traceSignals) {
-    ndbout << "NdbQueryImpl::handleBatchComplete, fragNo=" << fragNo
+    ndbout << "NdbQueryImpl::handleBatchComplete"
+           << ", fragNo=" << rootFrag.getFragNo()
            << ", pendingFrags=" << (m_pendingFrags-1)
            << ", finalBatchFrags=" << m_finalBatchFrags
            <<  endl;
@@ -2087,7 +2222,6 @@ NdbQueryImpl::handleBatchComplete(Uint32
   if (likely(m_fullFrags.m_errorCode == 0))
   {
     NdbQueryOperationImpl& root = getRoot();
-    NdbRootFragment& rootFrag = m_rootFrags[fragNo];
     assert(rootFrag.isFragBatchComplete());
 
     assert(m_pendingFrags > 0);                // Check against underflow.
@@ -2103,7 +2237,7 @@ NdbQueryImpl::handleBatchComplete(Uint32
     if (getQueryDef().isScanQuery())
     {
       // Only required for scans
-      root.getResultStream(fragNo).handleBatchComplete();  
+      rootFrag.getResultStream(root).handleBatchComplete();  
 
       // Only ordered scans has to wait until all pending completed
       resume = (m_pendingFrags==0) ||
@@ -2111,7 +2245,7 @@ NdbQueryImpl::handleBatchComplete(Uint32
     }
     else
     {
-      assert(root.m_resultStreams[fragNo]->getReceiver().m_tcPtrI==RNIL);
+      assert(rootFrag.getResultStream(root).getReceiver().m_tcPtrI==RNIL);
       assert(m_finalBatchFrags==1);
       assert(m_pendingFrags==0);  // Lookup query should be complete now.
       resume = true;   
@@ -2119,7 +2253,7 @@ NdbQueryImpl::handleBatchComplete(Uint32
 
     /* Position at the first (sorted?) row available from this fragments.
      */
-    root.m_resultStreams[fragNo]->firstResult();
+    rootFrag.getResultStream(root).firstResult();
 
     /* When application thread ::awaitMoreResults() it will later be moved
      * from m_fullFrags to m_applFrags under mutex protection.
@@ -2272,22 +2406,22 @@ NdbQueryImpl::execTCKEYCONF()
     ndbout << "NdbQueryImpl::execTCKEYCONF()" << endl;
   }
   assert(!getQueryDef().isScanQuery());
+  NdbRootFragment& rootFrag = m_rootFrags[0];
 
   // We will get 1 + #leaf-nodes TCKEYCONF for a lookup...
-  m_rootFrags[0].setConfReceived();
-  m_rootFrags[0].incrOutstandingResults(-1);
+  rootFrag.setConfReceived();
+  rootFrag.incrOutstandingResults(-1);
 
   bool ret = false;
-  if (m_rootFrags[0].isFragBatchComplete())
+  if (rootFrag.isFragBatchComplete())
   { 
-    ret = handleBatchComplete(0);
+    ret = handleBatchComplete(rootFrag);
   }
 
   if (traceSignals) {
     ndbout << "NdbQueryImpl::execTCKEYCONF(): returns:" << ret
            << ", m_pendingFrags=" << m_pendingFrags
-           << ", *getRoot().m_resultStreams[0]=" 
-           << *getRoot().m_resultStreams[0]
+           << ", rootStream= {" << rootFrag.getResultStream(0) << "}"
            << endl;
   }
   return ret;
@@ -2364,9 +2498,7 @@ NdbQueryImpl::prepareSend()
   // Allocate space for ptrs to NdbResultStream and NdbRootFragment objects.
   error = m_pointerAlloc.init(m_rootFragCount * 
                               (SharedFragStack::pointersPerFragment +
-                               OrderedFragSet::pointersPerFragment +
-                               // Pointers to NdbResultStream objects.
-                               getNoOfOperations()));
+                               OrderedFragSet::pointersPerFragment));
   if (error != 0)
   {
     setErrorCode(error);
@@ -2377,21 +2509,22 @@ NdbQueryImpl::prepareSend()
   getRoot().calculateBatchedRows(NULL);
   getRoot().setBatchedRows(1);
 
-  /** Calculate total amount of row buffer space for all operations and
-   * fragments.*/
+  /**
+   * Calculate total amount of row buffer space for all operations and
+   * fragments.
+   */
   Uint32 totalBuffSize = 0;
   for (Uint32 opNo = 0; opNo < getNoOfOperations(); opNo++)
   {
-    NdbQueryOperationImpl& op = getQueryOperation(opNo);
-
-    op.m_bufferSize = op.getRowSize() * op.getMaxBatchRows();
-    totalBuffSize += op.m_bufferSize;
+    const NdbQueryOperationImpl& op = getQueryOperation(opNo);
+    totalBuffSize += (op.getRowSize() * op.getMaxBatchRows());
   }
-  /** Add one word per operation for buffer overrun check. We add a word
+  /**
+   * Add one word per ResultStream for buffer overrun check. We add a word
    * rather than a byte to avoid possible alignment problems.
    */
-  m_rowBufferAlloc.init(totalBuffSize * m_rootFragCount + 
-                        sizeof(Uint32) * getNoOfOperations());
+  m_rowBufferAlloc.init(m_rootFragCount * 
+                       (totalBuffSize + (sizeof(Uint32) * getNoOfOperations())) );
   if (getQueryDef().isScanQuery())
   {
     Uint32 totalRows = 0;
@@ -2406,15 +2539,28 @@ NdbQueryImpl::prepareSend()
       return -1;
     }
   }
-  // 1. Build receiver structures for each QueryOperation.
-  // 2. Fill in parameters (into ATTRINFO) for QueryTree.
-  //    (Has to complete *after* ::prepareReceiver() as QueryTree params
-  //     refer receiver id's.)
-  //
+
+  /**
+   * Allocate and initialize fragment state variables.
+   * Will also cause a ResultStream object containing a 
+   * NdbReceiver to be constructed for each operation in QueryTree
+   */
+  m_rootFrags = new NdbRootFragment[m_rootFragCount];
+  if (m_rootFrags == NULL)
+  {
+    setErrorCode(Err_MemoryAlloc);
+    return -1;
+  }
+  for (Uint32 i = 0; i<m_rootFragCount; i++)
+  {
+    m_rootFrags[i].init(*this, i); // Set fragment number.
+  }
+
+  // Fill in parameters (into ATTRINFO) for QueryTree.
   for (Uint32 i = 0; i < m_countOperations; i++) {
-    int error;
-    if (unlikely((error = m_operations[i].prepareReceiver()) != 0)
-              || (error = m_operations[i].prepareAttrInfo(m_attrInfo)) != 0) {
+    const int error = m_operations[i].prepareAttrInfo(m_attrInfo);
+    if (unlikely(error))
+    {
       setErrorCode(error);
       return -1;
     }
@@ -2450,23 +2596,6 @@ NdbQueryImpl::prepareSend()
     return -1;
   }
 
-  /**
-   * Allocate and initialize fragment state variables.
-   */
-  m_rootFrags = new NdbRootFragment[m_rootFragCount];
-  if(m_rootFrags == NULL)
-  {
-    setErrorCode(Err_MemoryAlloc);
-    return -1;
-  }
-  else
-  {
-    for(Uint32 i = 0; i<m_rootFragCount; i++)
-    {
-      m_rootFrags[i].init(*this, i); // Set fragment number.
-    }
-  }
-
   if (getQueryDef().isScanQuery())
   {
     NdbRootFragment::buildReciverIdMap(m_rootFrags, m_rootFragCount);
@@ -2494,11 +2623,13 @@ class InitialReceiverIdIterator: public
 {
 public:
   
-  InitialReceiverIdIterator(const NdbQueryImpl& query)
-    :m_query(query),
+  InitialReceiverIdIterator(NdbRootFragment rootFrags[],
+                            Uint32 cnt)
+    :m_rootFrags(rootFrags),
+     m_fragCount(cnt),
      m_currFragNo(0)
   {}
-  
+
   virtual ~InitialReceiverIdIterator() {};
   
   /**
@@ -2519,8 +2650,11 @@ private:
    * improving efficiency.
    */
   static const Uint32 bufSize = 16;
-  /** The query with the scan root operation that we list receiver ids for.*/
-  const NdbQueryImpl& m_query;
+
+  /** Set of root fragments which we want to itterate receiver ids for.*/
+  NdbRootFragment* m_rootFrags;
+  const Uint32 m_fragCount;
+
   /** The next fragment numnber to be processed. (Range for 0 to no of 
    * fragments.)*/
   Uint32 m_currFragNo;
@@ -2530,25 +2664,25 @@ private:
 
 const Uint32* InitialReceiverIdIterator::getNextWords(Uint32& sz)
 {
-  sz = 0;
   /**
    * For the initial batch, we want to retrieve one batch for each fragment
    * whether it is a sorted scan or not.
    */
-  if (m_currFragNo >= m_query.getRootFragCount())
+  if (m_currFragNo >= m_fragCount)
   {
+    sz = 0;
     return NULL;
   }
   else
   {
-    const NdbQueryOperationImpl& root = m_query.getQueryOperation(0U);
-    while (sz < bufSize && 
-           m_currFragNo < m_query.getRootFragCount())
+    Uint32 cnt = 0;
+    while (cnt < bufSize && m_currFragNo < m_fragCount)
     {
-      m_receiverIds[sz] = root.getReceiver(m_currFragNo).getId();
-      sz++;
+      m_receiverIds[cnt] = m_rootFrags[m_currFragNo].getReceiverId();
+      cnt++;
       m_currFragNo++;
     }
+    sz = cnt;
     return m_receiverIds;
   }
 }
@@ -2690,7 +2824,7 @@ NdbQueryImpl::doSend(int nodeId, bool la
      * Section 2 : Optional KEYINFO section
      */
     GenericSectionPtr secs[3];
-    InitialReceiverIdIterator receiverIdIter(*this);
+    InitialReceiverIdIterator receiverIdIter(m_rootFrags, m_rootFragCount);
     LinearSectionIterator attrInfoIter(m_attrInfo.addr(), m_attrInfo.getSize());
     LinearSectionIterator keyInfoIter(m_keyInfo.addr(), m_keyInfo.getSize());
  
@@ -2831,17 +2965,15 @@ Remark:
 int
 NdbQueryImpl::sendFetchMore(NdbRootFragment& emptyFrag, bool forceSend)
 {
-  assert(getRoot().m_resultStreams!=NULL);
   assert(!emptyFrag.finalBatchReceived());
   assert(getQueryDef().isScanQuery());
 
-  const Uint32 fragNo = emptyFrag.getFragNo();
   emptyFrag.reset();
 
   for (unsigned opNo=0; opNo<m_countOperations; opNo++) 
   {
     NdbResultStream& resultStream = 
-       getQueryOperation(opNo).getResultStream(fragNo);
+       emptyFrag.getResultStream(opNo);
 
     if (!resultStream.isSubScanComplete())
     {
@@ -2868,8 +3000,7 @@ NdbQueryImpl::sendFetchMore(NdbRootFragm
   scanNextReq->transId2 = (Uint32) (transId >> 32);
   tSignal.setLength(ScanNextReq::SignalLength);
 
-  const uint32 receiverId = 
-    emptyFrag.getResultStream(0).getReceiver().m_tcPtrI;
+  const uint32 receiverId = emptyFrag.getReceiverTcPtrI();
   LinearSectionIterator receiverIdIter(&receiverId ,1);
 
   GenericSectionPtr secs[1];
@@ -3302,9 +3433,9 @@ NdbQueryImpl::OrderedFragSet::getEmpty()
 bool 
 NdbQueryImpl::OrderedFragSet::verifySortOrder() const
 {
-  for(int i = 0; i<m_activeFragCount-2; i++)
+  for (int i = 0; i<m_activeFragCount-1; i++)
   {
-    if(compare(*m_activeFrags[i], *m_activeFrags[i+1]) < 0)
+    if (compare(*m_activeFrags[i], *m_activeFrags[i+1]) < 0)
     {
       assert(false);
       return false;
@@ -3364,10 +3495,7 @@ NdbQueryOperationImpl::NdbQueryOperation
   m_parent(NULL),
   m_children(def.getNoOfChildOperations()),
   m_maxBatchRows(0),   // >0: User specified prefered value, ==0: Use default CFG values
-  m_resultStreams(NULL),
   m_params(),
-  m_bufferSize(0),
-  m_batchOverflowCheck(NULL),
   m_resultBuffer(NULL),
   m_resultRef(NULL),
   m_isRowNull(true),
@@ -3416,10 +3544,10 @@ NdbQueryOperationImpl::NdbQueryOperation
 
 NdbQueryOperationImpl::~NdbQueryOperationImpl()
 {
-  // We expect ::postFetchRelease to have deleted fetch related structures when fetch completed.
-  // Either by fetching through last row, or calling ::close() which forcefully terminates fetch
-  assert (m_batchOverflowCheck == NULL);
-  assert (m_resultStreams == NULL);
+  /**
+   * We expect ::postFetchRelease to have deleted fetch related structures when fetch completed.
+   * Either by fetching through last row, or calling ::close() which forcefully terminates fetch
+   */
   assert (m_firstRecAttr == NULL);
   assert (m_interpretedCode == NULL);
 } //NdbQueryOperationImpl::~NdbQueryOperationImpl()
@@ -3431,22 +3559,6 @@ NdbQueryOperationImpl::~NdbQueryOperatio
 void
 NdbQueryOperationImpl::postFetchRelease()
 {
-  // Buffer overrun check.
-  assert(m_batchOverflowCheck==NULL || *m_batchOverflowCheck ==  0xacbd1234);
-  m_batchOverflowCheck = NULL;
-  
-  if (m_resultStreams != NULL)
-  { 
-    for (int i = static_cast<int>(getQuery().getRootFragCount())-1; i >= 0; i--)
-    {
-      if (m_resultStreams[i] != NULL)
-      {
-        m_resultStreams[i]->~NdbResultStream();
-      }
-    }
-  }
-  m_resultStreams = NULL;
-
   Ndb* const ndb = m_queryImpl.getNdbTransaction().getNdb();
   NdbRecAttr* recAttr = m_firstRecAttr;
   while (recAttr != NULL) {
@@ -3680,7 +3792,7 @@ NdbQueryOperationImpl::firstResult()
 
   if (rootFrag != NULL)
   {
-    NdbResultStream& resultStream = *m_resultStreams[rootFrag->getFragNo()];
+    NdbResultStream& resultStream = rootFrag->getResultStream(*this);
     if (resultStream.firstResult() != tupleNotFound)
     {
       fetchRow(resultStream);
@@ -3720,7 +3832,7 @@ NdbQueryOperationImpl::nextResult(bool f
     const NdbRootFragment* rootFrag = m_queryImpl.m_applFrags.getCurrent();
     if (rootFrag!=NULL)
     {
-      NdbResultStream& resultStream = *m_resultStreams[rootFrag->getFragNo()];
+      NdbResultStream& resultStream = rootFrag->getResultStream(*this);
       if (resultStream.nextResult() != tupleNotFound)
       {
         fetchRow(resultStream);
@@ -3736,7 +3848,7 @@ NdbQueryOperationImpl::nextResult(bool f
 void 
 NdbQueryOperationImpl::fetchRow(NdbResultStream& resultStream)
 {
-  const char* buff = resultStream.getReceiver().get_row();
+  const char* buff = resultStream.getReceiver().peek_row();
   assert(buff!=NULL || (m_firstRecAttr==NULL && m_ndbRecord==NULL));
 
   m_isRowNull = false;
@@ -4051,55 +4163,9 @@ NdbQueryOperationImpl::setBatchedRows(Ui
   }
 }
 
-
-int 
-NdbQueryOperationImpl::prepareReceiver()
-{
-  // Construct receiver streams and prepare them for receiving scan result
-  assert(m_resultStreams==NULL);
-  assert(m_queryImpl.getRootFragCount() > 0);
-
-  m_resultStreams = reinterpret_cast<NdbResultStream**>
-    (getQuery().getPointerAlloc().allocObjMem(m_queryImpl.getRootFragCount())); 
-
-  for(Uint32 i = 0; i<m_queryImpl.getRootFragCount(); i++) {
-    m_resultStreams[i] = NULL;  // Init to legal contents for d'tor
-  }
-  for(Uint32 i = 0; i<m_queryImpl.getRootFragCount(); i++) {
-    m_resultStreams[i] = new (getQuery().m_resultStreamAlloc.allocObjMem(1))
-      NdbResultStream(*this, i);
-    const int error = m_resultStreams[i]->prepare();
-    if (unlikely(error)) {
-      return error;
-    }
-
-    m_resultStreams[i]->getReceiver().init(NdbReceiver::NDB_QUERY_OPERATION, 
-                                        false, this);
-    char* const rowBuf = reinterpret_cast<char*>(getQuery().getRowBufferAlloc()
-                                                 .allocObjMem(m_bufferSize));
-    m_resultStreams[i]->getReceiver()
-      .do_setup_ndbrecord(m_ndbRecord,
-                          getMaxBatchRows(), 
-                          0 /*key_size*/, 
-                          0 /*read_range_no*/, 
-                          getRowSize(),
-                          rowBuf);
-    m_resultStreams[i]->getReceiver().prepareSend();
-  }
-  // So that we can test for for buffer overrun.
-  m_batchOverflowCheck = 
-    reinterpret_cast<Uint32*>(getQuery().getRowBufferAlloc()
-                              .allocObjMem(sizeof(Uint32)));
-  *m_batchOverflowCheck = 0xacbd1234;
-  return 0;
-}//NdbQueryOperationImpl::prepareReceiver
-
 int 
 NdbQueryOperationImpl::prepareAttrInfo(Uint32Buffer& attrInfo)
 {
-  // ::prepareReceiver() need to complete first:
-  assert (m_resultStreams != NULL);
-
   const NdbQueryOperationDefImpl& def = getQueryOperationDef();
 
   /**
@@ -4582,14 +4648,14 @@ NdbQueryOperationImpl::execTRANSID_AI(co
   }
 
   // Process result values.
-  m_resultStreams[rootFragNo]->execTRANSID_AI(ptr, len);
+  rootFrag->getResultStream(*this).execTRANSID_AI(ptr, len);
 
   rootFrag->incrOutstandingResults(-1);
 
   bool ret = false;
   if (rootFrag->isFragBatchComplete())
   {
-    ret = m_queryImpl.handleBatchComplete(rootFragNo);
+    ret = m_queryImpl.handleBatchComplete(*rootFrag);
   }
 
   if (traceSignals) {
@@ -4631,7 +4697,6 @@ NdbQueryOperationImpl::execTCKEYREF(cons
     }
   }
 
-  Uint32 rootFragNo = 0;
   NdbRootFragment& rootFrag = getQuery().m_rootFrags[0];
 
   if (ref->errorCode != DbspjErr::NodeFailure)
@@ -4656,13 +4721,12 @@ NdbQueryOperationImpl::execTCKEYREF(cons
   bool ret = false;
   if (rootFrag.isFragBatchComplete())
   { 
-    ret = m_queryImpl.handleBatchComplete(rootFragNo);
+    ret = m_queryImpl.handleBatchComplete(rootFrag);
   } 
 
   if (traceSignals) {
     ndbout << "NdbQueryOperationImpl::execTCKEYREF(): returns:" << ret
-           << ", *getRoot().m_resultStreams[0] {" 
-           << *getRoot().m_resultStreams[0] << "}"
+           << ", resultStream= {" << rootFrag.getResultStream(*this) << "}"
            << ", *this=" << *this <<  endl;
   }
   return ret;
@@ -4698,12 +4762,13 @@ NdbQueryOperationImpl::execSCAN_TABCONF(
   rootFrag->incrOutstandingResults(rowCount);
 
   // Handle for SCAN_NEXTREQ, RNIL -> EOF
-  NdbResultStream& resultStream = *m_resultStreams[rootFrag->getFragNo()];
+  NdbResultStream& resultStream = rootFrag->getResultStream(*this);
   resultStream.getReceiver().m_tcPtrI = tcPtrI;  
 
   if(traceSignals){
-    ndbout << "  resultStream(root) {" << resultStream << "} fragNo" 
-           << rootFrag->getFragNo() << endl;
+    ndbout << "  resultStream {" << rootFrag->getResultStream(*this)
+           << "} fragNo" << rootFrag->getFragNo()
+           << endl;
   }
 
   const NdbQueryDefImpl& queryDef = m_queryImpl.getQueryDef();
@@ -4735,7 +4800,7 @@ NdbQueryOperationImpl::execSCAN_TABCONF(
   if (rootFrag->isFragBatchComplete())
   {
     /* This fragment is now complete */
-    ret = m_queryImpl.handleBatchComplete(rootFrag->getFragNo());
+    ret = m_queryImpl.handleBatchComplete(*rootFrag);
   }
   if (traceSignals) {
     ndbout << "NdbQueryOperationImpl::execSCAN_TABCONF():, returns:" << ret
@@ -4871,13 +4936,6 @@ int NdbQueryOperationImpl::setBatchSize(
   return 0;
 }
 
-NdbResultStream& 
-NdbQueryOperationImpl::getResultStream(Uint32 rootFragNo) const
-{
-  assert(rootFragNo < getQuery().getRootFragCount());
-  return *m_resultStreams[rootFragNo];
-}
-
 bool
 NdbQueryOperationImpl::hasInterpretedCode() const
 {
@@ -4916,15 +4974,8 @@ NdbQueryOperationImpl::prepareInterprete
 
 Uint32 
 NdbQueryOperationImpl::getIdOfReceiver() const {
-  return m_resultStreams[0]->getReceiver().getId();
-}
-
-
-const NdbReceiver& 
-NdbQueryOperationImpl::getReceiver(Uint32 recNo) const {
-  assert(recNo<getQuery().getRootFragCount());
-  assert(m_resultStreams!=NULL);
-  return m_resultStreams[recNo]->getReceiver();
+  NdbRootFragment& rootFrag = m_queryImpl.m_rootFrags[0];
+  return rootFrag.getResultStream(*this).getReceiver().getId();
 }
 
 Uint32 NdbQueryOperationImpl::getRowSize() const
@@ -4953,7 +5004,8 @@ NdbOut& operator<<(NdbOut& out, const Nd
   out << "  m_queryImpl: " << &op.m_queryImpl;
   out << "  m_operationDef: " << &op.m_operationDef;
   for(Uint32 i = 0; i<op.m_queryImpl.getRootFragCount(); i++){
-    out << "  m_resultStream[" << i << "]{" << *op.m_resultStreams[i] << "}";
+    NdbRootFragment& rootFrag = op.m_queryImpl.m_rootFrags[i];
+    out << "  m_resultStream[" << i << "]{" << rootFrag.getResultStream(op) << "}";
   }
   out << " m_isRowNull " << op.m_isRowNull;
   out << " ]";

=== modified file 'storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp'
--- a/storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp	2011-06-20 13:25:48 +0000
+++ b/storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp	2011-08-16 07:56:53 +0000
@@ -247,9 +247,15 @@ public:
   Uint32 getRootFragCount() const
   { return m_rootFragCount; }
 
+  NdbBulkAllocator& getResultStreamAlloc()
+  { return m_resultStreamAlloc; }
+
   NdbBulkAllocator& getTupleSetAlloc()
   { return m_tupleSetAlloc; }
 
+  NdbBulkAllocator& getRowBufferAlloc()
+  { return m_rowBufferAlloc; }
+
 private:
   /** Possible return values from NdbQueryImpl::awaitMoreResults. 
    * A subset of the integer values also matches those returned
@@ -577,13 +583,10 @@ private:
    *  the result.
    *  @return: 'true' if its time to resume appl. threads
    */ 
-  bool handleBatchComplete(Uint32 rootFragNo);
+  bool handleBatchComplete(NdbRootFragment& rootFrag);
 
   NdbBulkAllocator& getPointerAlloc()
   { return m_pointerAlloc; }
-  
-  NdbBulkAllocator& getRowBufferAlloc()
-  { return m_rowBufferAlloc; }
 
 }; // class NdbQueryImpl
 
@@ -705,10 +708,6 @@ public:
   int setInterpretedCode(const NdbInterpretedCode& code);
   bool hasInterpretedCode() const;
 
-  NdbResultStream& getResultStream(Uint32 rootFragNo) const;
-
-  const NdbReceiver& getReceiver(Uint32 rootFragNo) const;
-
   /** Verify magic number.*/
   bool checkMagicNumber() const
   { return m_magic == MAGIC; }
@@ -719,6 +718,12 @@ public:
   Uint32 getMaxBatchRows() const
   { return m_maxBatchRows; }
 
+  /** Get size of row as required to buffer it. */  
+  Uint32 getRowSize() const;
+
+  const NdbRecord* getNdbRecord() const
+  { return m_ndbRecord; }
+
 private:
 
   STATIC_CONST (MAGIC = 0xfade1234);
@@ -742,16 +747,9 @@ private:
   /** Max rows (per resultStream) in a scan batch.*/
   Uint32 m_maxBatchRows;
 
-  /** For processing results from this operation (Array of).*/
-  NdbResultStream** m_resultStreams;
   /** Buffer for parameters in serialized format */
   Uint32Buffer m_params;
 
-  /** Buffer size allocated for *each* ResultStream/Receiver when 
-   *  fetching results.*/
-  Uint32 m_bufferSize;
-  /** Used for checking if buffer overrun occurred. */
-  Uint32* m_batchOverflowCheck;
   /** User specified buffer for final storage of result.*/
   char* m_resultBuffer;
   /** User specified pointer to application pointer that should be 
@@ -819,9 +817,6 @@ private:
   Uint32 calculateBatchedRows(const NdbQueryOperationImpl* closestScan);
   void setBatchedRows(Uint32 batchedRows);
 
-  /** Construct and prepare receiver streams for result processing. */
-  int prepareReceiver();
-
   /** Prepare ATTRINFO for execution. (Add execution params++)
    *  @return possible error code.*/
   int prepareAttrInfo(Uint32Buffer& attrInfo);
@@ -863,7 +858,6 @@ private:
   bool diskInUserProjection() const
   { return m_diskInUserProjection; }
 
-  Uint32 getRowSize() const;
 }; // class NdbQueryOperationImpl
 
 

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.1-telco-7.1 branch (jonas.oreland:4253 to 4255) jonas oreland17 Aug