PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ _postgis_gserialized_joinsel()

Datum _postgis_gserialized_joinsel ( PG_FUNCTION_ARGS  )

Definition at line 2113 of file gserialized_estimate.c.

References estimate_join_selectivity(), gserialized_gist_sel_2d(), PG_FUNCTION_INFO_V1(), pg_get_nd_stats_by_name(), and text_to_cstring().

Referenced by _postgis_gserialized_sel().

2114 {
2115  Oid table_oid1 = PG_GETARG_OID(0);
2116  text *att_text1 = PG_GETARG_TEXT_P(1);
2117  Oid table_oid2 = PG_GETARG_OID(2);
2118  text *att_text2 = PG_GETARG_TEXT_P(3);
2119  ND_STATS *nd_stats1, *nd_stats2;
2120  float8 selectivity = 0;
2121  int mode = 2; /* 2D mode by default */
2122 
2123 
2124  /* Retrieve the stats object */
2125  nd_stats1 = pg_get_nd_stats_by_name(table_oid1, att_text1, mode, false);
2126  nd_stats2 = pg_get_nd_stats_by_name(table_oid2, att_text2, mode, false);
2127 
2128  if ( ! nd_stats1 )
2129  elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid1), text_to_cstring(att_text1));
2130 
2131  if ( ! nd_stats2 )
2132  elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid2), text_to_cstring(att_text2));
2133 
2134  /* Check if we've been asked to not use 2d mode */
2135  if ( ! PG_ARGISNULL(4) )
2136  {
2137  text *modetxt = PG_GETARG_TEXT_P(4);
2138  char *modestr = text_to_cstring(modetxt);
2139  if ( modestr[0] == 'N' )
2140  mode = 0;
2141  }
2142 
2143  /* Do the estimation */
2144  selectivity = estimate_join_selectivity(nd_stats1, nd_stats2);
2145 
2146  pfree(nd_stats1);
2147  pfree(nd_stats2);
2148  PG_RETURN_FLOAT8(selectivity);
2149 }
char * text_to_cstring(const text *textptr)
static ND_STATS * pg_get_nd_stats_by_name(const Oid table_oid, const text *att_text, int mode, bool only_parent)
Pull the stats object from the PgSQL system catalogs.
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...
N-dimensional statistics structure.
Here is the call graph for this function:
Here is the caller graph for this function: