PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ _postgis_gserialized_joinsel()

Datum _postgis_gserialized_joinsel ( PG_FUNCTION_ARGS  )

Definition at line 2063 of file gserialized_estimate.c.

References estimate_join_selectivity(), FALSE, gserialized_gist_sel_2d(), PG_FUNCTION_INFO_V1(), pg_get_nd_stats_by_name(), and text2cstring().

Referenced by _postgis_gserialized_sel().

2064 {
2065  Oid table_oid1 = PG_GETARG_OID(0);
2066  text *att_text1 = PG_GETARG_TEXT_P(1);
2067  Oid table_oid2 = PG_GETARG_OID(2);
2068  text *att_text2 = PG_GETARG_TEXT_P(3);
2069  ND_STATS *nd_stats1, *nd_stats2;
2070  float8 selectivity = 0;
2071  int mode = 2; /* 2D mode by default */
2072 
2073 
2074  /* Retrieve the stats object */
2075  nd_stats1 = pg_get_nd_stats_by_name(table_oid1, att_text1, mode, FALSE);
2076  nd_stats2 = pg_get_nd_stats_by_name(table_oid2, att_text2, mode, FALSE);
2077 
2078  if ( ! nd_stats1 )
2079  elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid1), text2cstring(att_text1));
2080 
2081  if ( ! nd_stats2 )
2082  elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid2), text2cstring(att_text2));
2083 
2084  /* Check if we've been asked to not use 2d mode */
2085  if ( ! PG_ARGISNULL(4) )
2086  {
2087  text *modetxt = PG_GETARG_TEXT_P(4);
2088  char *modestr = text2cstring(modetxt);
2089  if ( modestr[0] == 'N' )
2090  mode = 0;
2091  }
2092 
2093  /* Do the estimation */
2094  selectivity = estimate_join_selectivity(nd_stats1, nd_stats2);
2095 
2096  pfree(nd_stats1);
2097  pfree(nd_stats2);
2098  PG_RETURN_FLOAT8(selectivity);
2099 }
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.
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...
#define FALSE
Definition: dbfopen.c:168
N-dimensional statistics structure.
Here is the call graph for this function:
Here is the caller graph for this function: