Ejemplo n.º 1
0
        public IRowCursor Select(SelectableRange range)
        {
            // If it's an empty range,
            if (range.IsEmpty)
                return new SimpleRowCursor(0);

            List<IRowCursor> cursors = new List<IRowCursor>();
            // For each range pair,
            ISelectableRangeEnumerator en = range.GetEnumerator();

            while (en.MoveNext()) {
                // The range pair information,
                SqlObject[] lower = en.LowerBound;
                SqlObject[] upper = en.UpperBound;
                bool lowerAtFirst = en.IsLowerBoundAtFirst;
                bool upperAtLast = en.IsUpperBoundAtLast;

                IRowCursor cursor = RangeCursor(lower, upper, lowerAtFirst, upperAtLast);
                // If the pair resolves to something, add it to the iterator set.
                if (cursor != null && cursor.Count > 0)
                    cursors.Add(cursor);
            }

            return new SelectedRowCursor(new GroupedRowCursor(cursors));
        }
Ejemplo n.º 2
0
        private SubsetTable FilterByIndex(ITable table, IIndexSetDataSource index, Expression order, SelectableRange range)
        {
            // Select from the index and return the subset
            IRowCursor rows = index.Select(range);
            SubsetTable filteredTable = new SubsetTable(table, rows);

            filteredTable.OrderComposite = order;

            // If the number of rows selected from the index is the same as the
            // original table, then it is safe for index requests to fallthrough to the
            // parent.
            long selectCount = rows.Count;
            long originalCount = table.RowCount;
            if (selectCount == originalCount)
                filteredTable.IndexRequestFallthrough = true;

            // Assert we didn't select more than in the original context
            if (selectCount > originalCount)
                throw new ApplicationException(	"Index found more values than in parent table.");

            return filteredTable;
        }
Ejemplo n.º 3
0
        public double ProbabilityEstimate(SelectableRange rangeSet)
        {
            // If we don't have any information, return the worst case of 1.0.  This
            // will happen if the data set is very small.
            if (totalSize == 0) {
                return 1.0d;
            }

            // How many samples intersect the range set?
            IRangeIntersector comparator = rangeSet.Intersector;
            int intersect_count = 0;
            for (int i = 0; i < divisionPoints.Length; ++i) {
                if (comparator.ValueIntersects(new SqlObject[] { divisionPoints[i] })) {
                    ++intersect_count;
                }
            }

            // The worst case is ((1 + intersect_count) * row_to_samples) for single
            // value range sets.  This is the general heuristic we will use even
            // though the worst case could be higher for multi valued ranges.

            double iCount = intersect_count + 1;

            // Probability
            double probability = iCount / DivisionPointCount;
            return System.Math.Min(probability, 1.0d);
        }