PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ _postgis_gserialized_joinsel()

Datum _postgis_gserialized_joinsel ( PG_FUNCTION_ARGS  )

Definition at line 2129 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().

2130 {
2131  Oid table_oid1 = PG_GETARG_OID(0);
2132  text *att_text1 = PG_GETARG_TEXT_P(1);
2133  Oid table_oid2 = PG_GETARG_OID(2);
2134  text *att_text2 = PG_GETARG_TEXT_P(3);
2135  ND_STATS *nd_stats1, *nd_stats2;
2136  float8 selectivity = 0;
2137  int mode = 2; /* 2D mode by default */
2138 
2139 
2140  /* Retrieve the stats object */
2141  nd_stats1 = pg_get_nd_stats_by_name(table_oid1, att_text1, mode, false);
2142  nd_stats2 = pg_get_nd_stats_by_name(table_oid2, att_text2, mode, false);
2143 
2144  if ( ! nd_stats1 )
2145  elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid1), text_to_cstring(att_text1));
2146 
2147  if ( ! nd_stats2 )
2148  elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid2), text_to_cstring(att_text2));
2149 
2150  /* Check if we've been asked to not use 2d mode */
2151  if ( ! PG_ARGISNULL(4) )
2152  {
2153  text *modetxt = PG_GETARG_TEXT_P(4);
2154  char *modestr = text_to_cstring(modetxt);
2155  if ( modestr[0] == 'N' )
2156  mode = 0;
2157  }
2158 
2159  /* Do the estimation */
2160  selectivity = estimate_join_selectivity(nd_stats1, nd_stats2);
2161 
2162  pfree(nd_stats1);
2163  pfree(nd_stats2);
2164  PG_RETURN_FLOAT8(selectivity);
2165 }
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: