1 /* Copyright (C) 2014 InfiniDB, Inc.
2 
3    This program is free software; you can redistribute it and/or
4    modify it under the terms of the GNU General Public License
5    as published by the Free Software Foundation; version 2 of
6    the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16    MA 02110-1301, USA. */
17 
18 //  $Id: limitedorderby.h 9414 2013-04-22 22:18:30Z xlou $
19 
20 
21 /** @file */
22 
23 #ifndef LIMITED_ORDER_BY_H
24 #define LIMITED_ORDER_BY_H
25 
26 #include <string>
27 #include "rowgroup.h"
28 #include "../../utils/windowfunction/idborderby.h"
29 
30 
31 namespace joblist
32 {
33 
34 
35 // forward reference
36 struct JobInfo;
37 
38 
39 // ORDER BY with LIMIT class
40 // This version is for subqueries, limit the result set to fit in memory,
41 // use ORDER BY to make the results consistent.
42 // The actual output are the first or last # of rows, which are NOT ordered.
43 class LimitedOrderBy : public ordering::IdbOrderBy
44 {
45 public:
46     LimitedOrderBy();
47     virtual ~LimitedOrderBy();
48     using ordering::IdbOrderBy::initialize;
49     void initialize(const rowgroup::RowGroup&,
50         const JobInfo&,
51         bool invertRules = false,
52         bool isMultiThreded = false);
53     void processRow(const rowgroup::Row&);
54     uint64_t getKeyLength() const;
getLimitCount()55     uint64_t getLimitCount() const
56     {
57         return fCount;
58     }
59     const std::string toString() const;
60 
61     void finalize();
62 
63 protected:
64     uint64_t              fStart;
65     uint64_t              fCount;
66     uint64_t              fUncommitedMemory;
67     static const uint64_t fMaxUncommited;
68 };
69 
70 
71 }
72 
73 #endif  // LIMITED_ORDER_BY_H
74 
75