forked from yongwen/columbia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
supp.h
1228 lines (1006 loc) · 31.8 KB
/
supp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
SUPP.H - Classes which support optimization and are used throughout.
$Revision: 10 $
Columbia Optimizer Framework
A Joint Research Project of Portland State University
and the Oregon Graduate Institute
Directed by Leonard Shapiro and David Maier
Supported by NSF Grants IRI-9610013 and IRI-9619977
*/
#ifndef SUPP_H
#define SUPP_H
#include "stdafx.h" // general definitions
class SET_TRACE; // set trace flag
class OPT_STAT; // opt statistics
class CLASS_STAT; // class statistics
//Properties of stored objects, including physical and logical properties.
class COLL_PROP; //Collections
class IND_PROP; //Indexes
class ATTR; // Attribute
class SCHEMA; //Includes a set of attributes, some may be equivalent
class LOG_PROP; //Abstract class of logical properties.
class LOG_COLL_PROP; //For collection types
class LOG_ITEM_PROP; //For items (predicates)
class PHYS_PROP; //Physical Properties
class CONT; //Context: Conditions/Constraints on a search
class COST; //Cost of a physical operator or expression
// This class manages tracing.
// SET_TRACE(false) turns off tracing until the function exits, similar for on.
//##ModelId=3B0C085F0182
class SET_TRACE
{
private:
//##ModelId=3B0C085F018C
bool OldTrace;
public:
//##ModelId=3B0C085F01A0
SET_TRACE(bool DoTrace)
{
TraceDepth++;
OldTrace = TraceOn;
if( !WindowTrace && !FileTrace )
{ TraceOn = false; return; }
TraceOn = DoTrace;
}
//##ModelId=3B0C085F01AA
~SET_TRACE()
{
TraceDepth--;
TraceOn = OldTrace; // default is false, no trace
}
}; // class SET_TRACE
// class statistics
//##ModelId=3B0C085F01C8
class CLASS_STAT
{
public:
//##ModelId=3B0C085F01D2
CString Name; // the name of the class
//##ModelId=3B0C085F01E6
int Size; // the size of the class
//##ModelId=3B0C085F01F0
int Count; // the count of the class being allocated
//##ModelId=3B0C085F01FA
int Max; // the max count of the class
//##ModelId=3B0C085F0204
int Total; // the total count
public:
//##ModelId=3B0C085F0218
CLASS_STAT(CString name, int size)
: Name(name),Size(size),Count(0),Max(0), Total(0)
{};
//##ModelId=3B0C085F0222
void New() { Count++; Total++; if(Count>Max) Max = Count; };
//##ModelId=3B0C085F0223
void Delete() { Count--; };
//##ModelId=3B0C085F022C
CString Dump()
{ CString os ;
os.Format("MemUse = %d, %-16s --- Size = %d, Total = %d , Max = %d , Count = %d\r\n",
Max*Size, Name, Size, Total, Max, Count );
return os;
};
}; // class CLASS_STAT
// other statistics
//##ModelId=3B0C085F025E
class OPT_STAT
{
public:
//##ModelId=3B0C085F0268
int TotalMExpr;
//##ModelId=3B0C085F0272
int DupMExpr ;
//##ModelId=3B0C085F0287
int HashedMExpr;
//##ModelId=3B0C085F0291
int MaxBucket;
//##ModelId=3B0C085F029B
int FiredRule ;
//##ModelId=3B0C085F02A5
OPT_STAT() : TotalMExpr(0),DupMExpr(0),FiredRule(0),
HashedMExpr(0),MaxBucket(0)
{};
//##ModelId=3B0C085F02AF
CString Dump();
}; // class OPT_STAT
/*
============================================================
ORDERED SET OF ATTRIBUTES - class KEYS_SET
============================================================
*/
//Used for keys when sorted, hashed. That's why order matters.
//Also used for conditions (cf. eqjoin)
//##ModelId=3B0C085F034F
class KEYS_SET
{
private:
//A set of attribute names
//##ModelId=3B0C085F0359
CArray< int , int > KeyArray;
public:
//##ModelId=3B0C085F036D
KEYS_SET() {if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_KEYS_SET].New();};
//##ModelId=3B0C085F0377
KEYS_SET(int * array, int size)
{
if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_KEYS_SET].New();
KeyArray.SetSize(size);
for(int i=0; i<size; i++) KeyArray[i] = array[i];
}
//##ModelId=3B0C085F0381
KEYS_SET(KEYS_SET& other) // copy constructor
{
if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_KEYS_SET].New();
KeyArray.Copy(other.KeyArray);
};
//##ModelId=3B0C085F038B
KEYS_SET& operator= (KEYS_SET& other) // = operator
{
KeyArray.Copy(other.KeyArray);
return *this;
};
//##ModelId=3B0C085F038D
~KEYS_SET()
{
if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_KEYS_SET].Delete();
};
//return FALSE if duplicate found, and don't add it to the ordered set.
//##ModelId=3B0C085F0395
bool AddKey(CString CollName,CString KeyName) ;
//##ModelId=3B0C085F03A9
bool AddKey(int AttId);
// check if the attid is in the keys_Set
//##ModelId=3B0C085F03B3
bool ContainKey(int AttId);
//Transform each element from A.B to NewName.B (actually the IDs)
//##ModelId=3B0C085F03BD
void update(CString NewName);
// return int array from the keys_set
//##ModelId=3B0C085F03C7
int * CopyOut();
// return int array of size one from the keys_set
//##ModelId=3B0C085F03D1
int * CopyOutOne(int i);
// merge keys, ignore duplicates
//##ModelId=3B0C085F03DB
inline void Merge(KEYS_SET& other)
{
for(int i=0; i<other.GetSize(); i++) AddKey(other[i]);
}
// return the CString in the order Set
//##ModelId=3B0C085F03E5
inline int& operator[](int n) { return KeyArray[n];}
// return the number of the keys
//##ModelId=3B0C08600007
inline int GetSize() { return KeyArray.GetSize(); }
// decrements the size of key array
//##ModelId=3B0C08600011
inline void SetSize() { KeyArray.SetSize(GetSize()-1); }
//sets the size of key array
//##ModelId=3B0C0860001B
inline void SetSize(int newsize) {KeyArray.SetSize(newsize);}
//##ModelId=3B0C08600025
bool operator== (KEYS_SET& other) // = operator
{
if(GetSize() != other.GetSize()) return false;
for(int i=0; i< GetSize(); i++)
if( KeyArray[i] != other[i] )
return false;
return true; // they are identical
};
//##ModelId=3B0C0860002F
bool Equal(int * array, int size)
{
if(GetSize() != size) return false;
for(int i=0; i< size; i++)
if( KeyArray[i] != array[i] )
return false;
return true; // they are identical
}
//##ModelId=3B0C08600039
bool IsSubSet(int * array, int size)
{
if(GetSize() > size) return false;
int i, j;
for(i=0; i< GetSize(); i++)
for (j=0; j<size; j++)
if( KeyArray[i] == array[j]) break;
if (j==size) return false; //not in array
return true; // this keys_set is contained in array
}
// Remove the KEYS_SET with AttId = val
//##ModelId=3B0C08600043
bool RemoveKeysSet(int val)
{
if(val > GetSize()) return false;
for (int k=val; k< GetSize()-1; k++)
KeyArray[k] = KeyArray[k+1];
SetSize();
return true;
}
// choose the attribute with max cucard value
//##ModelId=3B0C0860004D
int ChMaxCuCard();
// get the cucard of the attribute
//##ModelId=3B0C0860004E
float GetAttrCuCard(int);
//##ModelId=3B0C08600061
CString Dump();
//##ModelId=3B0C08600062
void reset() {KeyArray.SetSize(0);};
//KEYS_SET* best();
};
//foreign key
//##ModelId=3B0C086000A7
class FOREIGN_KEY
{
public:
//##ModelId=3B0C086000C5
KEYS_SET *ForeignKey;
//##ModelId=3B0C086000DA
KEYS_SET *RefKey;
//##ModelId=3B0C086000ED
FOREIGN_KEY(KEYS_SET *FKeys, KEYS_SET *RKeys): ForeignKey(FKeys), RefKey(RKeys) {};
//##ModelId=3B0C08600101
FOREIGN_KEY(FOREIGN_KEY& other) // copy constructor
{
ForeignKey = new KEYS_SET(*other.ForeignKey);
RefKey = new KEYS_SET(*other.RefKey);
};
//##ModelId=3B0C0860010B
~FOREIGN_KEY()
{
delete ForeignKey;
delete RefKey;
}
//##ModelId=3B0C0860010C
CString Dump();
//##ModelId=3B0C08600115
void update(CString NewName)
{
ForeignKey->update(NewName);
}
};
/*
============================================================
PROPERTIES OF STORED OBJECTS- classes COLL_PROP, ATT_PROP and IND_PROP
============================================================
*/
//Properties of Stored Collections
//##ModelId=3B0C086001B6
class COLL_PROP
{
public:
//Logical Properties
//##ModelId=3B0C086001C0
float Card; //Cardinality
//##ModelId=3B0C086001CA
float UCard; //Unique Cardinality
//##ModelId=3B0C086001DE
float Width; //width of the table, fraction of a block
//Beware - this does not delete *Keys.
//##ModelId=3B0C086001E8
COLL_PROP& operator= (COLL_PROP& other) // = operator
{
Keys = new KEYS_SET(*other.Keys);
CandidateKey = new KEYS_SET(*other.CandidateKey);
for (int i=0; i<other.FKeyArray.GetSize(); i++)
{
FOREIGN_KEY * fk = new FOREIGN_KEY(*other.FKeyArray[i]);
FKeyArray.Add(fk);
}
Card = other.Card;
UCard = other.UCard;
Width = other.Width;
Order = other.Order;
if (Order == sorted)
for (int i=0; i<other.KeyOrder.GetSize(); i++)
KeyOrder.Add(other.KeyOrder[i]);
return *this;
};
//Physical properties
//##ModelId=3B0C086001F3
ORDER Order; //any, heap, sorted or hashed
//##ModelId=3B0C08600207
KEYS_SET * Keys; //Keys on which sorted or hashed
//null if heap or any, nonnull otherwise
//##ModelId=3B0C08600225
KeyOrderArray KeyOrder; //if order is sorted, nonnull
// need ascending/descending for each key
//the candidate keys
//##ModelId=3B0C08600239
KEYS_SET * CandidateKey;
//##ModelId=3B0C0860024D
CArray <FOREIGN_KEY *, FOREIGN_KEY *> FKeyArray;
// initialize member with -1, i.e.,not known
//##ModelId=3B0C08600260
COLL_PROP():Card(-1),UCard(-1)
{};
//Transform all keys in the properties to new name
//##ModelId=3B0C0860026A
void update(CString NewName);
//##ModelId=3B0C08600274
~COLL_PROP()
{
delete Keys;
delete CandidateKey;
for (int i=0; i<FKeyArray.GetSize(); i++)
delete FKeyArray[i];
};
//##ModelId=3B0C0860027E
CString Dump();
//copy constructor
//##ModelId=3B0C08600288
COLL_PROP(COLL_PROP& other);
//store the foreign key strings, translated to foreign keys at the end of CAT
//##ModelId=3B0C0860029D
STRING_ARRAY ForeignKeyString;
};
//Index Properties
//##ModelId=3B0C0860030A
class IND_PROP
{
public :
//##ModelId=3B0C08600314
IND_PROP() { };
//##ModelId=3B0C0860031E
~IND_PROP() { delete Keys; };
//##ModelId=3B0C08600328
IND_PROP& operator= (IND_PROP& other) // = operator
{
Keys = new KEYS_SET(*other.Keys);
IndType = other.IndType;
Clustered = other.Clustered;
return *this;
};
//Physical Properties
//##ModelId=3B0C08600333
KEYS_SET * Keys; //Index is on this ordered set of attributes
//##ModelId=3B0C08600347
ORDER_INDEX IndType;//hash or sort (Btree)
//##ModelId=3B0C0860035A
bool Clustered;
//Transform each key from A.X to NewName.X
//##ModelId=3B0C08600364
void update(CString NewName);
//##ModelId=3B0C08600378
CString Dump();
};
//Bit Index Properties
//##ModelId=3B0C08610008
class BIT_IND_PROP
{
public:
//##ModelId=3B0C08610013
KEYS_SET *BitAttr; //attributes for which all values are bit indexed
//##ModelId=3B0C08610027
int IndexAttr; //indexing attributes -- this is the key of the table
//it is dense key. we assume it is integer type
//bit indexes are only allowed for tables with single
// attibute keys
//##ModelId=3B0C08610031
CString BitPredString; // assume store the index for each predicate separately
//##ModelId=3B0C08610045
CString IndexAttrString;
//##ModelId=3B0C08610059
BIT_IND_PROP() {};
//##ModelId=3B0C08610077
~BIT_IND_PROP() {delete BitAttr;} ;
//##ModelId=3B0C08610078
void update(CString NewName);
//##ModelId=3B0C0861008B
CString Dump();
//##ModelId=3B0C0861008C
BIT_IND_PROP& operator= (BIT_IND_PROP& other) // = operator
{
BitAttr = new KEYS_SET(*other.BitAttr);
IndexAttr = other.IndexAttr;
return *this;
};
};
/*
============================================================
ATTR - Attribute
============================================================
*/
//##ModelId=3B0C0861015D
class ATTR
{
public:
//##ModelId=3B0C08610171
int AttId;
//##ModelId=3B0C0861017B
float CuCard ; //cardinality
//##ModelId=3B0C08610185
float Max; //max, min value
//##ModelId=3B0C0861018F
float Min;
//##ModelId=3B0C08610199
ATTR()
{ if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_ATTR].New(); };
//##ModelId=3B0C086101A3
ATTR(const int attId, const float CuCard, const float min, const float max)
:AttId(attId), CuCard(CuCard), Min(min), Max(max)
{ if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_ATTR].New(); };
//##ModelId=3B0C086101B0
ATTR(CString range_var, int * atts, int size);
//##ModelId=3B0C086101C1
ATTR(ATTR& other)
:AttId(other.AttId), CuCard(other.CuCard), Min(other.Min), Max(other.Max)
{ if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_ATTR].New(); };
//##ModelId=3B0C086101CB
~ATTR()
{ if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_ATTR].Delete();};
//##ModelId=3B0C086101CC
CString Dump();
//##ModelId=3B0C086101D5
CString attrDump();
//##ModelId=3B0C086101D6
CString DumpCOVE();
// the following is used by Bill's Memory Manager
// Redefine new and delete if memory manager is used.
#ifdef USE_MEMORY_MANAGER // use bill's memory manager
public:
//##ModelId=3B0C086101EA
static BLOCK_ANCHOR * _anchor ;
public:
// overload the new and delete methods
//##ModelId=3B0C086101F3
inline void * operator new(size_t my_size)
{ return memory_manager -> allocate(&_anchor, (int) my_size); }
//##ModelId=3B0C086101FE
inline void operator delete(void * dead_elem, size_t )
{ memory_manager -> deallocate(_anchor, dead_elem) ; }
#endif
}; // class ATTR
/*
============================================================
SCHEMA - Structure of a Group: attributes and their properties
============================================================
*/
// Think of each group as a temporary relation, which has a schema. The schema
// is a set of attributes, plus information about which attributes are equivalent
// (attributes are made equivalent by joins on them).
// An attribute is represented by a path name plus the name of the attribute,
// e.g. Emp plus age.
//##ModelId=3B0C086103AC
class SCHEMA
{
private:
//##ModelId=3B0C086103B7
ATTR ** Attrs; //Attributes
//##ModelId=3B0C086103CA
int Size; // number of the attrs
public:
//##ModelId=3B0C086103DE
int * TableId; // Base tables appearing in this schema - used for calculating Max cucards
// for each base table in a schema, and for calculating log prop of aggregate.
//##ModelId=3B0C08620000
int TableNum; // number of the tables
public:
//Make space for n attrs
//##ModelId=3B0C0862000A
SCHEMA(int n) : Size(n)
{
if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_SCHEMA].New();
assert(Size>=0);
Attrs = new ATTR* [Size];
};
//##ModelId=3B0C08620015
SCHEMA(SCHEMA & other) : Size(other.Size), TableNum(other.TableNum)
{
int i;
if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_SCHEMA].New();
assert(Size>=0);
Attrs = new ATTR* [Size];
for(i=0; i<Size; i++) Attrs[i] = new ATTR(*(other[i]));
TableId = new int [TableNum];
for(i=0; i<TableNum; i++) TableId[i] = other.GetTableId(i) ;
}
//##ModelId=3B0C0862001F
~SCHEMA();
//return FALSE if duplicate found
//##ModelId=3B0C08620028
bool AddAttr(int Index, ATTR *attr);
// return true if the attr is in the schema
//##ModelId=3B0C08620033
bool InSchema(int AttId);
// return true if contains all the keys
//##ModelId=3B0C0862003D
bool Contains( KEYS_SET * Keys);
// projection of attrs onto schema
//##ModelId=3B0C08620047
SCHEMA * projection( int * attrs, int size);
// union the schema of the joined collection
//##ModelId=3B0C0862005A
SCHEMA * UnionSchema(SCHEMA *other);
// return the nth attr in the schema
//##ModelId=3B0C08620064
inline ATTR* operator[](int n) { return Attrs[n];}
//##ModelId=3B0C0862006E
inline int GetSize() { return Size; }
// number of Tables in the schema
//##ModelId=3B0C08620078
inline int GetTableNum() { return TableNum; };
// max cucard of each tables in the schema
//##ModelId=3B0C08620079
float GetTableMaxCuCard(int TableIndex);
// width of each tables in the schema
//##ModelId=3B0C08620083
float GetTableWidth(int TableIndex);
// CollId of the table
//##ModelId=3B0C0862008D
inline int GetTableId(int TableIndex) { return TableId[TableIndex]; };
// store the key-sets of all attributes in the schema
//##ModelId=3B0C086200A0
KEYS_SET* AttrStore();
//##ModelId=3B0C086200A1
CString Dump();
//##ModelId=3B0C086200AA
CString DumpCOVE();
// the following is used by Bill's Memory Manager
// Redefine new and delete if memory manager is used.
#ifdef USE_MEMORY_MANAGER // use bill's memory manager
public:
//##ModelId=3B0C086200B5
static BLOCK_ANCHOR * _anchor ;
public:
// overload the new and delete methods
//##ModelId=3B0C086200C8
inline void * operator new(size_t my_size)
{ return memory_manager -> allocate(&_anchor, (int) my_size); }
//##ModelId=3B0C086200D2
inline void operator delete(void * dead_elem, size_t )
{ memory_manager -> deallocate(_anchor, dead_elem) ; }
#endif
}; //class SCHEMA
/*
============================================================
class LOG_PROP - LOGICAL PROPERTIES
============================================================
*/
//##ModelId=3B0C08620140
class LOG_PROP
{
//Abstract Class so an operator can deal with input logical properties of
//all types of inputs: collection, item, and whatever else is defined.
public:
//##ModelId=3B0C08620154
LOG_PROP() {};
//##ModelId=3B0C08620155
virtual ~LOG_PROP() {};
//##ModelId=3B0C0862015E
virtual CString Dump()=0;
//##ModelId=3B0C08620160
virtual CString DumpCOVE()=0;
}; //class LOG_PROP
/*
============================================================
LOG_COLL_PROP: LOGICAL PROPERTIES OF COLLECTIONS
============================================================
*/
//##ModelId=3B0C08620259
class LOG_COLL_PROP: public LOG_PROP
{
public:
//##ModelId=3B0C0862026D
const float Card; //Cardinality
//##ModelId=3B0C08620277
const float UCard; //Unique Cardinality
//##ModelId=3B0C0862028C
SCHEMA * const Schema; // schema includes the column unique
// cardinalities
//##ModelId=3B0C086202A0
KEYS_SET * CandidateKey; // candidate key
//##ModelId=3B0C086202B4
CArray <FOREIGN_KEY *, FOREIGN_KEY *> FKeyList;
//##ModelId=3B0C086202C7
LOG_COLL_PROP(float card, float ucard, SCHEMA * schema, KEYS_SET * cand_keys=NULL)
:Card(card),UCard(ucard),Schema(schema), CandidateKey(cand_keys)
{if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_LOG_COLL_PROP].New(); };
/* LOG_COLL_PROP(LOG_COLL_PROP & other) : Card(other.Card), UCard(other.UCard),
Schema(other.Schema)
{
CandidateKey = NULL;
if (other.CandidateKey)CandidateKey = new KEYS_SET(*other.CandidateKey);
};
*/
//##ModelId=3B0C086202DC
~LOG_COLL_PROP()
{ delete Schema;
delete CandidateKey;
for(int i=0;i<FKeyList.GetSize();i++)
delete FKeyList[i];
if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_LOG_COLL_PROP].Delete();
};
//##ModelId=3B0C086202E5
CString Dump();
//##ModelId=3B0C086202E6
CString DumpCOVE();
// the following is used by Bill's Memory Manager
// Redefine new and delete if memory manager is used.
#ifdef USE_MEMORY_MANAGER // use bill's memory manager
public:
//##ModelId=3B0C086202FA
static BLOCK_ANCHOR * _anchor ;
public:
// overload the new and delete methods
//##ModelId=3B0C08620303
inline void * operator new(size_t my_size)
{ return memory_manager -> allocate(&_anchor, (int) my_size ); }
//##ModelId=3B0C08620317
inline void operator delete(void * dead_elem, size_t )
{ memory_manager -> deallocate(_anchor, dead_elem) ; }
#endif
}; //class LOG_COLL_PROP
/*
============================================================
LOGICAL PROPERTIES OF ITEMS
============================================================
*/
//##ModelId=3B0C086203DF
class LOG_ITEM_PROP: public LOG_PROP
{
public:
//##ModelId=3B0C08630002
float Max;
//##ModelId=3B0C0863000B
float Min;
//##ModelId=3B0C0863001F
float CuCard;
//##ModelId=3B0C08630029
float Selectivity;
//##ModelId=3B0C0863003E
KEYS_SET FreeVars;
public:
//##ModelId=3B0C08630047
LOG_ITEM_PROP(float max, float min, float CuCard,
float selectivity, KEYS_SET & freevars)
:Max(max),Min(min),CuCard(CuCard),
Selectivity(selectivity),FreeVars(freevars)
{ if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_LOG_ITEM_PROP].New();};
//##ModelId=3B0C08630065
~LOG_ITEM_PROP() {if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_LOG_ITEM_PROP].Delete();};
//##ModelId=3B0C08630066
CString Dump()
{ CString os;
os.Format("Max : %.0f, Min : %.0f, CuCard : %.0f, Selectivity : %.3f, FreeVars : %s\r\n",
Max, Min, CuCard, Selectivity, FreeVars.Dump() );
return os;
};
// Temporary, till we use LOG_ITEM_PROPs in COVE
//##ModelId=3B0C08630070
CString LOG_ITEM_PROP::DumpCOVE()
{
CString os = "Error";
//os.Format("%d %d %s%s%s \r\n",Card, UCard, "{", (*Schema).DumpCOVE(), "}");
return os;
};
}; //class LOG_ITEM_PROP
/*
============================================================
PHYS_PROP: PHYSICAL PROPERTIES
============================================================
*/
// Physical properties of collections. These properites
// distinguish collections which are logically equivalent. Examples
// are orderings, data distribution, data compression, etc.
// Normally, a plan could have > 1 physical property. For now,
// we will work with hashing and sorting only, so we assume a plan
// can have only one physical property. Extensions should be
// tedious but not too hard.
//##ModelId=3B0C086301EC
class PHYS_PROP
{
public:
//##ModelId=3B0C08630201
const ORDER Order; //any, heap, sorted or hashed
//##ModelId=3B0C08630215
KEYS_SET * Keys; //Keys on which sorted or hashed
//null if heap or any, nonnull otherwise
//##ModelId=3B0C08630233
KeyOrderArray KeyOrder; //if order is sorted
// need ascending/descending for each key
public:
// PHYS_PROP(KeyOrderArray *KeyOrder, KEYS_SET * Keys, ORDER Order);
//##ModelId=3B0C0863023C
PHYS_PROP(KEYS_SET * Keys, ORDER Order);
//##ModelId=3B0C08630250
PHYS_PROP(ORDER Order);
//##ModelId=3B0C0863025A
PHYS_PROP(PHYS_PROP& other);
//##ModelId=3B0C08630264
~PHYS_PROP()
{ if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_PHYS_PROP].Delete();
if (Order != any) delete Keys;
//if (Order == sorted) delete [] KeyOrder;
}
//##ModelId=3B0C08630265
ORDER GetOrder() {return(Order);}
//##ModelId=3B0C0863026E
KEYS_SET *GetKeysSet() { return(Keys); }
//##ModelId=3B0C0863026F
void SetKeysSet(KEYS_SET* NewKeys) { Keys = NewKeys; }
// merge other phys_prop in
//##ModelId=3B0C08630279
void Merge(PHYS_PROP& other);
//##ModelId=3B0C0863028C
void bestKey();//returns the key and keyorder of the key
//with the most distinct values
//##ModelId=3B0C0863028D
bool operator== (PHYS_PROP & other);
//##ModelId=3B0C08630296
CString Dump();
//##ModelId=3B0C086302A0
CString DumpCOVE();
}; //class PHYS_PROP
/*
============================================================
COST - cost of executing a physical operator, expression or multiexpression
============================================================
COST cannot be associated with a multiexpression, since cost is determined
by properties desired. For example, a SELECT will cost
more if sorted is required.
COST value of -1 = infinite cost. Any other negative cost
is considered an error.
*/
//##ModelId=3B0C08640085
class COST
{
private:
//##ModelId=3B0C08640099
double Value; //Later this may be a base class specialized
//to various costs: CPU, IO, etc.
public:
//##ModelId=3B0C086400A3
COST(double Number): Value(Number)
{ assert(Number == -1 || Number >= 0);
if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_COST].New();
} ;
//##ModelId=3B0C086400AD
COST(COST& other): Value(other.Value)
{ if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_COST].New(); };
//##ModelId=3B0C086400AF
~COST() { if (TraceOn && !ForGlobalEpsPruning) ClassStat[C_COST].Delete();};
//FinalCost() makes "this" equal to the total of local and input costs.
// It is an error if any input is null.
// In a parallel environment, this may involve max.
//##ModelId=3B0C086400B7
void FinalCost (COST * LocalCost, COST ** TotalInputCost, int Size);
//##ModelId=3B0C086400C3
inline COST& operator+=( const COST &other)
{
if(Value==-1 || other.Value==-1) // -1 means Infinite
Value = -1;
else
Value += other.Value;
return ( *this );
}
//##ModelId=3B0C086400CC
inline COST& operator*=( double EPS)
{
assert( EPS > 0 ) ;
if(Value==-1) // -1 means Infinite
Value = 0;
else
Value *= EPS;
return ( *this );
}
//##ModelId=3B0C086400D6
inline COST& operator/=( int arity)
{
assert( arity > 0 ) ;
if(Value==-1) // -1 means Infinite
Value = 0;
else
Value /= arity;
return ( *this );
}
//##ModelId=3B0C086400E0
inline COST& operator-=( const COST &other)
{
if(Value==-1 || other.Value==-1) // -1 means Infinite
Value = -1;
else
Value -= other.Value;
return ( *this );
}
//##ModelId=3B0C086400EA
inline COST& operator=( const COST &other)
{
this->Value = other.Value;
return ( *this );
}
//##ModelId=3B0C086400F4
inline bool operator>=( const COST &other)
{
if(Value==-1)
return (true);
if(other.Value == -1) // -1 means Infinite
return(false);
return ( this->Value >= other.Value );
}
//##ModelId=3B0C086400FE
inline COST& operator*( double EPS)
{
assert( EPS >= 0 ) ;
COST *temp ;
if(Value==-1) // -1 means Infinite
temp = new COST (0);
else
temp = new COST (Value * EPS);
return (*temp);
}