PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum gserialized_gist_joinsel ( PG_FUNCTION_ARGS  )

Definition at line 1254 of file gserialized_estimate.c.

References DEFAULT_ND_JOINSEL, estimate_join_selectivity(), and pg_get_nd_stats().

Referenced by gserialized_gist_joinsel_2d(), and gserialized_gist_joinsel_nd().

1255 {
1256  PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
1257  /* Oid operator = PG_GETARG_OID(1); */
1258  List *args = (List *) PG_GETARG_POINTER(2);
1259  JoinType jointype = (JoinType) PG_GETARG_INT16(3);
1260  int mode = PG_GETARG_INT32(4);
1261 
1262  Node *arg1, *arg2;
1263  Var *var1, *var2;
1264  Oid relid1, relid2;
1265 
1266  ND_STATS *stats1, *stats2;
1267  float8 selectivity;
1268 
1269  /* Only respond to an inner join/unknown context join */
1270  if (jointype != JOIN_INNER)
1271  {
1272  elog(DEBUG1, "%s: jointype %d not supported", __func__, jointype);
1273  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1274  }
1275 
1276  /* Find Oids of the geometry columns we are working with */
1277  arg1 = (Node*) linitial(args);
1278  arg2 = (Node*) lsecond(args);
1279  var1 = (Var*) arg1;
1280  var2 = (Var*) arg2;
1281 
1282  /* We only do column joins right now, no functional joins */
1283  /* TODO: handle g1 && ST_Expand(g2) */
1284  if (!IsA(arg1, Var) || !IsA(arg2, Var))
1285  {
1286  elog(DEBUG1, "%s called with arguments that are not column references", __func__);
1287  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1288  }
1289 
1290  /* What are the Oids of our tables/relations? */
1291  relid1 = getrelid(var1->varno, root->parse->rtable);
1292  relid2 = getrelid(var2->varno, root->parse->rtable);
1293 
1294  POSTGIS_DEBUGF(3, "using relations \"%s\" Oid(%d), \"%s\" Oid(%d)",
1295  get_rel_name(relid1) ? get_rel_name(relid1) : "NULL", relid1, get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1296 
1297  /* Pull the stats from the stats system. */
1298  stats1 = pg_get_nd_stats(relid1, var1->varattno, mode, false);
1299  stats2 = pg_get_nd_stats(relid2, var2->varattno, mode, false);
1300 
1301  /* If we can't get stats, we have to stop here! */
1302  if ( ! stats1 )
1303  {
1304  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid1) ? get_rel_name(relid1) : "NULL" , relid1);
1305  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1306  }
1307  else if ( ! stats2 )
1308  {
1309  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1310  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1311  }
1312 
1313  selectivity = estimate_join_selectivity(stats1, stats2);
1314  POSTGIS_DEBUGF(2, "got selectivity %g", selectivity);
1315 
1316  pfree(stats1);
1317  pfree(stats2);
1318  PG_RETURN_FLOAT8(selectivity);
1319 }
#define DEFAULT_ND_JOINSEL
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.
static ND_STATS * pg_get_nd_stats(const Oid table_oid, AttrNumber att_num, int mode, bool only_parent)
Pull the stats object from the PgSQL system catalogs.

Here is the call graph for this function:

Here is the caller graph for this function: