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

Definition at line 1208 of file gserialized_estimate.c.

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

Referenced by gserialized_gist_joinsel_2d(), and gserialized_gist_joinsel_nd().

1209 {
1210  PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
1211  /* Oid operator = PG_GETARG_OID(1); */
1212  List *args = (List *) PG_GETARG_POINTER(2);
1213  JoinType jointype = (JoinType) PG_GETARG_INT16(3);
1214  int mode = PG_GETARG_INT32(4);
1215 
1216  Node *arg1, *arg2;
1217  Var *var1, *var2;
1218  Oid relid1, relid2;
1219 
1220  ND_STATS *stats1, *stats2;
1221  float8 selectivity;
1222 
1223  /* Only respond to an inner join/unknown context join */
1224  if (jointype != JOIN_INNER)
1225  {
1226  elog(DEBUG1, "%s: jointype %d not supported", __func__, jointype);
1227  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1228  }
1229 
1230  /* Find Oids of the geometry columns we are working with */
1231  arg1 = (Node*) linitial(args);
1232  arg2 = (Node*) lsecond(args);
1233  var1 = (Var*) arg1;
1234  var2 = (Var*) arg2;
1235 
1236  /* We only do column joins right now, no functional joins */
1237  /* TODO: handle g1 && ST_Expand(g2) */
1238  if (!IsA(arg1, Var) || !IsA(arg2, Var))
1239  {
1240  elog(DEBUG1, "%s called with arguments that are not column references", __func__);
1241  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1242  }
1243 
1244  /* What are the Oids of our tables/relations? */
1245  relid1 = getrelid(var1->varno, root->parse->rtable);
1246  relid2 = getrelid(var2->varno, root->parse->rtable);
1247 
1248  POSTGIS_DEBUGF(3, "using relations \"%s\" Oid(%d), \"%s\" Oid(%d)",
1249  get_rel_name(relid1) ? get_rel_name(relid1) : "NULL", relid1, get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1250 
1251  /* Pull the stats from the stats system. */
1252  stats1 = pg_get_nd_stats(relid1, var1->varattno, mode, FALSE);
1253  stats2 = pg_get_nd_stats(relid2, var2->varattno, mode, FALSE);
1254 
1255  /* If we can't get stats, we have to stop here! */
1256  if ( ! stats1 )
1257  {
1258  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid1) ? get_rel_name(relid1) : "NULL" , relid1);
1259  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1260  }
1261  else if ( ! stats2 )
1262  {
1263  POSTGIS_DEBUGF(3, "unable to retrieve stats for \"%s\" Oid(%d)", get_rel_name(relid2) ? get_rel_name(relid2) : "NULL", relid2);
1264  PG_RETURN_FLOAT8(DEFAULT_ND_JOINSEL);
1265  }
1266 
1267  selectivity = estimate_join_selectivity(stats1, stats2);
1268  POSTGIS_DEBUGF(2, "got selectivity %g", selectivity);
1269 
1270  pfree(stats1);
1271  pfree(stats2);
1272  PG_RETURN_FLOAT8(selectivity);
1273 }
#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...
#define FALSE
Definition: dbfopen.c:168
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: