PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ gserialized_gist_joinsel()

Datum gserialized_gist_joinsel ( PG_FUNCTION_ARGS  )

Definition at line 1257 of file gserialized_estimate.c.

References ovdump::args, DEFAULT_ND_JOINSEL, estimate_join_selectivity(), and pg_get_nd_stats().

Referenced by gserialized_gist_joinsel_2d(), and gserialized_gist_joinsel_nd().

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