NdbIndexScanOperation.hpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:5k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #ifndef NdbIndexScanOperation_H
  14. #define NdbIndexScanOperation_H
  15. #include <NdbScanOperation.hpp>
  16. /**
  17.  * @class NdbIndexScanOperation
  18.  * @brief Class of scan operations for use to scan ordered index
  19.  */
  20. class NdbIndexScanOperation : public NdbScanOperation {
  21.   friend class Ndb;
  22.   friend class NdbConnection;
  23.   friend class NdbResultSet;
  24.   friend class NdbOperation;
  25.   friend class NdbScanOperation;
  26. public:
  27.   /**
  28.    * readTuples returns a NdbResultSet where tuples are stored.
  29.    * Tuples are not stored in NdbResultSet until execute(NoCommit) 
  30.    * has been executed and nextResult has been called.
  31.    * 
  32.    * @param parallel  Scan parallelism
  33.    * @param batch     No of rows to fetch from each fragment at a time
  34.    * @param LockMode  Scan lock handling   
  35.    * @param order_by  Order result set in index order
  36.    * @returns NdbResultSet.
  37.    * @see NdbScanOperation::readTuples
  38.    */ 
  39.   NdbResultSet* readTuples(LockMode = LM_Read,
  40.    Uint32 batch = 0, 
  41.    Uint32 parallel = 0,
  42.    bool order_by = false);
  43.   
  44.   inline NdbResultSet* readTuples(int parallell){
  45.     return readTuples(LM_Read, 0, parallell, false);
  46.   }
  47.   
  48.   inline NdbResultSet* readTuplesExclusive(int parallell = 0){
  49.     return readTuples(LM_Exclusive, 0, parallell, false);
  50.   }
  51.   /**
  52.    * Type of ordered index key bound.  The values (0-4) will not change
  53.    * and can be used explicitly (e.g. they could be computed).
  54.    */
  55.   enum BoundType {
  56.     BoundLE = 0,        ///< lower bound
  57.     BoundLT = 1,        ///< lower bound, strict
  58.     BoundGE = 2,        ///< upper bound
  59.     BoundGT = 3,        ///< upper bound, strict
  60.     BoundEQ = 4         ///< equality
  61.   };
  62.   /**
  63.    * Define bound on index key in range scan.
  64.    *
  65.    * Each index key can have lower and/or upper bound.  Setting the key
  66.    * equal to a value defines both upper and lower bounds.  The bounds
  67.    * can be defined in any order.  Conflicting definitions is an error.
  68.    *
  69.    * For equality, it is better to use BoundEQ instead of the equivalent
  70.    * pair of BoundLE and BoundGE.  This is especially true when table
  71.    * distribution key is an initial part of the index key.
  72.    *
  73.    * The sets of lower and upper bounds must be on initial sequences of
  74.    * index keys.  All but possibly the last bound must be non-strict.
  75.    * So "a >= 2 and b > 3" is ok but "a > 2 and b >= 3" is not.
  76.    *
  77.    * The scan may currently return tuples for which the bounds are not
  78.    * satisfied.  For example, "a <= 2 and b <= 3" scans the index up to
  79.    * (a=2, b=3) but also returns any (a=1, b=4).
  80.    *
  81.    * NULL is treated like a normal value which is less than any not-NULL
  82.    * value and equal to another NULL value.  To compare against NULL use
  83.    * setBound with null pointer (0).
  84.    *
  85.    * An index stores also all-NULL keys.  Doing index scan with empty
  86.    * bound set returns all table tuples.
  87.    *
  88.    * @param attrName    Attribute name, alternatively:
  89.    * @param anAttrId    Index column id (starting from 0)
  90.    * @param type        Type of bound
  91.    * @param value       Pointer to bound value, 0 for NULL
  92.    * @param len         Value length in bytes.
  93.    *                    Fixed per datatype and can be omitted
  94.    * @return            0 if successful otherwise -1
  95.    */
  96.   int setBound(const char* attr, int type, const void* aValue, Uint32 len = 0);
  97.   /**
  98.    * Define bound on index key in range scan using index column id.
  99.    * See the other setBound() method for details.
  100.    */
  101.   int setBound(Uint32 anAttrId, int type, const void* aValue, Uint32 len = 0);
  102.   /**
  103.    * Reset bounds and put operation in list that will be
  104.    *   sent on next execute
  105.    */
  106.   int reset_bounds(bool forceSend = false);
  107.   
  108.   bool getSorted() const { return m_ordered; }
  109. private:
  110.   NdbIndexScanOperation(Ndb* aNdb);
  111.   virtual ~NdbIndexScanOperation();
  112.   int setBound(const NdbColumnImpl*, int type, const void* aValue, Uint32 len);
  113.   int insertBOUNDS(Uint32 * data, Uint32 sz);
  114.   virtual int equal_impl(const NdbColumnImpl*, const char*, Uint32);
  115.   virtual NdbRecAttr* getValue_impl(const NdbColumnImpl*, char*);
  116.   void fix_get_values();
  117.   int next_result_ordered(bool fetchAllowed, bool forceSend = false);
  118.   int send_next_scan_ordered(Uint32 idx, bool forceSend = false);
  119.   int compare(Uint32 key, Uint32 cols, const NdbReceiver*, const NdbReceiver*);
  120.   Uint32 m_sort_columns;
  121.   friend struct Ndb_free_list_t<NdbIndexScanOperation>;
  122. };
  123. #endif