PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum _postgis_gserialized_joinsel ( PG_FUNCTION_ARGS  )

Definition at line 1970 of file gserialized_estimate.c.

References estimate_join_selectivity(), pg_get_nd_stats_by_name(), and text2cstring().

1971 {
1972  Oid table_oid1 = PG_GETARG_OID(0);
1973  text *att_text1 = PG_GETARG_TEXT_P(1);
1974  Oid table_oid2 = PG_GETARG_OID(2);
1975  text *att_text2 = PG_GETARG_TEXT_P(3);
1976  ND_STATS *nd_stats1, *nd_stats2;
1977  float8 selectivity = 0;
1978  int mode = 2; /* 2D mode by default */
1979 
1980 
1981  /* Retrieve the stats object */
1982  nd_stats1 = pg_get_nd_stats_by_name(table_oid1, att_text1, mode);
1983  nd_stats2 = pg_get_nd_stats_by_name(table_oid2, att_text2, mode);
1984 
1985  if ( ! nd_stats1 )
1986  elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid1), text2cstring(att_text1));
1987 
1988  if ( ! nd_stats2 )
1989  elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid2), text2cstring(att_text2));
1990 
1991  /* Check if we've been asked to not use 2d mode */
1992  if ( ! PG_ARGISNULL(4) )
1993  {
1994  text *modetxt = PG_GETARG_TEXT_P(4);
1995  char *modestr = text2cstring(modetxt);
1996  if ( modestr[0] == 'N' )
1997  mode = 0;
1998  }
1999 
2000  /* Do the estimation */
2001  selectivity = estimate_join_selectivity(nd_stats1, nd_stats2);
2002 
2003  pfree(nd_stats1);
2004  pfree(nd_stats2);
2005  PG_RETURN_FLOAT8(selectivity);
2006 }
char * text2cstring(const text *textptr)
static float8 estimate_join_selectivity(const ND_STATS *s1, const ND_STATS *s2)
Given two statistics histograms, what is the selectivity of a join driven by the && or &&& operator...
static ND_STATS * pg_get_nd_stats_by_name(const Oid table_oid, const text *att_text, int mode)
Pull the stats object from the PgSQL system catalogs.
N-dimensional statistics structure.

Here is the call graph for this function: