* Estimate selectivity of "column <@ const" based on most common element * statistics. * * mcelem (of length nmcelem) and numbers (of length nnumbers) are from * the array column's MCELEM statistics slot, or are NULL/0 if stats are * not available. array_data (of length nitems) is the constant's elements. * hist (of length nhist) is from the array column's DECHIST statistics slot, * or is
| 694 | * ... * fn^on * (1 - fn)^(1 - on), o1, o2, ..., on) | o1 + o2 + .. on = m |
| 695 | */ |
| 696 | static Selectivity |
| 697 | mcelem_array_contained_selec(Datum *mcelem, int nmcelem, |
| 698 | float4 *numbers, int nnumbers, |
| 699 | Datum *array_data, int nitems, |
| 700 | float4 *hist, int nhist, |
| 701 | Oid operator, TypeCacheEntry *typentry) |
| 702 | { |
| 703 | int mcelem_index, |
| 704 | i, |
| 705 | unique_nitems = 0; |
| 706 | float selec, |
| 707 | minfreq, |
| 708 | nullelem_freq; |
| 709 | float *dist, |
| 710 | *mcelem_dist, |
| 711 | *hist_part; |
| 712 | float avg_count, |
| 713 | mult, |
| 714 | rest; |
| 715 | float *elem_selec; |
| 716 | |
| 717 | /* |
| 718 | * There should be three more Numbers than Values in the MCELEM slot, |
| 719 | * because the last three cells should hold minimal and maximal frequency |
| 720 | * among the non-null elements, and then the frequency of null elements. |
| 721 | * Punt if not right, because we can't do much without the element freqs. |
| 722 | */ |
| 723 | if (numbers == NULL || nnumbers != nmcelem + 3) |
| 724 | return DEFAULT_CONTAIN_SEL; |
| 725 | |
| 726 | /* Can't do much without a count histogram, either */ |
| 727 | if (hist == NULL || nhist < 3) |
| 728 | return DEFAULT_CONTAIN_SEL; |
| 729 | |
| 730 | /* |
| 731 | * Grab some of the summary statistics that compute_array_stats() stores: |
| 732 | * lowest frequency, frequency of null elements, and average distinct |
| 733 | * element count. |
| 734 | */ |
| 735 | minfreq = numbers[nmcelem]; |
| 736 | nullelem_freq = numbers[nmcelem + 2]; |
| 737 | avg_count = hist[nhist - 1]; |
| 738 | |
| 739 | /* |
| 740 | * "rest" will be the sum of the frequencies of all elements not |
| 741 | * represented in MCELEM. The average distinct element count is the sum |
| 742 | * of the frequencies of *all* elements. Begin with that; we will proceed |
| 743 | * to subtract the MCELEM frequencies. |
| 744 | */ |
| 745 | rest = avg_count; |
| 746 | |
| 747 | /* |
| 748 | * mult is a multiplier representing estimate of probability that each |
| 749 | * mcelem that is not present in constant doesn't occur. |
| 750 | */ |
| 751 | mult = 1.0f; |
| 752 | |
| 753 | /* |
no test coverage detected