PostgreSQL Source Code: src/backend/utils/adt/rangetypes_selfuncs.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
19
20#include <math.h>
21
26#include "utils/fmgrprotos.h"
31
37 Oid operator);
61
62
63
64
65
66static double
68{
69 switch (operator)
70 {
72 return 0.01;
73
76 return 0.005;
77
80
81
82
83
84
86
95
97
98 default:
99
100 return 0.01;
101 }
102}
103
104
105
106
109{
120
121
122
123
124
128
129
130
131
133 {
136 }
137
138
139
140
141
143 {
146 }
147
148
149
150
151
153 {
154
156 if (!operator)
157 {
158
161 }
162 }
163
164
165
166
167
168
169
170
171
172
173
174
176 {
178
180 {
183
186 lower.infinite = false;
187 lower.lower = true;
188 upper.inclusive = true;
190 upper.infinite = false;
191 upper.lower = false;
193 }
194 }
196 {
197
198
199
200
201
202
203 }
205 {
206
208
210 }
211
212
213
214
215
216
217
220 else
222
224
226
228}
229
230static double
233{
238
239
240
241
243 {
246
249
250
255 {
256 if (sslot.nnumbers != 1)
257 elog(ERROR, "invalid empty fraction statistic");
260 }
261 else
262 {
263
265 }
266 }
267 else
268 {
269
270
271
272
273
274
277 }
278
280 {
281
282
283
284
285 switch (operator)
286 {
287
293
296 break;
297
298
300
303 break;
304
305
307
310 break;
311
312
315 break;
316
317
319 default:
320 elog(ERROR, "unexpected operator %u", operator);
321 selec = 0.0;
322 break;
323 }
324 }
325 else
326 {
327
328
329
330
331
332
333
334
336 operator);
339
340
341
342
343
344
346 {
347
349 }
350 else
351 {
352
354 }
355 }
356
357
359
360
362
364}
365
366
367
368
369
370
371
372static double
375{
381 int i;
384 bool empty;
386
387
390 return -1;
394 return -1;
395
396
401 return -1.0;
402
403
404 if (hslot.nvalues < 2)
405 {
407 return -1.0;
408 }
409
410
411
412
413
418 {
421
422 if (empty)
423 elog(ERROR, "bounds histogram contains an empty range");
424 }
425
426
429 {
435 {
437 return -1.0;
438 }
439
440
441 if (lslot.nvalues < 2)
442 {
445 return -1.0;
446 }
447 }
448 else
450
451
454
455
456
457
458
459 switch (operator)
460 {
462
463
464
465
466
467
468
469
470
474 break;
475
480 break;
481
486 break;
487
492 break;
493
495
499 break;
500
502
506 break;
507
509
513 break;
514
516
520 break;
521
524
525
526
527
528
529
530
531
532
533
534
535
543 break;
544
550 break;
551
554 {
555
556
557
558
562 }
564 {
568 }
569 else
570 {
575 }
576 break;
577
578 default:
579 elog(ERROR, "unknown range operator %u", operator);
580 hist_selec = -1.0;
581 break;
582 }
583
586
588}
589
590
591
592
593
594
595static double
598{
601
602
603
604
605
608
609
613
615}
616
617
618
619
620
621
622
623
624
625
626
627static int
630{
635
637 {
640
643 else
645 }
647}
648
649
650
651
652
653
654
655
656static int
659{
663
665 {
667
669
673 else
675 }
677}
678
679
680
681
685{
688
689 if (->infinite &&
->infinite)
690 {
692
693
694
695
696
697
698
699 if (value->infinite)
700 return 0.5;
701
702
704 return 0.5;
705
706
712 return 0.5;
713
719
720 if (isnan(position))
721 return 0.5;
722
723
724 position = Max(position, 0.0);
725 position = Min(position, 1.0);
726 return position;
727 }
728 else if (hist1->infinite && ->infinite)
729 {
730
731
732
733
734
735
736 return ((value->infinite && value->lower) ? 0.0 : 1.0);
737 }
738 else if (->infinite && hist2->infinite)
739 {
740
741 return ((value->infinite && ->lower) ? 1.0 : 0.0);
742 }
743 else
744 {
745
746
747
748
749
750
751
752
753 return 0.5;
754 }
755}
756
757
758
759
760
761static double
763{
765 {
766
767
768
769
770
772 return 0.5;
773
775 }
777 {
778
779
780
781
782 return 1.0;
783 }
785 {
786
787 return 0.0;
788 }
789 else
790 {
791
792
793
794
795
796
797
798
799 return 0.5;
800 }
801}
802
803
804
805
808{
810
812 {
813
814
815
816
818 {
820
825
826 if (isnan(res) || res < 0.0)
827 return 1.0;
828 else
829 return res;
830 }
831 else
832 return 1.0;
833 }
834 else if (bound1->infinite && bound2->infinite)
835 {
836
838 return 0.0;
839 else
841 }
842 else
843 {
844
846 }
847}
848
849
850
851
852
853
854static double
857{
859 double A,
860 B,
863 double pos;
864 int i;
865 double area;
866
868
870 return 0.0;
871
872
874 return 1.0;
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
917 return 1.0;
918
919 if (i < 0)
920 {
921 i = 0;
922 pos = 0.0;
923 }
924 else
925 {
926
930 }
933
934
935
936
937
938
940 return PB;
941
942
943
944
945
946
947 area = 0.0;
949 {
951
952
954 break;
955
956
957 A = B;
959
962
963
964
965
966
967
968
970 area += 0.5 * (PB + PA) * (B - A);
971 }
972
973
974 A = B;
976
977 B = length2;
979 pos = 0.0;
980 else
981 {
983 pos = 0.0;
984 else
986 }
988
990 area += 0.5 * (PB + PA) * (B - A);
991
992
993
994
995
996
997
998
999
1002 else
1004
1005 return frac;
1006}
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017static double
1022{
1023 int i,
1029
1030
1031
1032
1033
1034
1035 upper->inclusive = ->inclusive;
1036 upper->lower = true;
1038 false);
1039
1040
1041
1042
1043
1045 return 0.0;
1046
1047
1048
1049
1050
1051
1052
1053
1054
1056
1057
1058
1059
1060
1061
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1077
1080 {
1081 double dist;
1084
1085
1086
1087
1088
1089
1090
1092 {
1094
1095
1096
1097
1098
1104 }
1105 else
1107
1108
1109
1110
1111
1115
1116
1117
1118
1119
1121
1123 break;
1124
1127 }
1128
1130}
1131
1132
1133
1134
1135
1136
1137
1138static double
1143{
1144 int i,
1150
1151
1153 true);
1154
1155
1156
1157
1158
1160 return 0.0;
1161
1162
1163
1164
1165
1166
1167
1168
1169
1171
1172
1173
1174
1175
1176
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1196 {
1199
1200
1201
1202
1203
1204
1206
1207
1208
1209
1210
1215
1217
1220 }
1221
1223}
#define Assert(condition)
#define OidIsValid(objectId)
bool equal(const void *a, const void *b)
#define palloc_array(type, count)
static float8 get_float8_infinity(void)
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
#define PG_RETURN_FLOAT8(x)
#define PG_GETARG_POINTER(n)
#define PG_GETARG_INT32(n)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
void free_attstatsslot(AttStatsSlot *sslot)
bool get_attstatsslot(AttStatsSlot *sslot, HeapTuple statstuple, int reqkind, Oid reqop, int flags)
Oid get_commutator(Oid opno)
#define ATTSTATSSLOT_NUMBERS
#define ATTSTATSSLOT_VALUES
#define IsA(nodeptr, _type_)
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
FormData_pg_statistic * Form_pg_statistic
static float8 DatumGetFloat8(Datum X)
int range_cmp_bounds(TypeCacheEntry *typcache, const RangeBound *b1, const RangeBound *b2)
RangeType * range_serialize(TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper, bool empty, struct Node *escontext)
void range_deserialize(TypeCacheEntry *typcache, const RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
TypeCacheEntry * range_get_typcache(FunctionCallInfo fcinfo, Oid rngtypid)
static RangeType * DatumGetRangeTypeP(Datum X)
static double calc_hist_selectivity_contains(TypeCacheEntry *typcache, const RangeBound *lower, const RangeBound *upper, const RangeBound *hist_lower, int hist_nvalues, const Datum *length_hist_values, int length_hist_nvalues)
static float8 get_position(TypeCacheEntry *typcache, const RangeBound *value, const RangeBound *hist1, const RangeBound *hist2)
static double calc_hist_selectivity_scalar(TypeCacheEntry *typcache, const RangeBound *constbound, const RangeBound *hist, int hist_nvalues, bool equal)
static int length_hist_bsearch(const Datum *length_hist_values, int length_hist_nvalues, double value, bool equal)
static double calc_hist_selectivity(TypeCacheEntry *typcache, VariableStatData *vardata, const RangeType *constval, Oid operator)
static int rbound_bsearch(TypeCacheEntry *typcache, const RangeBound *value, const RangeBound *hist, int hist_length, bool equal)
static double calc_rangesel(TypeCacheEntry *typcache, VariableStatData *vardata, const RangeType *constval, Oid operator)
static double default_range_selectivity(Oid operator)
static float8 get_len_position(double value, double hist1, double hist2)
static double calc_length_hist_frac(const Datum *length_hist_values, int length_hist_nvalues, double length1, double length2, bool equal)
static double calc_hist_selectivity_contained(TypeCacheEntry *typcache, const RangeBound *lower, RangeBound *upper, const RangeBound *hist_lower, int hist_nvalues, const Datum *length_hist_values, int length_hist_nvalues)
Datum rangesel(PG_FUNCTION_ARGS)
static float8 get_distance(TypeCacheEntry *typcache, const RangeBound *bound1, const RangeBound *bound2)
static int cmp(const chr *x, const chr *y, size_t len)
bool get_restriction_variable(PlannerInfo *root, List *args, int varRelid, VariableStatData *vardata, Node **other, bool *varonleft)
bool statistic_proc_security_check(VariableStatData *vardata, Oid func_oid)
#define ReleaseVariableStats(vardata)
#define CLAMP_PROBABILITY(p)
#define DEFAULT_RANGE_INEQ_SEL
FmgrInfo rng_cmp_proc_finfo
struct TypeCacheEntry * rngelemtype
FmgrInfo rng_subdiff_finfo