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 /*
19 * $Id: primitivemsg.h 9655 2013-06-25 23:08:13Z xlou $
20 */
21 
22 /** @file */
23 
24 #ifndef JOBLIST_PRIMITIVE_H
25 #define JOBLIST_PRIMITIVE_H
26 
27 #include <sys/types.h>
28 
29 #include "blocksize.h"
30 #include "calpontsystemcatalog.h"
31 #include "joblisttypes.h"
32 
33 #ifdef __cplusplus
34 #include <vector>
35 extern "C"
36 {
37 #endif
38 
39 #pragma pack(push,1)
40 
41 #ifdef _MSC_VER
42 #pragma warning (push)
43 #pragma warning (disable : 4200)
44 #endif
45 
46 // from blocksize.h
47 const int32_t DATA_BLOCK_SIZE = BLOCK_SIZE;
48 
49 const int8_t COMPARE_NIL = 0x00;
50 const int8_t COMPARE_LT = 0x01;
51 const int8_t COMPARE_EQ = 0x02;
52 const int8_t COMPARE_LE = (COMPARE_LT | COMPARE_EQ); //0x03
53 const int8_t COMPARE_GT = 0x04;
54 const int8_t COMPARE_NE = (COMPARE_LT | COMPARE_GT); //0x05
55 const int8_t COMPARE_GE = (COMPARE_GT | COMPARE_EQ); //0x06
56 const int8_t COMPARE_NOT = 0x08;
57 const int8_t COMPARE_NLT = (COMPARE_LT | COMPARE_NOT); //0x09
58 const int8_t COMPARE_NLE = (COMPARE_LE | COMPARE_NOT); //0x0b
59 const int8_t COMPARE_NGT = (COMPARE_GT | COMPARE_NOT); //0x0c
60 const int8_t COMPARE_NGE = (COMPARE_GE | COMPARE_NOT); //0x0e
61 
62 const int8_t COMPARE_LIKE = 0x10;
63 const int8_t COMPARE_NLIKE = (COMPARE_LIKE | COMPARE_NOT); //0x18
64 
65 
66 namespace primitives
67 {
68 
69 using utils::ConstString;
70 
71 class StringComparator: public datatypes::Charset
72 {
73 public:
StringComparator(const Charset & cs)74     StringComparator(const Charset &cs)
75      :Charset(cs)
76     { }
op(int * error,uint8_t COP,const ConstString & str1,const ConstString & str2)77     bool op(int * error, uint8_t COP,
78             const ConstString &str1,
79             const ConstString &str2) const
80     {
81         if (COP & COMPARE_LIKE)
82            return like(COP & COMPARE_NOT, str1, str2);
83 
84         int cmp = strnncollsp(str1, str2);
85 
86         switch (COP)
87         {
88             case COMPARE_NIL:
89                 return false;
90 
91             case COMPARE_LT:
92                 return cmp < 0;
93 
94             case COMPARE_EQ:
95                 return cmp == 0;
96 
97             case COMPARE_LE:
98                 return cmp <= 0;
99 
100             case COMPARE_GT:
101                 return cmp > 0;
102 
103             case COMPARE_NE:
104                 return cmp != 0;
105 
106             case COMPARE_GE:
107                 return cmp >= 0;
108 
109             default:
110                 *error |= 1;
111                 return false;
112         }
113 
114     }
115 };
116 
117 } // namespace primities
118 
119 //      BOP (Binary Operation) values
120 //          used to tell if the operations are all be true or
121 //          any to be true.
122 
123 #define BOP_NONE 0
124 #define BOP_AND 1
125 #define BOP_OR 2
126 #define BOP_XOR 3
127 
128 //		OT (Output Type) values
129 // 1 = RID, 2 = Token, 3 = Both
130 
131 #define OT_RID 1
132 #define OT_TOKEN 2
133 #define OT_BOTH 3				// both = RID & TOKEN
134 #define OT_DATAVALUE 4
135 #define OT_INPUTARG OT_RID		// reuse OT_RID's flag in dictionary primitives.  Specifies that
136 // the filter argument that matched should be part of the result set.
137 // (only makes sense when BOP = OR).
138 #define OT_AGGREGATE 8			// specifies that aggregate data should be generated
139 
140 //      Packet Header Types
141 
142 enum PACKETTYPE
143 {
144     NULL1   = 0,
145     NULL2   = 0X0F,
146     DATA    = 1,
147     CMD     = 2,
148     FLOW    = 3,
149     CONFIG  = 9
150 };
151 
152 enum TYPEFLOWCOMMAND
153 {
154     ACK     = 1,
155     NACK    = 2
156 };
157 
158 //      Define the ISM Commands
159 
160 #define PRIM_LOCALBASE 10
161 #define PRIM_COLBASE 50
162 #define PRIM_INDEXBASE 100
163 #define PRIM_CACHEBASE 190
164 #define PRIM_DICTBASE 200
165 #define PRIM_DELIVERBASE 250
166 
167 //8 bits only!
168 enum ISMPACKETCOMMAND
169 {
170     //max of 50-10=40 commands
171     LOCAL_JOIN_BY_RID           = PRIM_LOCALBASE + 0,
172     LOCAL_OR_BY_RID             = PRIM_LOCALBASE + 1,
173     ARITHMETIC_FUNCTION         = PRIM_LOCALBASE + 2,
174     FUNCTION_CALL               = PRIM_LOCALBASE + 3,
175     FUNCTION_CALL_VECTOR        = PRIM_LOCALBASE + 4,
176     LOCAL_COMPARE_BY_VALUE      = PRIM_LOCALBASE + 5,
177     LOCAL_JOIN_BY_VALUE         = PRIM_LOCALBASE + 6,
178     BATCH_PRIMITIVE_CREATE      = PRIM_LOCALBASE + 7,
179     BATCH_PRIMITIVE_RUN         = PRIM_LOCALBASE + 8,
180     BATCH_PRIMITIVE_DESTROY     = PRIM_LOCALBASE + 9,
181     BATCH_PRIMITIVE_ADD_JOINER  = PRIM_LOCALBASE + 10,
182     BATCH_PRIMITIVE_END_JOINER  = PRIM_LOCALBASE + 11,
183     BATCH_PRIMITIVE_ACK			= PRIM_LOCALBASE + 12,
184     BATCH_PRIMITIVE_ABORT		= PRIM_LOCALBASE + 13,
185 
186     //max of 100-50=50 commands
187     COL_RESULTS                 = PRIM_COLBASE + 0,
188     COL_AGG_RESULTS             = PRIM_COLBASE + 1,
189     COL_BY_SCAN                 = PRIM_COLBASE + 2,
190     COL_BY_RID                  = PRIM_COLBASE + 3,
191     COL_AGG_BY_SCAN             = PRIM_COLBASE + 4,
192     COL_AGG_BY_RID              = PRIM_COLBASE + 5,
193     COL_JOIN_BY_SCAN            = PRIM_COLBASE + 6,
194     COL_FILTER_BY_TOKEN         = PRIM_COLBASE + 7,
195     COL_FILTER_BY_RID_VAL       = PRIM_COLBASE + 8,
196     COL_BY_SCAN_RANGE           = PRIM_COLBASE + 9,
197     COL_LOOPBACK                = PRIM_COLBASE + 10,
198 
199     //max of 190-100=90 commands
200     INDEX_RESULTS                = PRIM_INDEXBASE + 0, // Obsolete ?
201     INDEX_SCAN_RESULTS           = PRIM_INDEXBASE + 1, // p_IdxScan results
202     INDEX_WALK_RESULTS           = PRIM_INDEXBASE + 2, // p_IdxWalk results
203     INDEX_LIST_RESULTS           = PRIM_INDEXBASE + 3, // p_IdxList results
204     INDEX_LIST_AGGREGATE_RESULTS = PRIM_INDEXBASE + 4, // p_IdxListAggregate results
205     INDEX_SCAN_AGGREGATE_RESULTS = PRIM_INDEXBASE + 5, // p_IdxScanAggregate results
206     INDEX_BY_SCAN                = PRIM_INDEXBASE + 6, // p_IdxScan
207     INDEX_BY_COMPARE             = PRIM_INDEXBASE + 7, // Obsolete ?
208     INDEX_WALK                   = PRIM_INDEXBASE + 8, // p_IdxWalk
209     INDEX_LIST                   = PRIM_INDEXBASE + 9, // p_IdxList
210     INDEX_LIST_AGGREGATE         = PRIM_INDEXBASE + 10, // p_IdxListAggregate
211     INDEX_SCAN_AGGREGATE         = PRIM_INDEXBASE + 11, // p_IdxScanAggregate
212 
213     //max of 200-190=10 commands
214     CACHE_OP_RESULTS           = PRIM_CACHEBASE + 0, // Response msg
215     CACHE_FLUSH                = PRIM_CACHEBASE + 1, // Flush the entire block cache
216     CACHE_CLEAN_VSS            = PRIM_CACHEBASE + 2, // Clean out indicated VSS entries
217     CACHE_DROP_FDS             = PRIM_CACHEBASE + 3, // Drop the whole file descriptor cache
218     FLUSH_ALL_VERSION          = PRIM_CACHEBASE + 4, // Drop all versions of specified LBIDs
219     CACHE_FLUSH_BY_OID		   = PRIM_CACHEBASE + 5, // Drop all versions of all LBIDs for the given OIDs
220     CACHE_FLUSH_PARTITION	   = PRIM_CACHEBASE + 6, // Drop a partition
221     CACHE_PURGE_FDS			   = PRIM_CACHEBASE + 7, // Purge the file descriptor cache for the modified files
222 
223     //max of 250-200=50 commands
224     DICT_RESULTS                = PRIM_DICTBASE + 0,
225     DICT_TOKEN_BY_INDEX_COMPARE = PRIM_DICTBASE + 1,
226     DICT_TOKEN_BY_SCAN_COMPARE  = PRIM_DICTBASE + 2,
227     DICT_SIGNATURE              = PRIM_DICTBASE + 3,
228     DICT_AGGREGATE              = PRIM_DICTBASE + 4,
229     DICT_AGGREGATE_RESULTS		= PRIM_DICTBASE + 5,
230     DICT_SCAN_COMPARE_RESULTS	= PRIM_DICTBASE + 6,
231     DICT_SIGNATURE_RANGE        = PRIM_DICTBASE + 7,
232     DICT_CREATE_EQUALITY_FILTER	= PRIM_DICTBASE + 8,
233     DICT_DESTROY_EQUALITY_FILTER = PRIM_DICTBASE + 9,
234 
235     //max of 256-250=6 commands
236     DELIVER_TOKEN_RESULTS       = PRIM_DELIVERBASE + 0,
237     DELIVER_RID_RESULTS         = PRIM_DELIVERBASE + 1
238 };
239 
240 #undef PRIM_LOCALBASE
241 #undef PRIM_COLBASE
242 #undef PRIM_INDEXBASE
243 #undef PRIM_DICTBASE
244 #undef PRIM_DELIVERBASE
245 
246 /* Flags for BPP messages */
247 const uint8_t NEED_STR_VALUES       = 0x01; //1;
248 const uint8_t GOT_ABS_RIDS          = 0x02; //2;
249 const uint8_t GOT_VALUES            = 0x04; //4;
250 const uint8_t LBID_TRACE            = 0x08; //8;
251 const uint8_t HAS_JOINER            = 0x10; //16;
252 const uint8_t SEND_RIDS_AT_DELIVERY = 0x20; //32;
253 const uint8_t HAS_ROWGROUP          = 0x40; //64;
254 const uint8_t JOIN_ROWGROUP_DATA	= 0x80; //128
255 
256 //TODO: put this in a namespace to stop global ns pollution
257 enum PrimFlags
258 {
259     PF_LBID_TRACE = 0x01,	/*!< Enable LBID tracing in PrimProc */
260     PF_PM_PROF = 0x02,	/*!< Enable LBID tracing in PrimProc */
261 };
262 
263 enum BPSOutputType
264 {
265     BPS_ELEMENT_TYPE,
266     STRING_ELEMENT_TYPE,
267     TABLE_BAND,
268     TUPLE,
269     ROW_GROUP
270 };
271 
272 //      Constant Message Header structures
273 
274 //      Packet Header for VBEU & CachEU
275 
276 #if 0
277 struct VBCPacketHeader
278 {
279     //    unsigned char Type:4;
280     //    unsigned char SubType:4;
281     //    unsigned int  Size:16;
282     //    unsigned int  Dest:16;
283     unsigned int  Source: 16;
284     unsigned char CmdAddr: 8;
285 };
286 #endif
287 
288 //      Packet Header for ISM SubBlock EU
289 
290 struct ISMPacketHeader
291 {
ISMPacketHeaderISMPacketHeader292     ISMPacketHeader(): Interleave(0), Flags(0), Command(0), Size(0), Type(0), MsgCount(0), Status(0) {}
293     uint32_t Interleave;
294     uint16_t Flags;
295     uint8_t Command;
296     uint16_t Size;
297     unsigned Type: 4;
298     unsigned MsgCount: 4;
299     uint16_t Status;
300 
301 };
302 
303 //      Primitive request/response structure Header
304 //@Bug 2744 changed all variables to 32 bit, and took out StatementID
305 struct PrimitiveHeader
306 {
307     uint32_t SessionID;     // Front end Session Identifier
308     uint32_t TransactionID; // Front end Transaction Identifier
309     uint32_t VerID;         // DB Version ID used for this Session/Statement
310     uint32_t StepID;        // Internal Primitive Sequence number
311     uint32_t UniqueID;      // Unique ID for DEC and BPP
312     uint32_t Priority;      // Priority level of the user
313 };
314 
315 #if 0
316 struct AckNackHeader
317 {
318     int VerID: 16;
319 };
320 
321 struct DiskResultsHeader
322 {
323     uint64_t    LBID;
324     uint64_t    VerID;
325     uint64_t    ArbIndex;
326     uint64_t    ISM;
327     uint64_t    Status;
328     uint8_t     data[DATA_BLOCK_SIZE];
329 };
330 #endif
331 
332 //      COL_LOOPBACK
333 
334 struct ColLoopback
335 {
336     PrimitiveHeader Hdr;    // 64 bit header
337 };
338 
339 
340 struct ColRequestHeaderDataType: public datatypes::Charset
341 {
342     int32_t CompType;
343     uint16_t DataSize;
344     uint8_t DataType;       // enum ColDataType defined in calpont system catalog header file
ColRequestHeaderDataTypeColRequestHeaderDataType345     ColRequestHeaderDataType()
346        :Charset(my_charset_bin),
347         CompType(0),
348         DataSize(0),
349         DataType(0)
350     { }
ColRequestHeaderDataTypeColRequestHeaderDataType351     ColRequestHeaderDataType(const execplan::CalpontSystemCatalog::ColType &rhs)
352        :Charset(rhs.charsetNumber),
353         CompType(rhs.compressionType),
354         DataSize(rhs.colWidth),
355         DataType(rhs.colDataType)
356    { }
357 };
358 
359 
360 //      COL_BY_SCAN
361 //Tied to ColByScanRangeRequestHeader and NewColRequestHeader.  Check other headers if modifying.
362 
363 struct ColByScanRequestHeader
364 {
365     PrimitiveHeader Hdr;    // 64 bit header
366     uint64_t LBID;
367     ColRequestHeaderDataType colType;
368     uint8_t OutputType;     // 1 = RID, 2 = Token, 3 = Both
369     uint8_t BOP;            // 0 = N/A, 1 = AND, 2 = OR
370     uint8_t RidFlags;		// a bitmap indicating the rid ranges in the resultM SB => row 7168-8191
371     uint16_t NOPS;
372     uint16_t NVALS;
373     uint8_t sort;
ColByScanRequestHeaderColByScanRequestHeader374     ColByScanRequestHeader()
375         :LBID(0), OutputType(0), BOP(0),
376          RidFlags(0), NOPS(0), NVALS(0), sort(0)
377     {
378         memset(&Hdr, 0, sizeof(Hdr));
379     }
380 };
381 
382 //      COL_BY_SCAN_RANGE
383 //Tied to ColByScanRequestHeader and NewColRequestHeader.  Check other headers if modifying.
384 
385 struct ColByScanRangeRequestHeader
386 {
387     PrimitiveHeader Hdr;    // 64 bit header
388     uint64_t LBID;		    // starting LBID
389     ColRequestHeaderDataType colType;
390     uint8_t OutputType;     // 1 = RID, 2 = Token, 3 = Both
391     uint8_t BOP;            // 0 = N/A, 1 = AND, 2 = OR
392     uint8_t RidFlags;		// a bitmap indicating the rid ranges in the result MSB => row 7168-8191
393     uint16_t NOPS;
394     uint16_t NVALS;
395     uint8_t sort;
396     uint16_t Count;			//Number of LBID's
ColByScanRangeRequestHeaderColByScanRangeRequestHeader397     ColByScanRangeRequestHeader()
398         :LBID(0), OutputType(0),
399          BOP(0), RidFlags(0), NOPS(0), NVALS(0),
400          sort(0), Count(0)
401     {
402         memset(&Hdr, 0, sizeof(Hdr));
403     }
404 };
405 
406 //      COL_BY_RID
407 
408 struct ColByRIDRequestHeader
409 {
410     PrimitiveHeader Hdr;                      // 64 bit header
411     uint64_t LBID;
412     ColRequestHeaderDataType colType;
413     uint8_t OutputType;                          // 1 = RID, 2 = Token, 3 = Both
414     uint8_t BOP;                                 // 0 = N/A, 1 = AND, 2 = OR
415     uint8_t InputFlags;		// 1 = interpret each NOP & RID as a pair
416     uint16_t NOPS;
417     uint16_t NVALS;
418     uint8_t sort;
419     ColByRIDRequestHeader(); // QQ? Not used?
420 };
421 
422 //      COL_AGG_BY_SCAN
423 
424 struct ColAggByScanRequestHeader
425 {
426     PrimitiveHeader Hdr;                      // 64 bit header
427     uint64_t LBID;
428     uint16_t DataSize;
429     uint8_t DataType;                            // enum ColDataType defined in calpont system catalog header file
430     uint8_t OutputType;                          // 1 = RID, 2 = Token, 3 = Both
431     uint8_t BOP;                                 // 0 = N/A, 1 = AND, 2 = OR
432     uint8_t   ExtraNotUsed;
433     uint16_t NOPS;
434     uint16_t NVALS;
435 };
436 
437 //      COL_AGG_BY_RID
438 
439 struct ColAggByRIDRequestHeader
440 {
441     PrimitiveHeader Hdr;                      // 64 bit header
442     uint64_t LBID;
443     ColRequestHeaderDataType colType;
444     uint8_t OutputType;                          // 1 = RID, 2 = Token, 3 = Both
445     uint8_t BOP;                                 // 0 = N/A, 1 = AND, 2 = OR
446     uint8_t   ExtraNotUsed;
447     uint16_t NOPS;
448     uint16_t NVALS;
449     ColAggByRIDRequestHeader(); // Not used?
450 };
451 
452 //      Loopback Results
453 
454 struct LoopbackResultHeader
455 {
456     PrimitiveHeader Hdr;
457 };
458 
459 //      Column Results
460 
461 struct ColResultHeader
462 {
463     PrimitiveHeader Hdr;
464     uint64_t LBID;
465     uint8_t RidFlags;
466     uint16_t NVALS;
467     uint16_t ValidMinMax; 			  // 1 if Min/Max are valid, otherwise 0
468     uint32_t OutputType;
469     int64_t Min; 				  // Minimum value in this block (signed)
470     int64_t Max; 				  // Maximum value in this block (signed)
471     uint32_t CacheIO;				  // I/O count from buffer cache
472     uint32_t PhysicalIO;			  // Physical I/O count from disk
473 };
474 
475 //      Column Aggregate results
476 
477 struct ColAggResultHeader
478 {
479     PrimitiveHeader Hdr;
480     uint64_t LBID;
481     uint64_t MIN;                                // Minimum value in this block (signed)
482     uint64_t MAX;                                // Maximum value in this block (signed)
483     uint64_t SUM;                                // Sum of values in this block (unsigned)
484     uint32_t SUMOverflow;                        // Overflow of sum (unsigned)
485     uint16_t NVALS;                              // Number of values in this block
486     uint16_t Pad1;
487 };
488 
489 //      INDEX_BY_SCAN
490 
491 struct IndexByScanRequestHeader
492 {
493     PrimitiveHeader Hdr;
494     uint64_t LBID;
495     uint32_t State;
496     uint8_t  Flags;
497     uint8_t  DataSize;
498     uint8_t DataType;                            // enum ColDataType defined in calpont system catalog header file
499     uint8_t   ExtraNotUsed;
500     uint16_t NVALS;
501 };
502 
503 //      INDEX_BY_COMPARE
504 
505 struct IndexByCompareRequestHeader
506 {
507     PrimitiveHeader Hdr;
508     uint64_t LBID;
509     uint32_t State;
510     uint8_t  Flags;
511     uint8_t  DataSize;
512     uint8_t DataType;                            // enum ColDataType defined in calpont system catalog header file
513     uint8_t   ExtraNotUsed;
514     uint16_t NVALS;
515 };
516 
517 struct IndexResultHeader
518 {
519     PrimitiveHeader Hdr;
520     uint64_t LBID;
521     uint32_t State;
522     uint16_t NVALS;
523     uint16_t Pad;
524 };
525 
526 //  p_IdxWalk
527 
528 // this is used as input & output to the software p_IdxWalk processor.  Ideally
529 // there would only be one copy of the ISM and packet headers per returned result.
530 
531 #ifdef __cplusplus
532 struct IndexWalkHeader
533 {
534     ISMPacketHeader ism;
535     PrimitiveHeader Hdr;
536     uint64_t SearchString[2];
537     const std::vector<uint64_t>* SearchStrings;  //used only if NVALS > 2
538     uint8_t SSlen;                               // width of the search argument in BITS
539     uint8_t Shift;                                // initialize to zero when first sending to primitive
540     uint8_t BOP;
541     uint8_t COP1;
542     uint8_t COP2;
543     uint8_t State;                               //right now this is only 1 or 0, specifying entire subtrees
544     uint16_t NVALS;
545     uint64_t LBID: 36;
546     uint8_t SubBlock: 5;
547     uint8_t SBEntry: 5;
548 };
549 #endif
550 
551 // p_IdxList
552 
553 struct IndexListHeader
554 {
555     ISMPacketHeader ism;
556     PrimitiveHeader Hdr;
557     uint64_t LBID;
558     uint16_t NVALS;
559     uint16_t Pad1;
560     uint32_t Pad2;
561     // As the input parameter, what follows is IndexListParam[NVALS]
562     // As the output parameter, what follows is IndexListResult[NVALS]
563 };
564 
565 // p_IdxList parameter
566 struct IndexListParam
567 {
568     uint64_t type  : 3;                          // 0 - header, 4 - subblock, 5 - block
569     uint64_t spare : 15;
570     uint64_t fbo   : 36;
571     uint64_t sbid  : 5;
572     uint64_t entry : 5;
573 // 		int64_t listValue;
574 };
575 
576 struct IndexListEntry
577 {
578     uint64_t type  : 3;
579     uint64_t spare : 5;
580     uint64_t ridCt : 10;
581     uint64_t value : 46;
582 };
583 
584 struct IndexListResult
585 {
586     IndexListEntry entry;
587     int64_t listValue;
588 };
589 
590 enum IndexListType
591 {
592     LIST_SIZE      = 0,
593     EMPTY_LIST_PTR = 1,
594     EMPTY_PTR      = 2,
595     RID            = 3,
596     LLP_SUBBLK     = 4,
597     LLP_BLK        = 5,
598     PARENT		   = 6,
599     NOT_IN_USE     = 7
600 };
601 
602 //      DICT_TOKEN_BY_INDEX_COMPARE
603 struct DictTokenByIndexRequestHeader
604 {
605     PrimitiveHeader Hdr;
606     uint64_t LBID;
607     uint16_t NVALS;
608     uint16_t Pad1;
609     uint32_t Pad2;
610 };
611 
612 //      DICT_TOKEN_BY_SCAN_COMPARE
613 
614 struct DataValue
615 {
616     uint16_t len;
617     char data[];
618 };
619 
620 struct PrimToken
621 {
622     uint64_t LBID;
623     uint16_t offset;                             // measured in bytes
624     uint16_t len;                                // # of bytes
625 };
626 
627 // Masks for the flags member of TokenByScanRequestHeader
628 #define HAS_EQ_FILTER 0x1
629 #define IS_SYSCAT 0x2
630 
631 struct TokenByScanRequestHeader
632 {
633     ISMPacketHeader ism;
634     PrimitiveHeader Hdr;
635     uint64_t LBID;
636     int32_t CompType;
637     uint8_t COP1;
638     uint8_t COP2;
639     uint8_t BOP;
640     uint8_t OutputType;
641     uint16_t NVALS;
642     uint16_t flags;
643     uint32_t Pad2;
644     uint16_t Count;
645     uint32_t charsetNumber;
646 };                     // what follows is NVALS DataValues.
647 
648 // compatibility with Ron's stuff.
649 typedef TokenByScanRequestHeader DictTokenByScanRequestHeader;
650 
651 struct TokenByScanResultHeader
652 {
653     ISMPacketHeader ism;
654     PrimitiveHeader Hdr;
655     uint32_t NBYTES;
656     uint16_t NVALS;
657     uint16_t Pad1;
658     uint32_t CacheIO;				// I/O count from buffer cache
659     uint32_t PhysicalIO;			// Physical I/O count from disk
660 };                      // what follows is NVALS Tokens or DataValues.
661 
662 //      DICT_SIGNATURE
663 
664 struct DictSignatureRequestHeader
665 {
666     PrimitiveHeader Hdr;
667     uint64_t LBID;
668     int32_t CompType;
669     uint16_t NVALS;
670     uint16_t Pad1;
671     uint32_t Pad2;
672 };
673 //Tied to DictSignatureRequestHeader, note if modifying either.
674 struct DictSignatureRangeRequestHeader
675 {
676     PrimitiveHeader Hdr;
677     uint64_t LBID;
678     int32_t CompType;
679     uint16_t NVALS;
680     uint16_t Pad1;
681     uint32_t Pad2;
682     uint16_t Count;
683 };
684 
685 
686 //      DICT_AGGREGATE
687 
688 struct DictAggregateRequestHeader
689 {
690     PrimitiveHeader Hdr;
691     uint64_t LBID;
692     int32_t CompType;
693     uint16_t NVALS;
694     uint16_t Pad1;
695     uint32_t Pad2;
696 };
697 
698 struct DictResultHeader
699 {
700     PrimitiveHeader Hdr;
701     uint64_t LBID;
702     uint16_t NVALS;
703     uint16_t Pad1;
704     uint32_t Pad2;
705 };
706 
707 struct AggregateSignatureRequestHeader
708 {
709     ISMPacketHeader ism;
710     PrimitiveHeader hdr;
711     uint16_t NVALS;
712     PrimToken tokens[];
713 };
714 
715 struct AggregateSignatureResultHeader
716 {
717     ISMPacketHeader ism;
718     PrimitiveHeader hdr;
719     uint16_t Count;
720     // these implicitly follow the header
721     // DataValue min;
722     // DataValue max;
723 };
724 
725 /* An array of these structures defines a filter applied by p_Col.  The length
726  * of the val field should be the width of the column the filter will be applied
727  * to, ex: 4 bytes long for a 32-bit column.
728  */
729 struct ColArgs
730 {
731     uint8_t COP;
732     uint8_t rf;     // rounding flag: indicates if val is truncated or saturated
733     // for further evaluation of an equal condiction
734     int8_t val[];
735 };
736 
737 // const for rf
738 const uint8_t ROUND_POS = 0x01;  // actual value larger/longer than the stored value
739 const uint8_t ROUND_NEG = 0x80;  // actual value less than the stored value
740 
741 //Tied to ColByScanRequestHeader and ColByScanRangeRequestHeader.  Check other headers if modifying.
742 struct NewColRequestHeader
743 {
744     ISMPacketHeader ism;
745     PrimitiveHeader hdr;
746     uint64_t LBID;
747     ColRequestHeaderDataType colType;
748     uint8_t OutputType;		// OT_DATAVALUE, OT_RID, or OT_BOTH
749     uint8_t BOP;
750 // 	uint8_t InputFlags;		// 1 = interpret each NOP & RID as a pair (deprecated)
751     uint8_t RidFlags;		// a bitmap indicating the rid ranges in the result MSB => row 7168-8191
752     uint16_t NOPS;
753     uint16_t NVALS;
754     uint8_t sort;				//1 to sort
755     // this follows the header
756     // ColArgs ArgList[NOPS] (where the val field is DataSize bytes long)
757     // uint16_t Rids[NVALS]  (each rid is relative to the given block)
758 
759     // QQ: The below constructor is never used.
760     // This struct is used in a cast only, in a hackish way.
761     NewColRequestHeader();
762 };
763 
764 struct NewColAggRequestHeader
765 {
766     ISMPacketHeader ism;
767     PrimitiveHeader hdr;
768     uint64_t LBID;
769     ColRequestHeaderDataType colType;
770     uint8_t OutputType;
771     uint8_t BOP;
772     uint8_t ExtraNotUsed;
773     uint16_t NOPS;
774     uint16_t NVALS;
775     // this follows the header
776     // ColArgs ArgList[NOPS] (where the val field is DataSize bytes long)
777     // uint16_t Rids[NVALS] (each rid is relative to the given block)
778     NewColAggRequestHeader(); // QQ: not used
779 };
780 
781 struct NewColResultHeader
782 {
783     ISMPacketHeader ism;
784     PrimitiveHeader hdr;
785     uint64_t LBID;
786     uint8_t RidFlags;
787     uint16_t NVALS;
788     uint16_t ValidMinMax;		// 1 if Min/Max are valid, otherwise 0
789     uint32_t OutputType;
790     int64_t Min; 			    // Minimum value in this block for signed data types
791     int64_t Max; 			    // Maximum value in this block for signed data types
792     uint32_t CacheIO;			// I/O count from buffer cache
793     uint32_t PhysicalIO;		// Physical I/O count from disk
794     // if OutputType was OT_DATAVALUE, what follows is DataType[NVALS]
795     // if OutputType was OT_RID, what follows is uint16_t Rids[NVALS]
796     // if OutputType was OT_BOTH, what follows is NVALS <Rid, DataType> pairs
797 };
798 
799 /* additional types to support p_dictionary */
800 struct DictFilterElement
801 {
802     uint8_t COP;
803     uint16_t len;  // this is the length of data, not the size of the entire entry
804     uint8_t data[];
805 };
806 
807 struct DictInput
808 {
809     ISMPacketHeader ism;
810     PrimitiveHeader hdr;
811     uint64_t LBID;
812     uint8_t BOP;
813     uint8_t InputFlags;		// 1 -> 64-bit RID, 64-bit token pairs (old p_GetSignature behavior),
814     // 0-> new behavior
815     uint8_t OutputType;
816     uint16_t NOPS;
817     uint16_t NVALS;
818     PrimToken tokens[];   // NVALS of these.
819     // DictFilterElement[NOPS] filter;
820 };
821 
822 struct DictAggregate
823 {
824     uint16_t Count;
825     // DataValue min;
826     // DataValue max;
827 };
828 
829 struct DictOutput
830 {
831     ISMPacketHeader ism;
832     PrimitiveHeader hdr;
833     uint64_t LBID;
834     uint16_t NVALS;
835     uint16_t Pad;
836     uint32_t NBYTES;
837     uint32_t CacheIO;				// I/O count from buffer cache
838     uint32_t PhysicalIO;			// Physical I/O count from disk
839     // What follows this header depends on OutputType.
840     // for each NVAL, what follows is ...
841     //   if OutputType | OT_RID & InputFlags==1, the 64-bit RID associated with the input token
842     //   if OutputType | OT_TOKEN, a PrimToken
843     //   if OutputType | OT_DATAVALUE, a DataValue containing the string in the dict block
844     //   if OutputType | OT_INPUT, a DataValue containing the first filter string...
845     //        ... that matched (only makes sense when BOP is OR).
846     // DictAggregate agg;  (if OutputType | OT_AGGREGATE)
847 };		//same as TokenByScanResultHeader at the moment
848 
849 struct OldGetSigParams
850 {
851     uint64_t rid;
852     uint16_t offsetIndex;
853 };
854 
855 struct LbidAtVer
856 {
857     uint64_t LBID;
858     uint32_t Ver;
859 };
860 
861 #ifdef _MSC_VER
862 #pragma warning (pop)
863 #endif
864 
865 #pragma pack(pop)
866 
867 #ifdef __cplusplus
868 }
869 #endif
870 
871 #endif //JOBLIST_PRIMITIVE_H
872 // vim:ts=4 sw=4:
873 
874