MobilityDB 1.1
Functions
span_selfuncs.c File Reference
#include "pg_general/span_selfuncs.h"
#include <assert.h>
#include <math.h>
#include <access/htup_details.h>
#include "utils/syscache.h"
#include <utils/lsyscache.h>
#include <catalog/pg_statistic.h>
#include <utils/timestamp.h>
#include <meos.h>
#include <meos_internal.h>
#include "general/set.h"
#include "pg_general/meos_catalog.h"
#include "pg_general/span_analyze.h"
Include dependency graph for span_selfuncs.c:

Functions

PGDLLEXPORT Datum _mobdb_span_joinsel (PG_FUNCTION_ARGS)
 Utility function to read the calculated selectivity for a given couple of table/column, and operator. More...
 
PGDLLEXPORT Datum _mobdb_span_sel (PG_FUNCTION_ARGS)
 Utility function to read the calculated selectivity for a given table/column, operator, and search span. More...
 
double calc_length_hist_frac (Datum *hist_length, int hist_length_nvalues, double length1, double length2, bool equal)
 Calculate the average of function P(x), in the interval [length1, length2], where P(x) is the fraction of tuples with length < x (or length <= x if 'equal' is true). More...
 
double get_len_position (double value, double hist1, double hist2)
 Get relative position of value in a length histogram bin in [0,1] range. More...
 
int length_hist_bsearch (Datum *hist_length, int hist_length_nvalues, double value, bool equal)
 Binary search on length histogram. More...
 
static int span_bound_bsearch (const SpanBound *value, const SpanBound *hist, int hist_nvalues, bool equal)
 Binary search on an array of span bounds. More...
 
static float8 span_bound_distance (const SpanBound *bound1, const SpanBound *bound2)
 Measure distance between two span bounds. More...
 
void span_const_to_span (Node *other, Span *span)
 Transform the constant into a span. More...
 
PGDLLEXPORT Datum Span_joinsel (PG_FUNCTION_ARGS)
 Join selectivity for spans. More...
 
float8 span_joinsel (PlannerInfo *root, meosOper oper, List *args, JoinType jointype, SpecialJoinInfo *sjinfo)
 Estimate join selectivity for spans. More...
 
static double span_joinsel_contained (SpanBound *lower1, SpanBound *upper1, int nhist1, SpanBound *lower2, SpanBound *upper2, int nhist2, Datum *length, int length_nvalues)
 Look up the fraction of values in the first histogram that is contained in a value in the second histogram. More...
 
static double span_joinsel_contains (SpanBound *lower1, SpanBound *upper1, int nhist1, SpanBound *lower2, SpanBound *upper2, int nhist2, Datum *length, int length_nvalues)
 Look up the fraction of values in the first histogram that contain a value in the second histogram. More...
 
float8 span_joinsel_default (meosOper oper)
 Return a default join selectivity estimate for given operator, when we don't have statistics or cannot use them for some reason. More...
 
static double span_joinsel_hist (VariableStatData *vardata1, VariableStatData *vardata2, meosOper oper)
 Calculate span operator selectivity using histograms of span bounds. More...
 
static double span_joinsel_hist1 (AttStatsSlot *hslot1, AttStatsSlot *hslot2, AttStatsSlot *lslot, meosOper oper)
 Calculate span operator selectivity using histograms of span bounds. More...
 
static double span_joinsel_overlaps (SpanBound *lower1, SpanBound *upper1, int nhist1, SpanBound *lower2, SpanBound *upper2, int nhist2)
 Look up the fraction of values in the first histogram that overlap a value in the second histogram. More...
 
static double span_joinsel_scalar (const SpanBound *hist1, int nhist1, const SpanBound *hist2, int nhist2, bool equal)
 Given two histograms of span bounds, estimate the fraction of values in the first histogram that are less than (or equal to, if 'equal' argument is true) a value in the second histogram. More...
 
static float8 span_position (const SpanBound *value, const SpanBound *hist1, const SpanBound *hist2)
 Get relative position of value in histogram bin in [0,1] span. More...
 
PGDLLEXPORT Datum Span_sel (PG_FUNCTION_ARGS)
 Restriction selectivity for span operators. More...
 
float8 span_sel (PlannerInfo *root, Oid operid, List *args, int varRelid)
 Restriction selectivity for span operators. More...
 
static double span_sel_contained (SpanBound *const_lower, SpanBound *const_upper, SpanBound *hist_lower, int hist_nvalues, Datum *hist_length, int hist_length_nvalues)
 Calculate selectivity of "var <@ const" operator, i.e., estimate the fraction of spans that fall within the constant lower and upper bounds. More...
 
static double span_sel_contains (SpanBound *const_lower, SpanBound *const_upper, SpanBound *hist_lower, int hist_nvalues, Datum *hist_length, int hist_length_nvalues)
 Calculate selectivity of "var @> const" operator, i.e., estimate the fraction of spans that contain the constant lower and upper bounds. More...
 
float8 span_sel_default (meosOper oper)
 Functions for selectivity estimation of time types operators. More...
 
double span_sel_hist (VariableStatData *vardata, const Span *constval, meosOper oper, bool value)
 Calculate span operator selectivity using histograms of span bounds. More...
 
static double span_sel_hist1 (AttStatsSlot *hslot, AttStatsSlot *lslot, const Span *constval, meosOper oper)
 Calculate span operator selectivity using histograms of span bounds. More...
 
static double span_sel_overlaps (const SpanBound *const_lower, const SpanBound *const_upper, const SpanBound *hist_lower, const SpanBound *hist_upper, int nhist)
 Calculate selectivity of "var && const" operator, i.e., estimate the fraction of spans that overlap the constant lower and upper bounds. More...
 
static double span_sel_scalar (const SpanBound *constbound, const SpanBound *hist, int nhist, bool equal)
 Estimate the fraction of values less than (or equal to, if 'equal' argument is true) a given const in a histogram of span bounds. More...
 
bool time_oper_sel (meosOper oper, meosType ltype, meosType rtype)
 Determine whether we can estimate selectivity for the operator. More...
 
static bool value_oper_sel (Oid operid, meosType ltype, meosType rtype)
 Determine whether we can estimate selectivity for the operator. More...